I have a code for a menu which is implemented for Click.
function DropDown(el) {
this.dd = el;
this.initEvents();
}
DropDown.prototype = {
initEvents : function() {
var obj = this;
var loc = window.location.pathname;
var filename = loc.match(/([^\/]+)(?=\.\w+$)/)[0];
console.log("sssss" + $(this).attr("id"));
obj.dd.on('click', function(event){
console.log($(this).attr("id"));
if(!($(this).hasClass("active")) && ( $(this).attr("id")) === filename) {
console.log("Hiding");
$(this).toggleClass('active');
event.stopPropagation();
}
});
}
}
$(function() {
var dd1 = new DropDown( $('#value') );
var dd2 = new DropDown( $('#diagnostics') );
var dd3 = new DropDown( $('#design') );
var dd4 = new DropDown( $('#delivery') );
//$('.wrapper-dropdown-5').on('click', function(e){ console.log(e); });
$(document).click(function() {
// all dropdowns
$('.wrapper-dropdown-5').removeClass('active');
});
});
If you see obj.dd.on('click', function(event){, that is where the click action is being intercepted. But I want to implement hover state, and to my surprise, it is not working, I tried using hover, mouseover and mouseout there, but nothing works. Only click is working.
Do you have any idea what might be the problem or how could I implement Hover in this scenario?
Thanks
Related
I am trying to add a custom combobox to the toolbar in the forge viewer. Below is the code for it. I am able to successfully able to add buttons and they are functional. But combobox is not. It adds a combobox but it does show the fly out menu when I click on it. Not sure what I am doing wrong. help!
function BuildingToolbarExtension(viewer, options) {
Autodesk.Viewing.Extension.call(this, viewer, options);
}
BuildingToolbarExtension.prototype = Object.create(Autodesk.Viewing.Extension.prototype);
BuildingToolbarExtension.prototype.constructor = BuildingToolbarExtension;
BuildingToolbarExtension.prototype.load = function () {
// Set background environment to "Infinity Pool"
// and make sure the environment background texture is visible
this.viewer.setLightPreset(6);
this.viewer.setEnvMapBackground(true);
// Ensure the model is centered
//this.viewer.fitToView();
return true;
};
BuildingToolbarExtension.prototype.unload = function () {
// nothing yet
if (this.subToolbar) {
this.viewer.toolbar.removeControl(this.subToolbar);
this.subToolbar = null;
}
};
BuildingToolbarExtension.prototype.onToolbarCreated = function (toolbar) {
alert('TODO: customize Viewer toolbar');
var viewer = this.viewer;
// Button 1
var button1 = new Autodesk.Viewing.UI.Button('show-env-bg-button');
button1.onClick = function (e) {
viewer.setEnvMapBackground(true);
};
button1.addClass('show-env-bg-button');
button1.setToolTip('Show Environment');
// Button 2
var button2 = new Autodesk.Viewing.UI.Button('hide-env-bg-button');
button2.onClick = function (e) {
viewer.setEnvMapBackground(false);
};
button2.addClass('hide-env-bg-button');
button2.setToolTip('Hide Environment');
var comboButton = new Autodesk.Viewing.UI.ComboButton('buildings');
comboButton.setToolTip('buildings');
this.floors = new Autodesk.Viewing.UI.ControlGroup('my-custom-toolbar1');
this.floors.addControl(button1);
this.floors.addControl(button2);
comboButton.addControl(this.floors);
comboButton._isCollapsed = true;
comboButton.onClick = function (e) {
this.setCollapsed(false);
}
// SubToolbar
this.subToolbar = new Autodesk.Viewing.UI.ControlGroup('my-custom-toolbar');
this.subToolbar.addControl(button1);
this.subToolbar.addControl(button2);
this.subToolbar.addControl(comboButton);
toolbar.addControl(this.subToolbar);
};
Autodesk.Viewing.theExtensionManager.registerExtension('BuildingToolbarExtension', BuildingToolbarExtension);
The ControlGroup is unnecessary in your case, please refer the following to add buttons to ComboButton
var comboButton = new Autodesk.Viewing.UI.ComboButton('buildings');
comboButton.setToolTip('buildings');
// Button 1
var button1 = new Autodesk.Viewing.UI.Button('show-env-bg-button');
button1.onClick = function (e) {
viewer.setEnvMapBackground(true);
};
button1.addClass('show-env-bg-button');
button1.setToolTip('Show Environment');
comboButton.addControl(button1);
// Button 2
var button2 = new Autodesk.Viewing.UI.Button('hide-env-bg-button');
button2.onClick = function (e) {
viewer.setEnvMapBackground(false);
};
button2.addClass('hide-env-bg-button');
button2.setToolTip('Hide Environment');
comboButton.addControl(button2);
Here are snapshots:
Before opening
After opening
I am using fabric js version 1.7.22
when image set in a repetitive manner in a rectangle of fabric js, at
the first time it will be loaded and saved into JSON using toJSON()
and save an image using todataUrl() method, but when cal canvas a loadFromJson method at that time, this canvas not savable, because it throws tainted canvas error.
Please help me,
I already set crossOrigin in a pattern but it not working. and not
added in canvas JSON.
I have made one Fiddle For Generate Issue :
[http://jsfiddle.net/Mark_1998/kt387vLc/1/][1]
Steps to generate issue :
click on 'set pattern'
then click on 'save canvas'
then click on 'reload canvas' // load canvas from JSON
then click on 'save canvas' // cause issue of tainted canvas
This issue is fixed in new version of fabricjs already. If you are still using 1.7.20 the override fabric.Pattern.prototype.toObject and fabric.Pattern.prototype.initialize, find code in snippet.
var canvas = new fabric.Canvas('canvas', {
height: 500,
width: 500,
});
canvas.backgroundColor = '#ff0000';
canvas.renderAll();
var canvasJSON = {};
document.getElementById('setPat').addEventListener('click', function() {
fabric.util.loadImage('https://cdn.dribbble.com/assets/icon-backtotop-1b04df73090f6b0f3192a3b71874ca3b3cc19dff16adc6cf365cd0c75897f6c0.png', function(image) {
var pattern = new fabric.Pattern({
source: image,
repeat: 'repeat',
crossOrigin: 'Anonymous'
});
var patternObject = new fabric.Rect({
left: 0,
top: 0,
height: canvas.height,
width: canvas.width,
angle: 0,
fill: pattern,
objectCaching: false
})
canvas.add(patternObject);
}, null, {
crossOrigin: 'Anonymous'
});
})
document.getElementById('saveCanvas').addEventListener('click', function() {
console.log('save canvas');
canvasJSON = canvas.toJSON();
var image = canvas.toDataURL("image/png", {
crossOrigin: 'Anonymous'
}); // don't remove this, i need it as thumbnail.
//console.log('canvas.Json', canvasJSON);
//console.log('image', image);
canvas.clear();
canvas.backgroundColor = '#ff0000';
canvas.renderAll();
});
document.getElementById('reloadCanvas').addEventListener('click', function() {
console.log('save canvas');
canvas.loadFromJSON(canvasJSON, function() {
canvas.set({
crossOrigin: 'Anonymous'
})
});
console.log('canvas.Json', canvasJSON);
});
//cross origin was not added in toObject JSON
fabric.Pattern.prototype.toObject = (function(toObject) {
return function() {
return fabric.util.object.extend(toObject.call(this), {
crossOrigin: this.crossOrigin,
patternTransform: this.patternTransform ? this.patternTransform.concat() : null
});
};
})(fabric.Pattern.prototype.toObject);
//cross origin was not added while creating image
fabric.Pattern.prototype.initialize = function(options, callback) {
options || (options = {});
this.id = fabric.Object.__uid++;
this.setOptions(options);
if (!options.source || (options.source && typeof options.source !== 'string')) {
callback && callback(this);
return;
}
// function string
if (typeof fabric.util.getFunctionBody(options.source) !== 'undefined') {
this.source = new Function(fabric.util.getFunctionBody(options.source));
callback && callback(this);
} else {
// img src string
var _this = this;
this.source = fabric.util.createImage();
fabric.util.loadImage(options.source, function(img) {
_this.source = img;
callback && callback(_this);
}, null, this.crossOrigin);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.20/fabric.js"></script>
<button id="setPat">
Set pattern
</button>
<button id="saveCanvas">
Save canvas
</button>
<button id="reloadCanvas">
Reload CAnvas
</button>
<canvas id="canvas"></canvas>
I have created Chrome extension and use pusher to receive some data from server.
When I test it show multiple duplicate data because it follow tabs that I opened.
anyone understand me.Help me please.Thank you in advance.
Content.js
Pusher.Util.getLocalStorage = function()
{
return undefined;
}
Pusher.ScriptRequest.prototype.send = function(receiver) {
var xhr = new XMLHttpRequest();
xhr.open("GET", this.src, true);
xhr.send();
}
document.addEventListener('DOMContentLoaded', function () {
if (Notification.permission !== "granted")
Notification.requestPermission();
});
var pusher = new Pusher('xxxxxxxxxxxxxxxxxxxxx');
var notificationsChannel = pusher.subscribe('notifications');
notificationsChannel.bind('new_notification', function(notification){
// assign the notification's message to a <div></div>
var message = notification.message;
if (!Notification) {
alert('Desktop notifications not available in your browser. Try Chromium.');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
console.log(message);
var notification = new Notification('แจ้งเตือน', {
icon: 'img/LOGO.png',
body: message,
});
notification.onclick = function () {
location.reload();
};
}
});
duplicate notification
I know how to drag and drop in one window with html5. But how to drag and drop across frames?
Here is my script which can work in one window. Can someone help me?
<script>
var drag = document.getElementById("drag");
var drop = document.getElementById("drop");
drag.onselectstart = function () {
return false;
}
drag.ondragstart = function (ev) {
ev.dataTransfer.effectAllowed = "move";
ev.dataTransfer.setData("text", ev.target.innerHTML);
}
drag.ondragend = function (ev) {
var text = ev.dataTransfer.getData("text");
alert(text);
ev.dataTransfer.clearData("text");
return false;
}
drop.ondragover = function (ev) {
ev.preventDefault();
return true;
}
drop.ondragenter = function (ev) {
this.background = "#ffffff";
return true;
}
drop.ondrop = function (ev) {
}
</script>
#Nickolay: oh, ok.
There's an example at http://www.useragentman.com/blog/2010/01/10/cross-browser-html5-drag-and-drop/ .
Added:
I'm not sure why the OP's code didn't work - maybe it wasn't loaded in both frames? I modified their Javascript a little to give more indications:
window.onload = function () {
var drag = document.getElementById('drag');
var drop = document.getElementById("drop");
if (drag) {
drag.style.backgroundColor = '#00ff00';
drag.onselectstart = function () {
return false;
}
drag.ondragstart = function (ev) {
ev.dataTransfer.effectAllowed = "move";
ev.dataTransfer.setData("text", ev.target.innerHTML);
}
drag.ondragend = function (ev) {
var text = ev.dataTransfer.getData("text");
alert(text);
//ev.dataTransfer.clearData("text");
return false;
}
}
if (drop != null) {
drop.style.backgroundColor = '#0000ff';
drop.ondragover = function (ev) {
ev.preventDefault();
return false;
}
drop.ondragenter = function (ev) {
this.style.backgroundColor = "#ff0000";
return false;
}
drop.ondrop = function (ev) {
return false;
}
}
}
It works between iframes and between browser windows (only tested in Firefox 11 and IE9 on Windows 7 x64).
I modified your script to work in the case that the iframe name is "frame1". Please check it now.
<script type="text/javascript">
window.onload = function ()
{
var drag = document.getElementById("drag");
var drop = frame1.document.getElementById("drop");
drag.draggable = true;
drag.onselectstart = function () {
return false;
}
drag.ondragstart = function (ev) {
ev.dataTransfer.effectAllowed = "move";
ev.dataTransfer.setData("text", ev.target.innerHTML);
}
drop.ondragover = function (ev) {
ev.preventDefault();
return true;
}
drop.ondragenter = function (ev) {
this.background = "#ffffff";
return true;
}
drop.ondrop = function (ev) {
var data = ev.dataTransfer.getData("text");
drop.innerHTML += data;
ev.preventDefault();
}
}
Check out the tutorial for Cross-Frame Drag and Drop. It explains the events required and the basic flow when working with multiple frames.
http://blog.dockphp.com/post/78640660324/cross-browser-drag-and-drop-interface-development-using
How are the iframes hosted? are you just using html files? as this could potentially be the issue.
I created a couple of html files with the drag and drop code in your question, this didn't work when just referencing each other. However when I added the files to IIS server and referenced the files using localhost it then started to work.
I have an website I'm working on that uses Ajax it uses pushState and popstate, it works great in HTML5 browsers, but I want to get it to work in HTML4 browsers, IE& 8 and IE9.
I have tried History.js,
https://github.com/browserstate/History.js/
but cant' for the life of me figure out how to implement it. could some one give me some pointers?
Here is the code I'm using for HTML5,
if (history.pushState) {
function currentPage(url){
var index = /index/g,
program = /program/g,
photos = /photos/g,
testimonials = /testimonials/g,
about = /about/g,
contact = /contact/g;
if (program.test(url)){
changeCurrentPage('#program');
document.title = "Our Programs Kolibri Daycare";
}else if (photos.test(url)){
changeCurrentPage('#photos');
document.title = "Photos Kolibri Daycare";
}else if (testimonials.test(url)){
changeCurrentPage('#testimonials');
document.title = "Tesimonials Kolibri Daycare";
}else if (about.test(url)){
changeCurrentPage('#about');
document.title = "About Kolibri Daycare";
}else if (contact.test(url)){
changeCurrentPage('#contact');
document.title = "Contact Kolibri Daycare";
}else {
changeCurrentPage('#home');
document.title = "Kolibri Daycare";
}
}
function changeContent(url) {
$.ajax({
url: "getContents.php?url=" + url,
success: function(responseText){
$("#content").html(responseText);
}
});
currentPage(url);
}
$(document).ajaxComplete(function(event, request, settings) {
if (settings.url == 'getContents.php?url=photos.html') {
$("a[rel=example_group]").fancybox({
'overlayShow' : false,
'cyclic' : true,
'transitionIn' : 'elastic',
'transitionOut' : 'elastic'
});
}
});
$(document).ready(function() {
var elems = null,
links = null,
link = null,
i;
elems = document.getElementById('nav');
links = elems.getElementsByTagName('a');
if (links) {
for (i = 0; i < links.length; i++) {
links[i].addEventListener("click", function(e) {
var url = $(this).attr("href");
changeContent(url);
history.pushState(null, null, url);
e.preventDefault();
}, false);
}
}
window.setTimeout(function() {
/*window.addEventListener("popstate", function(e) {*/
window.onpopstate = function (e) {
var pathArray = window.location.pathname.split( '/' );
var n = pathArray.length;
if (pathArray[n-1]){
changeContent(pathArray[n-1]);
}else {
changeContent('index.html');
}
/*}, false);*/
}
}, 1);
});
}
Here is a link to the test site.
http://robfenwick.com/kolibri4/index.html
Ok maybe the problem was that you weren't using History.js in the right way ( that's the problem i was having too ). Basically to use History.js in the correct way you must do something like:
// Register navigation click handlers where you will load Ajax content
$( window ).on( 'click', 'a.ai1ec-load-view', handle_click_on_link_to_load_view );
// Bind to the statechange event
$( window ).bind( 'statechange', handle_state_change );
// When the state changes, load the corresponding view
var handle_state_change = function( e ) {
var state = History.getState();
load_view( state.url, 'json' );
};
// When clicking on a link you want to load, trigger statechange by changing state
var handle_click_on_link_to_load_view = function( e ) {
e.preventDefault();
History.pushState( { target :this }, null, $( this ).attr( 'href' ) );
};
Before doing this i wasn't listening to statechange and i was simply using pushState() in the link click handler.
If you do it like this there is no need to code a fallback, it will work also in html4 browsers ( and bookmarks from html4 browsers will work as expected )