After Ajax request hover event doesn't load to image thumbail to display bigger image - datatables

I use datatables tot display a thumbnail in the first column. With jquery I display the original bigger picture when I hover the thumbnail.
Everything works fine until I decided to load the content into the table via Ajax. The hover event won't bind to the thumnail.
I tried all sorts of things. Read something about delagate, but can't get it to work. Can anyone help me?
<tr role="row" class="odd">
<td class="dtr-control"><a href="../images/cont/257.jpg" class="hover">
<img src="../images/redcont_thumb/1757.jpg" class="mediabank-preview-thumbnail"></a>
</td>
<td>Description</td>
</tr>
Hover Jquery code:
$('a.hover').hover(function(e){
var href = $(this).attr('href');
$('<img id="largeImage" src="' + href + '" alt="image" />')
.css({'top':e.pageY + offsetY,'left':e.pageX + offsetX})
.appendTo('body');
}, function(){
$('#largeImage').remove(); // Delete displaying picture
});
$('a.hover').mousemove(function(e){
$('#largeImage').css({'top':e.pageY + offsetY,'left':e.pageX + offsetX});
});
$('a.hover').click(function(e){
e.preventDefault();
});
UPDATE:
Hover won't work, so I uses 'mouseenter' and 'mouseleave'. Everything works fine.
// Hover images
var offsetX = 20;
var offsetY = -250
$('#table_mediaBank').on('mouseenter', 'a.hover', function (e) {
var href = $(this).attr('href');
$('<img id="largeImage" src="' + href + '" alt="image" />')
.css({'top':e.pageY + offsetY,'left':e.pageX + offsetX})
.appendTo('body');
});
$('#table_mediaBank').on('mouseleave', 'a.hover', function () { // Verwijder het displayen van de afbeelding
$('#largeImage').remove();
});
$('#table_mediaBank').on('mousemove', 'a.hover', function (e) { verplaatsen
$('#largeImage').css({'top':e.pageY + offsetY,'left':e.pageX + offsetX});
});
$('#table_mediaBank').on('click', 'a.hover', function (e) {
e.preventDefault();
});

Related

Copy table to clipboard in vue.js

I am trying to copy div element to clipboard in vuejs. I have gone through to search related solution and applied. But not working. I ant to copy full table to clipboard. Thanks in advance
<button v-on:click = "copyToClipboard(select_txt)">Click To Copy</button>
<table class="table table-sm" id="select_txt">
<tr>
<td>Name</td>
<td> abcd </td>
</tr>
<tr>
<td>Phone</td>
<td>124545</td>
</tr>
</table>
Methods
methods:{
copyToClipboard(containerid){
var range = document.createRange();
range.selectNode(containerid);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand("copy");
window.getSelection().removeAllRanges();
alert("data copied");
}
},
You are doing something wrong in selecting node.
copyToClipboard(containerid){
var range = document.createRange();
let containerNode = document.getElementById(containerid); //// this part
range.selectNode(containerNode); //// this part
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand("copy");
window.getSelection().removeAllRanges();
alert("data copied");
}
To copy html code
copyToClipboard(containerid) {
let containerNode = document.getElementById(containerid);
var textArea = document.createElement("textarea");
textArea.style.position = "fixed";
textArea.style.top = 0;
textArea.style.left = 0;
// Ensure it has a small width and height. Setting to 1px / 1em
// doesn't work as this gives a negative w/h on some browsers.
textArea.style.width = "2em";
textArea.style.height = "2em";
// We don't need padding, reducing the size if it does flash render.
textArea.style.padding = 0;
// Clean up any borders.
textArea.style.border = "none";
textArea.style.outline = "none";
textArea.style.boxShadow = "none";
// Avoid flash of white box if rendered for any reason.
textArea.style.background = "transparent";
textArea.value = containerNode.outerHTML;
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
document.execCommand("copy");
window.getSelection().removeAllRanges();
document.body.removeChild(textArea);
alert("data copied");
}

Videojs : How can I disable play/pause on click?

I am using the videojs framework.
I want to implement click action.
When I click the player, I want to get information about mouse position (x,y) and current time in video.
However, I don't want to play/pause video.
and I want to show control bar.
How can I do?
Here is body part (below)
<video
id="myvideo"
class="video-js"
controls
preload="auto"
data-setup='{}'>
<source src="http://media.w3.org/2010/05/sintel/trailer.mp4" type="video/mp4"></source>
<source src="http://media.w3.org/2010/05/sintel/trailer.webm" type="video/webm"></source>
<source src="http://media.w3.org/2010/05/sintel/trailer.ogv" type="video/ogg"></source>
<p class="vjs-no-js">
To view this video please enable JavaScript, and consider upgrading to a
web browser that
<a href="http://videojs.com/html5-video-support/" target="_blank">
supports HTML5 video
</a>
</p>
</video>
<script type="text/javascript">
videoElement = document.getElementById("myvideo");
videoElement.addEventListener("mousedown", mouseHandler, false);
function getElementCSSSize(el) {
var cs = getComputedStyle(el);
var w = parseInt(cs.getPropertyValue("width"), 10);
var h = parseInt(cs.getPropertyValue("height"), 10);
return {width: w, height: h}
}
function mouseHandler(event) {
var size = getElementCSSSize(this);
var scaleX = this.videoWidth / size.width;
var scaleY = this.videoHeight / size.height;
var rect = this.getBoundingClientRect(); // absolute position of element
var x = ((event.clientX - rect.left) * scaleX + 0.5)|0; // round to integer
var y = ((event.clientY - rect.top ) * scaleY + 0.5)|0;
console.log("x : " + x);
console.log("y : " + y);
console.log("Video Current Time :" + videoElement.currentTime);
}
</script>
I tried this code in css file.
.vjs-tech {
pointer-events: none;
}
If I write this statement, video player don't play or stop when I click the video. But, my mouseHandler action is also didn't work.
My videojs version is 6.2.0
I solved this problem. In my click event, I implemented play toggle action again.
function mouseHandler(event) {
if(video.paused()){
video.play();
}
else{
video.pause();
}
var size = getElementCSSSize(this);
var scaleX = this.videoWidth / size.width;
var scaleY = this.videoHeight / size.height;
var rect = this.getBoundingClientRect(); // absolute position of element
var x = ((event.clientX - rect.left) * scaleX + 0.5)|0; // round to integer
var y = ((event.clientY - rect.top ) * scaleY + 0.5)|0;
console.log("x : " + x);
console.log("y : " + y);
console.log("Video Current Time :" + videoElement.currentTime);
}
I solved this problem by css and changing option setting.
css:
.video-js.vjs-has-started .vjs-tech {
pointer-events: none;
}
JS:
var options = {controlBar: {
children: [
"durationDisplay",
"timeDivider",
"currentTimeDisplay",
"fullscreenToggle"
]
}};
var player = videojs('my-player', options);
enter link description here

Change avatar with vue.js without refresh?

I have this in view:
<div class="seller_image" :style="{background: 'url(' + user_credentials.avatar +')', backgroundSize: 'cover ', display: 'block'}">
</div>
In vue i have this:
setAvatar:function(x,y,w,h){
this.setAvatarLoader = true;
var data = new FormData();
this.x1 = $('#x1').val();
this.y1 = $('#y1').val();
this.w = $('#w').val();
this.h = $('#h').val();
this.x2 = $('#x2').val();
this.y2 = $('#y2').val();
data.append('avatar',this.$els.fileAvatarImage.files[0]);
data.append('x1',this.x1);
data.append('x2',this.x2);
data.append('y1',this.y1);
data.append('y2',this.y2);
data.append('w',this.w);
data.append('h',this.h);
user_id = this.user_credentials.user_id;
this.$http.post('/profile/' + user_id + '/basic_info/set_avatar',data).then(function(response){
this.avatarImageSet = false;
public_path = response.data.public_path;
url_path = response.data.url_path;
filename = response.data.filename;
this.setAvatarLoader = false;
this.basic_status = true;
this.basic_success_message = response.data.successMsg;
this.profile_image = url_path;
this.user_credentials.avatar = url_path
this.getAvatar();
$("html, body").animate({ scrollTop: 0 }, "slow");
}, function(response) {
this.setAvatarLoader = false;
$('#myModal').modal('hide');
this.getAvatar();
console.log('error');
});
},
When I refresh the page I get the avatar but in time when I set it it does not change the image.
Any suggestion?
As #AWolf said, it's difficult to guess what's the problem with your code because I can see only a part of your code base.
Another possible issue could be the url_path. If it remains the same, will never change. So, you need to append the timestamp:
this.user_credentials.avatar = url_path + '?' + Date.now()
https://jsfiddle.net/pespantelis/fy0re26m/
As mentioned in the comments, try to avoid jQuery because it's most of the time not needed and it is making things more complicated.
Please have a look at the demo below for a simple image uploader/avatar changer or at this fiddle.
The demo just opens a file picker dialog and then the returned file is used to update the displayed image. (Posting to server is not added in the demo.)
To your code:
Something like $('#x1').val() shouldn't be done with Vue.js because in Vue you're doing that model driven.
So the only source of truth is your data model and not the stuff displayed in the DOM.
Not sure what you're trying to do with the x1,y1, ... code. That's not clear from your snippet with-out the html markup.
new Vue({
el: '#app',
data() {
return {
user_credentials: {
avatar: 'https://unsplash.it/100/100'
}
}
},
methods: {
changeAvatar() {
const input = document.createElement('input');
let self = this;
input.setAttribute("type", "file");
input.addEventListener('change', function(e) {
// uploading code from this fiddle: http://jsfiddle.net/vacidesign/ja0tyj0f/
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
// image is loaded callback
self.user_credentials.avatar = e.target.result;
// here you can post the data to your backend...
};
reader.readAsDataURL(this.files[0]);
}
})
input.click(); // opening dialog
return false; // avoiding navigation
}
}
})
.seller_image {
width: 200px;
height: 200px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.10/vue.js"></script>
<div id="app">
<div class="seller_image" :style="{background: 'url(' + user_credentials.avatar +')', backgroundSize: 'cover ', display: 'block'}">
</div>
<button #click="changeAvatar()">
Change
</button>
</div>

PhantomJS/CasperJS -- continue execution after programmatically clicking button that reloads page [duplicate]

This question already has an answer here:
Cannot get link to be clicked and switch to next page using PhantomJS
(1 answer)
Closed 7 years ago.
I am attempting to automate a website on my remote server using PhantomJS.
For this website I have to log in with my username and password.
Examining the HTML, I see:
<form class="" method="post" action="https://foo.com/login/"
id="foo_login_bar" accept-charset="utf-8">
<input tabindex="1" name="user_name" id="user" value="" type="text">
<input tabindex="2" name="password" id="pass" value="" type="password">
<div class="wrapper_login_button">
<input class="saved_url_for_login" name="login_url"
value="http://foo.com/" type="hidden">
<input tabindex="3" id="login_button" class="btn left login_button"
name="login" value="Login" type="submit">
</div>
</form>
So I try:
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
console.log('CONSOLE: ' + msg);
};
page.open('http://foo.com', function(status)
{
console.log("Status: " + status);
if(status === "success")
page.evaluate( bot );
page.render('example.png');
phantom.exit();
});
function bot()
{
if( ! Foo.isLoggedIn() ) {
console.log("Not logged in!");
document.getElementById( "user" ).value = "myuser";
document.getElementById( "pass" ).value = "mypass";
document.getElementById( "login_button" ).click();
}
}
Examining the screenshot shows that it has correctly entered text into the user and password fields, but it has failed to refresh the page.
i.e. If I fill out both fields and click the login button on Firefox, it takes me to my account homepage.
I'm guessing that what is happening here is that the code is immediately reaching the screenshot before the page has had a chance to reload.
How can I get execution to continue once the reload has completed?
EDIT: Phantomjs login, redirect and render page after pageLoad finishes
I'm guessing that what is happening here is that the code is immediately reaching the screenshot before the page has had a chance to reload.
You are absolutely right, you need to wait for the page to reload.
In PhantomJS you can register callback functions for when a page is done loading.
var page = require('webpage').create();
var action;
page.onLoadFinished = function(result)
{
page.render('example' + (new Date()).getTime() + '.png');
// Need to check `action` variable because
// this callback will also fire when opening page for the first time
if(action == "loggin in")
{
phantom.exit();
}
}
page.onConsoleMessage = function(msg) {
console.log('CONSOLE: ' + msg);
};
page.open('http://foo.com', function(status)
{
console.log("Status: " + status);
if(status === "success")
{
action = "loggin in";
page.evaluate( bot );
}
});
function bot()
{
if( ! Foo.isLoggedIn() )
{
console.log("Not logged in!");
document.getElementById( "user" ).value = "myuser";
document.getElementById( "pass" ).value = "mypass";
document.getElementById( "login_button" ).click();
}
}

How to Get GPS data of a path by drawing on a Map

I need a data set of location points (Lat. and Lon.) is there any tool I can use where I can draw the path on a map and get the points as required format? Or is there any other easy way to do this? Thanks in Advance.
I have found a solution check it out, and make sure add the external Jar and CSS resorses.
The HTML
<div id="map" style="width: 800px; height:500px" align="center"></div>
<br>
<button type="button" onclick="getAllLocations();">GET ALL THE LOCATIONS</button>
<div>
<h3>Output Console</h3>
<textarea id="TextArea" rows="8" cols="80"></textarea>
<br>
The JS
var map = L.map('map').setView([ 6.88869, 79.85878 ], 18);
L.tileLayer(
'https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png',
{
maxZoom : 20,
attribution : 'Map data © OpenStreetMap contributors, '
+ 'CC-BY-SA, '
+ 'Imagery © Mapbox',
id : 'examples.map-i86knfo3'
}).addTo(map);
var poly = L.polyline([], {
color : 'green'
});
poly.addTo(map);
map.on('click', function(e) {
poly.addLatLng(e.latlng);
//alert();
});
getAllLocations = function (){
alert ("Test");
var locArray = poly.getLatLngs();
var area = document.getElementById('TextArea');
for(var i=0; i<locArray.length; i++){
var item2 = locArray[i];
var item3 = "" + item2;
var item4 = item3.split("(");
var item5 = item4[1].split(")")
//alert(item5[0]);
area.value += item5[0] + "\n";
}
}
http://jsfiddle.net/ZdLrb/13/