Close menu event in jQuery - javascript

I have a menu plugin in jQuery.
The menu is closed only when i click the inner circle of it...
www.tranceil.fm -> click the headphones
I want to close the menu by clicking anywhere, not just the inner circle
the header code is this
<script type="text/javascript">
jQuery(document).ready(function(){
var pieMenu = jQuery('#promo').pieMenu({icon : [
{
path : "/wp-content/themes/Tersus/images/piemenu/winamp.png",
alt : "Winamp",
fn : function(){('Click:: Plus');window.location.href = 'http://94.23.250.14:2199/tunein/tranceilfm.pls';return false}
}, {
path : "/wp-content/themes/Tersus/images/piemenu/vlc.png",
alt : "VLC Media Player",
fn : function(){('Click:: Plus');window.location.href = 'http://94.23.250.14:2199/tunein/tranceilfm.pls';return false}
},{
path : "/wp-content/themes/Tersus/images/piemenu/QuickTime.png",
alt : "Quick Time Player",
fn : function(){('Click:: Plus');window.location.href = 'http://94.23.250.14:2199/tunein/tranceilfm.qtl';return false}
},{
path : "/wp-content/themes/Tersus/images/piemenu/WMP.png",
alt : "Windows Media Player",
fn : function(){('Click:: Plus');window.location.href = 'http://94.23.250.14:2199/tunein/tranceilfm.asx';return false}
},{
path : "/wp-content/themes/Tersus/images/piemenu/popup.png",
alt : "נגן Popup",
fn : function(){jQuery("#popupplay").click();return false}
},{
path : "/wp-content/themes/Tersus/images/piemenu/iTunes.png",
alt : "iTunes",
fn : function(){alert('...בקרוב');return false}
}],
beforeMenuOpen: function(){
jQuery('<div id="shadow"></div>').css(
{
'position':'fixed',
'background-color':'#000000',
'opacity': 0.6,
'width':'100%',
'height':'100%',
'z-index' :999,
'top':0,
'left':0
}).appendTo('body');
},
beforeMenuClose: function(){
jQuery('#shadow').remove();
}
});
jQuery('#promo').click(function(){
if(jQuery('#'+pieMenu.id).css('display') != 'block') //if jpie is not visible
pieMenu.initMenu(760,150);
})
});
</script>
The click event in the JS file ->
//click event
jQuery('#'+idCore).live({
click: function() {
if(closable)
removeMenu();
},
contextmenu:function(e){
e.preventDefault();
}
})
Any thoughts?

Looks like you need to remove the pie0 div and the shadow div when the shadow is clicked, because they're being entirely generated/re-generated whenever they are brought on/back to the screen.
So just add this:
$('#shadow').on('click', function(event){
$('#pie0').remove();
$(this).remove();
});
Update: I just realized: because shadow is added dynamically after a user-event, and not present on documentready, you need to define it by attaching it to the body element, and delegating to a click on the shadow element, like this:
$('body').on('click', 'shadow', function(event){
$('#pie0').remove();
$(this).remove();
});

If you want to close it by clicking anywhere:
$(document).live({
....
});
The problem that you will face here is that this click will cause other clicks also to happen. For example, if the user clicks on some link or something, he will be redirected and also the menu will be closed. Moreover, since document is a top level element, events will never propogate FROM it, they will always propogate TO it. Even if such was not the case, live works in a way such that it handles events once they have propagated to the top
What you can do is, set it up in capture mode:
document.addEventListener('click', function(event) {
if(closeable) {
removeMenu();
event.stopPropogation();
}
}, true);
The true parameter at the end sets this event listener in the capturing mode, which will cause it to call the event handler of the highest order ancestor there is, which will be there for document. After calling that event, the event is then bubbled to the target. And within document's event handler, if we consume an event (we shall do it ONLY and ONLY if closeable is set), then we don't propagate it at all.

Related

simulated call onMouseDown in console

There is a div element on the page, by clicking on it a menu with a choice of the displayed number of elements is created.
Menu:
How to call this action through the console (onMouseDown React)?
Code:
In the console you want to grab your element and then use a dispatch event to simulate a mouseover or click
var div = document.querySelector("#myDiv");
var myEventToDispatch = new MouseEvent("click"); //or "mousedown", whichever you need
div.dispatchEvent(myEventToDispatch);
These three lines in your console should do the trick.
Checkout: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent for more options
found a solution, works in practice. The menu implementation on the site consisted of several nested divs and one input. None of these elements responded to the click () function. The solution below solved my problem and the next steps I needed.
<pre><code>
var MENU = IFrame.contentDocument.getElementsByClassName("class box menu")[0]; // getElementsById, getElementsByTag[0] ....
MENU = MENU.getElementsByTagName("div");
var MaxList = MENU[1].getElementsByTagName("input")[0];
if(MaxList != undefined)
{
if(MENU[0].textContent != "100 items")
{
// focus menu
MaxList.focus();
var e = new KeyboardEvent(
"keydown",
{
bubbles : true,
cancelable : true,
key : "ArrowDown",
char : "ArrowDown",
shiftKey : true
}
);
// scroll down the list
MaxList.dispatchEvent(e);
MaxList.dispatchEvent(e);
MaxList.dispatchEvent(e);
// choice
e = new KeyboardEvent(
"keydown",
{
bubbles : true,
cancelable : true,
key : "Enter",
char : "Enter",
shiftKey : true
}
);
MaxList.dispatchEvent(e);
}
}
</code></pre>
VKomyak (Volt_Nerd)

How to restrict TAB navigation within the one window widget?

I have a Webix modal window with a form with several inputs:
var form = {
view:"form",
borderless:true,
elements: [
{ view:"text", label:'Login', name:"login" },
{ view:"text", label:'Email', name:"email" },
{
view:"button", value: "Submit", click:function(){
console.log(this.getParentView().getValues())
}}
]
};
The following sample there's a window that illustrates the current behavior:
http://webix.com/snippet/4bd116bb
If I use TAB navigation, focus goes out the window from the last in-window control. Is there a way to localize TAB navigation within the window once the focus gets in?
Code can catch onFocusChange event and move focus back if target is outsideo of the window.
webix.attachEvent("onFocusChange", function(target){
if (!target || target.getTopParentView() != $$("win"))
webix.delay(function(){
webix.UIManager.setFocus($$("win").getBody().elements.login);
});
});
http://webix.com/snippet/7db250dd

jquery draggable in iframe won't click

I have created a draggable within an iframe from it's parent and I would like to attach an event for when the draggable is clicked.
The draggable works by itself and all the click functions work by themselves, however as soon as you mix the two together the left click events stop working. If I remove the iframe and put the draggable and click bindings in a seperate page it works fine.
parent.html
<iframe id="siteframe" src="http://jsfiddle.net/kyT6N/show/light/">
parent.js
$('#siteframe').load(function () {
$('#siteframe').contents().find('.draggable').draggable({ delay:200, iframeFix: true});
$('#siteframe').contents().find('.draggable').bind('mouseup',function() {
alert('mouse up');
});
$('#siteframe').contents().find('.draggable').click(function() {
alert('click');
});
$('#siteframe').contents().find('.draggable').on('click', function() {
alert('click');
});
});
iframe.html
<div class="draggable">draggable</div>
JSFiddle code:
http://jsfiddle.net/A5T3Q/
JSFiddle demo:
http://jsfiddle.net/A5T3Q/show/light/
EDIT:
After investigating a bit further it seems that it's the iframeFix: true option that messes with the click function, I'm guessing this is because it overlays the iframe? is there anything that can be done about this?
I think it is the problem that jquery ui create iframeFix mask too fast immediately after the mousedown event occured , but the delay is only use for mousestart control . So this can be optimized by add a function _iframeFix .
_iframeFix: function(event){
//patch for iframe
var o=this.options;
if(o.iframeFix === true){
$("div.ui-draggable-iframeFix").each(function() {
this.parentNode.removeChild(this);
});
}
$(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() {
$('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>')
.css({
width: this.offsetWidth+"px", height: this.offsetHeight+"px",
position: "absolute", opacity: "0.001", zIndex: 1000
})
.css($(this).offset())
.appendTo("body");
});
}
remove the iframe mask code in the _mouseCapture function ,and to create iframe mask after delay .
Also , you should add a mouseup event handle for the drag element in the iframe to endup the timeout control
if(o.iframeFix&&o.delay){
that.element
.bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
}
And final in the _mouseup function, clear the mouseup handle ,clear the timeout
_mouseUp: function(event) {
$(document)
.unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
.unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
var o=this.options;
if(o.iframeFix&&o.delay){
mouseHandled = false;
this.element
.unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
}
if(this._mouseDelayTimer) clearTimeout(this._mouseDelayTimer);
if (this._mouseStarted) {
this._mouseStarted = false;
if (event.target === this._mouseDownEvent.target) {
$.data(event.target, this.widgetName + '.preventClickEvent', true);
}
this._mouseStop(event);
}
return false;
},
Your code is right, but, you are loading iframe from different URL.
If parent domain and iframe url domain is different then javascript don't allows you to access iframe element.

two onClick() events happening simultaneously?

What I am expecting from my code is this:
When clicking a button, a menu of options appears at the pointer position. Any following click, whether on a menu item or elsewhere in the browser, should close the menu. Clicking on a menu item closes the menu, but not clicking anywhere else. When I uncomment $(document.body).one('click', function() {menu.remove()} the menu never appears in the first place, and I suspect that I somehow have it arranged so that the click to bring up the menu actually closes the menu as well. Here is the code:
render : function() {
this.$el.html(this.template(this.model.toJSON()));
var that = this;
if (this.model.attributes.memberType != 'OWNER') {
this.$('.memberTypeSelector').button({
icons : {
secondary : "ui-icon-triangle-1-s"
}
}).click(function(event) {
that.showPermissions(that.model, event, that);
});
...
},
showPermissions : function(member, event, view) {
var levels = ['ADMIN', 'CONTRIBUTOR', 'VIEWER'];
var menu = $('<ul>');
$.each(levels, function() {
if(member.attributes.memberType !== this) {
var item = $('<li>').appendTo(menu);
$('<a>').attr('href', '#').text(this).appendTo(item).click(function() {
menu.remove();
view.changePermission(member, this.text, view);
});
}
});
menu.menu().css({
position : 'absolute',
left : event.clientX,
top : event.clientY
});
$(document.body).append(menu);
/*$(document.body).one('click', function() {
menu.remove();
});*/
}
Thanks in advance for your help.
If you delay binding to the document by 10ms, that should be enough time for the event to propagate to the body so that it doesn't immediately close the menu, then the next click on the menu will result in the body click handler triggering.
setTimeout(function(){
$(document.body).one('click', function() {menu.remove();});
},10)
you can't use stop propagation or anything similar because that would also stop the 2nd click on the menu.
While delaying the second event binding will probably work 99.999% of the time, I can't help but feel that nagging 'what if' for the one time that something lags and it doesn't work.
This question provides a more satisfactory (at least to me) solution

Hide a text input on a dialog box of CKEditor

I'm working on a plugin in CKEditor which have as a goal to hide or show element depending on which of my check box is checked. I have those element defined :
contents :
[
{
id : 'tab1',
label : 'Configuration Basique',
elements :
[
{
type : 'checkbox',
id : 'check',
label : 'Vers une page web',
'default' : 'unchecked',
onClick : function(){
}
},
{
type : 'text',
id : 'title',
label : 'Explanation',
}
]
},
{
id : 'tab2',
label : 'Advanced Settings',
elements :
[
{
type : 'text',
id : 'id',
label : 'Id'
}
]
}
],
so now what i would like to do is to hide no disable the text input with the label and print it only when the box is checked. So i've seen that i should use something like that :
onLoad : function(){
this.getContentElement('tab1','title').disable();
},
but the thing is i don't want to disable it i want to hide and then print it if the user check the box (which is why i put a onClick function in my checkbox). i've tryed to use the hide() function but it doesn't work and also the setAttribute('style','display : none;')
Tia :)
If you actually want to hide (and not disable) the element you can do this using
this.getContentElement('tab1','title').getElement().hide();
The extra getElement() call returns the litteral DOM object for your contentElement object, so you can call hide()/show() at will on it.
The onClick properties is available and does work on uiElement although it is not documented. The biggest problem is the definition of "this" is not the same inside the event than other place in the config. You first have to get the dialog to get other fields:
{
type: 'checkbox',
id: 'check',
label: 'check',
onClick: function() {
var dialog = this.getDialog()
if(this.getValue()){
dialog.getContentElement('tab1','title' ).disable();
} else {
dialog.getContentElement('tab1','title' ).enable()
}
}
}
Your checkbox definition is correct but there's no such thing like onClick property in dialog uiElement definition. All you got to do is to attach some listeners and toggle your field. Here you go:
CKEDITOR.on( 'dialogDefinition', function( ev ) {
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if ( isThisYourDialog? ) {
...
// Toggle your field when checkbox is clicked or dialog loaded.
// You can also use getInputElement to retrieve element and hide(), show() etc.
function toggleField( field, check ) {
field[ check.getValue() ? 'enable' : 'disable' ]();
}
var clickListener;
dialogDefinition.onShow = function() {
var check = this.getContentElement( 'tab1', 'check' ),
// The element of your checkbox.
input = check.getInputElement(),
// Any field you want to toggle.
field = this.getContentElement( 'tab1', 'customField' );
clickListener = input.on( 'click', function() {
toggleField( field, check );
});
// Toggle field immediately on show.
toggleField( field, check );
}
dialogDefinition.onHide = function() {
// Remove click listener on hide to prevent multiple
// toggleField calls in the future.
clickListener.removeListener();
}
...
}
});
More docs: uiElement API, dialog definition API.

Categories

Resources