I want the link generated, copied to clipboard - copy

<div class="form-group m-l-4">
<label class="" for="">Share It :</label>
<p id="postcodep<?php echo isset($campaign['post_id']) ? $campaign['post_id'] : 0 ?>" style=" word-wrap: break-word; margin: 0px;
border: 1px solid #1083d4;
padding: 5px;
}">Please Generate Link</p>
</div>
<!--<button ng-click="getCode('<?php echo isset($campaign['post_id']) ? $campaign['post_id'] : 0 ?>', <?php echo isset($campaign['campaign_id']) ? $campaign['campaign_id'] : 0 ?>)" class="btn btn-default m-l-2 waves-effect waves-light"><span class="fa "></span>GET</button>-->
<button ng-click="getCode('<?php echo isset($campaign['post_id']) ? $campaign['post_id'] : 0 ?>', <?php echo isset($campaign['campaign_id']) ? $campaign['campaign_id'] : 0 ?>)" class="btn btn-info waves-effect waves-light m-b-5 btn-xs"><span class="fa fa-plus " ></span> GENERATE LINK </button>
I want the link generated, copied to clipboard
as soon as people click on generate link. Can anyone help me I am not to familiar with angular?

I don't know how this is working in Angular, but in pure JavaScript it can be something like:
<button id="get-link" data-link="<?= getCode() ?>">GET LINK</button>
document.getElementById('get-link').addEventListener('click', function () {
var temp = document.createElement('textarea');
temp.value = this.getAttribute('data-link');
document.body.appendChild(temp);
temp.select();
document.execCommand('copy');
document.body.removeChild(temp);
});

Related

Clicking text (list item) with Selenium and Powershell

I have the following HTML and I am trying to find a way (in Powershell) to click the "folder" list item, which appears when the "new" button is clicked.
<div>
<i class="fa fa-fw fa-plus"></i>
<span>new</span>
<i class="fa fa-fw fa-caret-down margin-none margin-left-xsmall"></i>
</div>
<div class="itg-popover qa-itg-popover borderless point-to-right arrow-direction-up arrow-position-right open" style="left: 0px; top: 0px;">
<span class="arrow-container" style="height: 0px; width: 10px; left: calc(100% - 0px); top: 100%;">
<span class="arrow" style="border-width: 0px;">
</span>
</span>
<div class="itg-popover-content qa-itg-popover-content" style="left: calc(100% + 0px); transform: translateX(-100%); top: calc(-1px + 100%);">
<ul class="react-selectable-list qa-react-selectable-list">
<li data-id="assset" class="selectable-list-item qa-selectable-list-item">
<span class="sentence-case">
<a>document</a>
</span>
</li>
<li data-id="folder" class="selectable-list-item qa-selectable-list-item">
<span class="sentence-case">
<a>folder</a>
</span>
</li>
<li data-id="file-upload" class="selectable-list-item qa-selectable-list-item">
<span class="sentence-case">
<a>File Upload</a>
</span>
</li>
</ul>
</div>
</div>
Using the following code, I have clicked the "new" button:
$seleniumPath = 'C:\it\selenium'
Add-Type -Path "$seleniumPath\WebDriver.dll"
Add-Type -Path "$seleniumPath\WebDriver.Support.dll"
$chromedriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver
$chromedriver.Navigate().GoToUrl('https://<url>')
$chromedriver.FindElementByXPath("//div[#id='react-main']/div/div[3]/div[2]/div[2]/div/div/div/div/div/div/div/i[2]").Click()
I thought I could create a SelectElement (so I could search by text) with this:
$SelectElement = [OpenQA.Selenium.Support.UI.SelectElement]::new($chromedriver.FindElementByXPath("//div[#id='react-main']/div/div[3]/div[2]/div[2]/div/div/div/div/div/div/div/i[2]"))
But I get this error:
Exception calling ".ctor" with "1" argument(s): "Element should have
been select but was i"
Sure enough, if I look at the object, there's, "i":
WrappedDriver : OpenQA.Selenium.Chrome.ChromeDriver
TagName : i
Text : New
document
folder
File Upload
Enabled : True
Selected : False
Location : {X=1025,Y=102}
Size : {Width=95, Height=35}
Displayed : True
LocationOnScreenOnceScrolledIntoView : {X=1025,Y=102}
Coordinates : OpenQA.Selenium.Remote.RemoteCoordinates
So the question in, how in the world do I click "folder"?

Passing Data from a Controller to a View (not displaying it) then passing back to different Controller in Codeigniter

I am trying to a create a View which provides a summary table of various site members profiles - then each summary has a button, that once clicked, takes the user to that member's full profile. I can get the summary page to work properly, but I cant get the second part -where the button takes the user to the members full profile to work.
Here is my controller:
public function network_barre()
{
$this->load->model("Profiles_model");
$style ='barre';
$profilesubdata["fetch_data"] = $this->Profiles_model->fetch_data($style);
$this->load->view('templates/header');
$this->load->view('pages/page-network_barre', $profilesubdata);
$this->load->view('templates/footer');
Here is my Model "Profiles Model"
function fetch_data($style)
{
$this->db->select("username, email, style, about");
$this->db->from("profiles");
$this->db->where('style', $style);
$query = $this->db->get();
return $query;
}
Here is the view
<div class="container">
<div class="row d-flex justify-content-center card-top">
<?php
if($fetch_data->num_rows()>0)
{
foreach ($fetch_data->result() as $row)
{
?>
<div class="col-lg-4 col-md-6">
<div class="card card-warning wow zoomInUp mb-4 animation-delay-5">
<div class="withripple zoom-img">
<img src="<?=base_url();?>assets/img/demo/avatar4.jpg" class="img-fluid">
</div>
<div class="card-body">
<span class="badge badge-warning pull-right"><?php echo $row->style; ?></span>
<h3 class="color-warning"><?php echo $row->username; ?></h3>
<p><?php $string=character_limiter($row->about, 255, '&#8230(More in Profile)') ; echo $string?></p>
<div class="row">
<div class="col text-center">
<!-- BUTTON -->
<form method="POST" action="<?php echo base_url(); ?>public_area/gotopublicprofile/<?php echo $row->email; ?>">
<input type="hidden" name="<?php echo $this->security->get_csrf_token_name();?>" value="<?php echo $this->security->get_csrf_hash();?>">
<button type="submit" class="btn btn-raised btn-sm btn-warning" name="submit" value="submit"><i class="zmdi zmdi-account"></i>Profile</button>
</form>
</div>
</div>
</div>
</div>
</div>
<?php //this tag close out php tags above
}
}
?>
</div>
</div>
here is Controller gotopublicprofile
function gotopublicprofile()
{
$this->load->model("profiles_model");
$email = '$this->uri->segment(3)';
$profiledata["fetch_profiledata"] = $this->Profiles_model->fetch_profiledata($email);
$this->load->view('templates/header');
$this->load->view('pages/page-profilepublic', $profiledata);
$this->load->view('templates/footer');
}
And here is the fetch_profiledata function in the Model:
function fetch_profiledata($email)
{
$this->db->where('email', $email);
$query = $this->db->get("profiles");
return $query;
}
I always get these error messages:
Undefined property: Public_area::$Profiles_model
AND
Call to a member function fetch_profiledata() on null
I am sure I am just missing something simple, as lots of websites use this approach.
Thanks in advance!
So I figured it out..it was a combination of little things:
First
$email = '$this->uri->segment(3)';
became
$email = $this->uri->segment(3);
Thanks #kirb! and
function gotopublicprofile()
{
$this->load->model("profiles_model");
became
function gotopublicprofile()
{
$this->load->model("Profiles_model");
Thanks #Atal Prateek!

Trying to write a cypress test for drag and drop to a specific destination

I am able to drag the content but its dropping in the same location instead of intended location.
My goal is to drop at specific location,which isn't happening.Need some help or suggestion on this!!
My test
it('moves the piece when dragged to valid place', function () {
cy.get('[data-cy="dataExplorer" ]').find('ux-accordion-panel').first().click();
cy.get('[data-cy="metricContainer"]').first()
.trigger('mousedown', { button: 0 })
.wait(1000)
.trigger('mousemove', {force: true, x: -370, y: 180, bubbles: false})
.trigger('mouseup', {force: true})
});
My html
<table class="table table-hover">
<tbody uxTabbableList>
<tr *ngFor="let field of fields; let i=index" uxTabbableListItem>
<td class="metric-group" (mouseenter)="activeRowId = field.id"
(mouseleave)="activeRowId = null" [attr.aria-expanded]="activeRowId === field.id"
[cdkDropListConnectedTo]="['mashup-dashboard']" cdkDropList>
<div cdkDrag (cdkDragDropped)="dragDropped($event, field)" data-cy="metricContainer" class="metric-container">
<div data-cy="metricName" class="metric-name">
<div>{{field.name}}</div>
<div *cdkDragPlaceholder class="drop-preview-placeholder"></div>
<div *cdkDragPreview>{{field.name}}</div>
</div>
<div class="add-button-container" [class.flt-show]="activeRowId === field.id">
<button type="button" aria-label="Edit" class="btn button-primary"
[tabindex]="activeRowId === field.id ? 0 : -1" (click)="addMetricPanel(field);">
</button>
</div>
</div>
</td>
</tr>
</tbody>
</table>

Jquery - Sortable did not work when div.load is called

I have this issue that every time the div is loaded using div.load in the ajax success, the code for sortable will not work. Sortable will work again after the page is refreshed manually. What could be the possible solution for this?
$(document).on('click', '#add-song-tag', function() {
tag_id = $('#tags').val();
$.ajax({
url: base_url + '/songtags/add_song_tag',
type: 'POST',
data: {
song_info_id: song_info_id,
tag_id: tag_id
},
success: function() {
$('#category').load(window.location.href + ' #category');
$('#modal-categories').trigger('change');
},
error: function(xhr) {
console.log(xhr.responseText);
}
})
});
I have my code in the sortable.js like
$( function() {
$( "#sortable, #sortable1" ).sortable({
connectWith: ".draggable-group",
start: function(event, ui){
$(ui.item).width($('#sortable div').width());
}
// containment: "parent",
// tolerance: "pointer"
}).disableSelection();
} );
and in the html it looks something like:
<?php if($selected_tag_for_m['category_id'] == $tempo_id):?>
<div class="btn-group draggable-group">
<div>
<i class="fa fa-minus-circle fa-lg delete-a-tag" aria-hidden="true"></i>
</div>
<div type="button" class="btn btn-default btn-color"><i class="fa fa-circle-o custom-text-blue"></i> <?php echo $selected_tag_for_m['tag_name'];?> </div>
<div type="button" class="btn btn-default custom-bgcolor-blue dropdown-toggle" data-toggle="dropdown">
<span><i class="fa fa-pencil"></i></span>
<span class="sr-only">Toggle Dropdown</span>
</div>
<ul class="dropdown-menu" role="menu" id="tempo">
<?php foreach($tempos as $tempo):?>
<li data-id="<?php echo $selected_tag_for_m['info_tag_id']?>"><a href="" data-id="<?php echo $tempo['tag_id']?>" class="songtaglist" ><?php echo $tempo['tag_name'];?></a></li>
<?php endforeach;?>
</ul>
</div>
<?php endif;?>
I found solution to this by calling sortable.js script in body of the load function. The code looks like this:
$('#category').load(window.location.href + ' #category', function(){
$.getScript(base_url + '/assets/js/sortable.js');
});

Open bootstrap modal with vue.js 2.0

Does anyone know how to open a bootstrap modal with vue 2.0? Before vue.js I would simply open the modal by using jQuery: $('#myModal').modal('show');
However, is there a proper way I should do this in Vue?
Thank you.
My code is based on the Michael Tranchida's answer.
Bootstrap 3 html:
<div id="app">
<div v-if="showModal">
<transition name="modal">
<div class="modal-mask">
<div class="modal-wrapper">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" #click="showModal=false">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
modal body
</div>
</div>
</div>
</div>
</div>
</transition>
</div>
<button id="show-modal" #click="showModal = true">Show Modal</button>
</div>
Bootstrap 4 html:
<div id="app">
<div v-if="showModal">
<transition name="modal">
<div class="modal-mask">
<div class="modal-wrapper">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true" #click="showModal = false">×</span>
</button>
</div>
<div class="modal-body">
<p>Modal body text goes here.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" #click="showModal = false">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
</transition>
</div>
<button #click="showModal = true">Click</button>
</div>
js:
new Vue({
el: '#app',
data: {
showModal: false
}
})
css:
.modal-mask {
position: fixed;
z-index: 9998;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, .5);
display: table;
transition: opacity .3s ease;
}
.modal-wrapper {
display: table-cell;
vertical-align: middle;
}
And in jsfiddle
Tried to write a code that using VueJS transitions to operate native Bootsrap animations.
HTML:
<div id="exampleModal">
<!-- Button trigger modal-->
<button class="btn btn-primary m-5" type="button" #click="showModal = !showModal">Launch demo modal</button>
<!-- Modal-->
<transition #enter="startTransitionModal" #after-enter="endTransitionModal" #before-leave="endTransitionModal" #after-leave="startTransitionModal">
<div class="modal fade" v-if="showModal" ref="modal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button class="close" type="button" #click="showModal = !showModal"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">...</div>
<div class="modal-footer">
<button class="btn btn-secondary" #click="showModal = !showModal">Close</button>
<button class="btn btn-primary" type="button">Save changes</button>
</div>
</div>
</div>
</div>
</transition>
<div class="modal-backdrop fade d-none" ref="backdrop"></div>
</div>
Vue.JS:
var vm = new Vue({
el: "#exampleModal",
data: {
showModal: false,
},
methods: {
startTransitionModal() {
vm.$refs.backdrop.classList.toggle("d-block");
vm.$refs.modal.classList.toggle("d-block");
},
endTransitionModal() {
vm.$refs.backdrop.classList.toggle("show");
vm.$refs.modal.classList.toggle("show");
}
}
});
Example on Codepen if you are not familiar with Pug click View compiled HTML on a dropdown window in HTML section.
This is the basic example of how Modals works in Bootstrap. I'll appreciate if anyone will adopt it for general purposes.
Have a great code 🦀!
I did an amalgam of the Vue.js Modal example and the Bootstrap 3.* live demo.
Basically, I used the Vue.js modal example but replaced (sorta) the Vue.js "html" part with the bootstrap modal html markup, save one thing (I think). I had to strip the outer div from the bootstrap 3, then it just worked, voila!
So the relevant code is regarding bootstrap. Just strip the outer div from the bootstrap markup and it should work. So...
ugh, a site for developers and i can't easily paste in code? This has been a serious continuing problem for me. Am i the only one? Based on history, I'm prolly an idiot and there's an easy way to paste in code, please advise. Every time i try, it's a horrible hack of formatting, at best.
i'll provide a sample jsfiddle of how i did it if requested.
Using the $nextTick() function worked for me. It just waits until Vue has updated the DOM and then shows the modal:
HTML
<div v-if="is_modal_visible" id="modal" class="modal fade">...</div>
JS
{
data: {
isModalVisible: false,
},
methods: {
showModal() {
this.isModalVisible = true;
this.$nextTick(() => {
$('#modal').modal('show');
});
}
},
}
Here's the Vue way to open a Bootstrap modal..
Bootstrap 5 (2022)
Now that Bootstrap 5 no longer requires jQuery, it's easy to use the Bootstrap modal component modularly. You can simply use the data-bs attributes, or create a Vue wrapper component like this...
<bs-modal id="theModal">
<button class="btn btn-info" slot="trigger"> Bootstrap modal </button>
<div slot="target" class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Modal body text goes here.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</bs-modal>
const { Modal } = bootstrap
const modal = Vue.component('bsModal', {
template: `
<div>
<slot name="trigger"></slot>
<slot name="target"></slot>
</div>
`,
mounted() {
var trigger = this.$slots['trigger'][0].elm
var target = this.$slots['target'][0].elm
trigger.addEventListener('click',()=>{
var theModal = new Modal(target, {})
theModal.show()
})
},
})
Bootstrap 5 Modal in Vue Demo
Bootstrap 4
Bootstrap 4 JS components require jQuery, but it's not necessary (or desirable) to use jQuery in Vue components. Instead manipulate the DOM using Vue...
Launch modal
<div :class="modalClasses" class="fade" id="reject" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Modal</h4>
<button type="button" class="close" #click="toggle()">×</button>
</div>
<div class="modal-body"> ... </div>
</div>
</div>
</div>
var vm = new Vue({
el: '#app',
data () {
return {
modalClasses: ['modal','fade'],
}
},
methods: {
toggle() {
document.body.className += ' modal-open'
let modalClasses = this.modalClasses
if (modalClasses.indexOf('d-block') > -1) {
modalClasses.pop()
modalClasses.pop()
//hide backdrop
let backdrop = document.querySelector('.modal-backdrop')
document.body.removeChild(backdrop)
}
else {
modalClasses.push('d-block')
modalClasses.push('show')
//show backdrop
let backdrop = document.createElement('div')
backdrop.classList = "modal-backdrop fade show"
document.body.appendChild(backdrop)
}
}
}
})
Bootstrap 4 Vue Modal Demo
My priority was to keep using Bootstrap code, since they made the effort to make the modal work, fixin' the scrollbars and all. I found existing proposals try to mimic that, but they go only part of the way. I didn't even want to leave it to chance: I just wanted to use actual bootstrap code.
Additionally, I wanted to have a procedural interface, e.g. calling dialog.show(gimme plenty of parameters here), not just toggling a variable somewhere (even if that variable could be a complex object).
I also wanted to have Vue's reactivity and component rendering for the actual dialog contents.
The problem to solve was that Vue refuses to cooperate if it finds component's DOM to have been manipulated externally. So, basically, I moved the outer div declaring the modal itself, out of the component and registered the component such that I also gain procedural access to the dialogs.
Code like this is possible:
window.mydialog.yesNo('Question', 'Do you like this dialog?')
On to the solution.
main.html (basically just the outer div wrapping our component):
<div class="modal fade" id="df-modal-handler" tabindex="-1" role="dialog" aria-hidden="true">
<df-modal-handler/>
</div>
component-template.html (the rest of the modal):
<script type="text/x-template" id="df-modal-handler-template">
<div :class="'modal-dialog ' + sizeClass" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{{ title }}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" v-html="body"/>
<div class="modal-footer">
<button type="button" v-for="button in buttons" :class="button.classes" v-bind="button.arias"
#click.stop="buttonClick(button, callback)">{{ button.text }}
</button>
</div>
</div>
</div>
</script>
component-def.js - contains logic for showing & manipulating the dialog, also supports dialog stacks in case you make a mistake and invoke two dialogs in sequence:
Vue.component('df-modal-handler', {
template: `#df-modal-handler-template`,
props: {},
data() {
return {
dialogs: [],
initialEventAssignDone: false,
};
},
computed: {
bootstrapDialog() { return document.querySelector('#df-modal-handler'); },
currentDialog() { return this.dialogs.length ? this.dialogs[this.dialogs.length - 1] : null; },
sizeClass() {
let dlg = this.currentDialog;
if (!dlg) return 'modal-sm';
if (dlg.large || ['large', 'lg', 'modal-lg'].includes(dlg.size)) return 'modal-lg';
else if (dlg.small || ['small', 'sm', 'modal-sm'].includes(dlg.size)) return 'modal-sm';
return '';
},
title() { return this.currentDialog ? this.currentDialog.title : 'No dialogs to show!'; },
body() { return this.currentDialog ? this.currentDialog.body : 'No dialogs have been invoked'; },
callback() { return this.currentDialog ? this.currentDialog.callback : null; },
buttons() {
const self = this;
let res = this.currentDialog && this.currentDialog.buttons ? this.currentDialog.buttons : [{close: 'default'}];
return res.map(value => {
if (value.close == 'default') value = {
text: 'Close',
classes: 'btn btn-secondary',
data_return: 'close'
};
else if (value.yes == 'default') value = {
text: 'Yes',
classes: 'btn btn-primary',
data_return: 'yes'
};
else if (value.no == 'default') value = {
text: 'No',
classes: 'btn btn-secondary',
data_return: 'no'
};
value.arias = value.arias || {};
let clss = (value.classes || '').split(' ');
if (clss.indexOf('btn') == -1) clss.push('btn');
value.classes = clss.join(' ');
return value;
});
},
},
created() {
// make our API available
window.mydialog = this;
},
methods: {
show: function show() {
const self = this;
if (!self.initialEventAssignDone) {
// created is too soon. if we try to do this there, the dialog won't even show.
self.initialEventAssignDone = true;
$(self.bootstrapDialog).on('hide.bs.modal', function (event) {
let callback = null;
if (self.dialogs.length) callback = self.dialogs.pop().callback;
if (self.dialogs.length) event.preventDefault();
if (callback && callback.df_called !== true) callback(null);
});
}
$(self.bootstrapDialog).modal('show');
},
hide: function hide() {
$(this.bootstrapDialog).modal('hide');
},
buttonClick(button, callback) {
if (callback) { callback(button.data_return); callback.df_called = true; }
else console.log(button);
this.hide();
},
yesNo(title, question, callback) {
this.dialogs.push({
title: title, body: question, buttons: [{yes: 'default'}, {no: 'default'}], callback: callback
});
this.show();
},
},
});
Do note that this solution creates one single dialog instance in the DOM and re-uses that for all your dialog needs. There are no transitions (yet), so the UX isn't too great when there are multiple active dialogs. It's bad practice anyway, but I wanted it covered because you never know...
Dialog body is actually a v-html, so just instantiate your component with some parameters to have it draw the body itself.
I create button with params for modal and simply trigger click()
document.getElementById('modalOpenBtn').click()
<a id="modalOpenBtn" data-toggle="modal" data-target="#Modal">open modal</a>
<div class="modal" id="Modal" tabindex="-1" role="dialog" aria-labelledby="orderSubmitModalLabel" aria-hidden="true">...</div>
From https://getbootstrap.com/docs/4.0/getting-started/javascript/#programmatic-api
$('#myModal').modal('show')
You can do this from a Vue method and it works just fine.
modal doc
Vue.component('modal', {
template: '#modal-template'
})
// start app
new Vue({
el: '#app',
data: {
showModal: false
}
})
<script type="text/x-template" id="modal-template">
<transition name="modal">
<div class="modal-mask">
<div class="modal-wrapper">
<div class="modal-container">
<div class="modal-header">
<slot name="header">
default header
</slot>
</div>
<div class="modal-body">
<slot name="body">
default body
</slot>
</div>
<div class="modal-footer">
<slot name="footer">
default footer
<button class="modal-default-button" #click="$emit('close')">
OK
</button>
</slot>
</div>
</div>
</div>
</div>
</transition>
</script>
<!-- app -->
<div id="app">
<button id="show-modal" #click="showModal = true">Show Modal</button>
<!-- use the modal component, pass in the prop -->
<modal v-if="showModal" #close="showModal = false">
<!--
you can use custom content here to overwrite
default content
-->
<h3 slot="header">custom header</h3>
</modal>
</div>