Backbone Events on jquery tool tip - javascript

I'm using JQuery Tool Tip in on my HTML page and in that tool tip I've User Name and a Sign Out Link.
Now I'm trying to bind the event in my backbone view, on the id of the Sign Out Link.
But the event is not fired.
I removed the tool tip code and then when i clicked on the sign out link the event got fired.
So question here is - Is it possible to bind the backbone event on jquery tool tip? If not than what would be the work around.
Some code snippets
This is the function which is used to apply jquery tool tip
jQuery(function () {
jQuery.widget("ui.tooltip", jQuery.ui.tooltip, {
options: {
content: function () {
// self.addDescendant('toolTip', {selector: templ.loginHelpContent, view: tt});
return jQuery(templ.loginHelpContent).html();
},
show: null,
close: function (event, ui) {
ui.tooltip.hover(
function () {
jQuery(this).stop(true).fadeTo(400, 1);
},
function () {
jQuery(this).fadeOut("400", function () {
jQuery(this).remove();
})
});
},
position: {
my: "left-190 bottom-18",
using: function( position, feedback ) {
jQuery( this ).css( position );
jQuery( "<div>" )
// .addClass( "arrow" )
.addClass( feedback.vertical )
.addClass( feedback.horizontal )
.appendTo( this );
}
},
}
});
jQuery(templ.loginHelpIcon).tooltip();
});
and the HTML
<span id=loginHelpContent style="display:none">
Not Elizabeth Murphy? <a id="logoutLink" style="color:blue;text-decoration: none">Sign out</a><br> and login as a different user.
</span>
When I tried to bind and event on 'logoutLink' it didn't worked.

You can listen to the "tooltipopen" event ".tooltip tooltipopen": "listenTooltip" and in listenTooltip function :
listenTooltip: function( e ) {
var tooltip = $( e )
}
Now you can bind listener to tooltip in this function

Related

JQuery-UI autocomplete search() not displaying DropDownList

Given the documentation for the search method for the Autocomplete Widget, I would expect a button that calls this method would display a box containing a list of available selections. Nothing happens.
I have the following code that creates the autocomplete widget on a text box:
$("#StateListCoolBox").autocomplete({
source: StateListCoolBoxTags,
focus: function( event, ui ) {
$("#StateListCoolBox").val(ui.item.label);
return false;
},
select: function( event, ui ) {
$("#StateListCoolBox").val(ui.item.label);
$("#StateListCoolBox-id").val(ui.item.value);
return false;
}
});
It works fine.
I have the following code attached to the button I want to display the list. It gets called but nothing happens:
function StateListCoolBox_dropDownClick() {
$("#StateListCoolBox").autocomplete("search", "" );
};
I have tested this with text in the corresponding textbox and with the textbox blank.
How do I get a button to behave like the button on a DropDown Combo, so that when clicked, the list of available selections is displayed?
If you look at the "View Source" for this: http://jqueryui.com/autocomplete/#combobox
You will see:
_createShowAllButton: function() {
var input = this.input,
wasOpen = false;
$( "<a>" )
.attr( "tabIndex", -1 )
.attr( "title", "Show All Items" )
.tooltip()
.appendTo( this.wrapper )
.button({
icons: {
primary: "ui-icon-triangle-1-s"
},
text: false
})
.removeClass( "ui-corner-all" )
.addClass( "custom-combobox-toggle ui-corner-right" )
.on( "mousedown", function() {
wasOpen = input.autocomplete( "widget" ).is( ":visible" );
})
.on( "click", function() {
input.trigger( "focus" );
// Close if already visible
if ( wasOpen ) {
return;
}
// Pass empty string as value to search for, displaying all results
input.autocomplete( "search", "" );
});
}
So this shows all the results by triggering focus event on the text field.
How do I get a button to behave like the button on a DropDown Combo, so that when clicked, the list of available selections is displayed?
I think this fits what you wanted to accomplish. So Try the following with minLength: 0:
function StateListCoolBox_dropDownClick() {
$("#StateListCoolBox").trigger("focus").autocomplete( "search", "" );
};
That said, there should be nothing wrong with your method:
Triggers a search event and invokes the data source if the event is not canceled. Can be used by a selectbox-like button to open the suggestions when clicked. When invoked with no parameters, the current input's value is used. Can be called with an empty string and minLength: 0 to display all items.
Your current code is simply missing: minLength: 0. Try both if you like.

swipebox auto transition to next slide

This is more of a tip than a question, but i hope others find this useful.
Basically i needed to make the lightbox slider called 'Swipebox' auto transition to the next slide, I looked online for help but found nothing.
to add this feature to the plugin i added this code:
setInterval(function(){
$this.getNext(); // Auto transitions each slide
}, 5000);
The file for this JS is called 'jquery.swipebox.js'. This is the code where you want to place the code previously mentioned:
/**
* Navigation events : go to next slide, go to prevous slide and close
*/
actions : function () {
var $this = this,
action = 'touchend click'; // Just detect for both event types to allow for multi-input
if ( elements.length < 2 ) {
$( '#swipebox-bottom-bar' ).hide();
if ( undefined === elements[ 1 ] ) {
$( '#swipebox-top-bar' ).hide();
}
} else {
$( '#swipebox-prev' ).bind( action, function( event ) {
event.preventDefault();
event.stopPropagation();
$this.getPrev();
$this.setTimeout();
} );
$( '#swipebox-next' ).bind( action, function( event ) {
event.preventDefault();
event.stopPropagation();
$this.getNext();
$this.setTimeout();
} );
}
$( '#swipebox-close' ).bind( action, function() {
$this.closeSlide();
} );
// THIS IS THE NEW CODE ADDED:
setInterval(function(){
$this.getNext(); // Auto transitions each slide
}, 5000);
},
This function is around about 550 lines down.
Also, to make the slideshow loop back around, you will need to change the option called 'loopAtEnd' from FALSE to TRUE. This is located at the top of the document.
loopAtEnd: true,
Hope this helped :)

Popup window not showing div

I have this JQuery code:
function JQueryPopup(value) {
$(value).toggle();
$('#JQueryClose').click(function(){
$(value).hide();
});
$( document ).on( 'click', function ( e ) {
$(value).hide();
});
$( document ).on( 'keydown', function ( e ) {
if ( e.keyCode === 27 ) { // ESC
$(value).hide();
}
});
}
and a HTML button that calls this function, it doesn't seem to be showing the popup window/div.
here is a fiddle with my full code: http://jsfiddle.net/XHLY8/3/
P.S. i do have this code on another page, i call the function like this:
<script type="text/javascript">JQueryPopup('#customer_popup_notes');</script>
which works fine.
You need to add the following:
$('#inbox_button').on('click', function(event){
event.preventDefault(); // This isn't critical, but you would need
event.stopPropagation();
JQueryPopup('#inbox_div');
});
You want to stop the click event from bubbling up and triggering the following:
$( document ).on( 'click', function { ... });
Otherwise your #inbox_div will be hidden before you can see it.
Here is a working fiddle.
I suggest reading up on stopPropagation and preventDefault.
You dont need
$( document ).on( 'click', function ( e ) {
$(value).hide();
});
Which always hides the Bottom div no matter where u click .
Working fiddle

Imagemap: Leave clicked area's tooltip displayed on mouseout?

I am using the plugin Imagemapster to add highlighting and tooltip functions to an image map. It provides callbacks like so:
image.mapster(
{
mapKey: 'name',
listKey: 'name',
onClick: function (e) {
if(!$(this).hasClass('clicked')){
$(this).addClass('clicked');
}
$('#selections').html(xref[e.key]);
},
onMouseover: function (e) {
$('#selections').html(xref[e.key]);
},
onMouseout: function (e) {
if(!$(this).hasClass('clicked')){
$('#selections').html('');
}
},
});
Here is my example:
http://jsfiddle.net/5scbh/6/
If you click an item, I want that item's tooltip to remain displayed even if you mouseout. I'm sort of there, but the problem is: if you click an item, and then mouseover another area and then mouseout... it doesn't keep the clicked item's tooltip on mouseout.
I like that the tooltip changes on mouseover to whatever you rollover, but once you mouseout of that area or the imagemap, I want it to go back to showing the tooltip of whatever area has been clicked. If you unclick the clicked area so that nothing is clicked, then the tooltip should go away.
Can you help me do this? Thank you.
You can store your current tooltip in a data attribute, then write it back on mouse out.
...
onClick: function (e) {
if(!$(this).hasClass('clicked')){
$(this).addClass('clicked');
}
$('#selections').html(xref[e.key]);
$( '#selections' ).data( 'storage', xref[e.key] );
},
...
onMouseout: function (e) {
if(!$(this).hasClass('clicked')){
$('#selections').html('');
}
if( $( '#selections' ).data( 'storage' ) ) {
$( '#selections' ).html( $( '#selections' ).data( 'storage' ) );
};
},
....
updated your fiddle acordingly.
Here is the updated fiddle, using the correct edits provided by #robotroll, as well as the solution to the selecting/deselecting issue described in my comment above.
That part was solved by using this code:
onClick: function (e) {
if (e.selected) {
$(this).addClass('clicked');
$('#selections').html(xref[e.key]);
$('#selections').data( 'storage', xref[e.key] );
} else {
$(this).removeClass('clicked');
$('#selections').removeData();
$('#selections').html('');
}
},
http://jsfiddle.net/5scbh/10/

How to extend the jQuery accordion plugin

How to extend a jQuery plugin?
currently I am using multiopen accordion plugin.
I need to add new feature like once the expand/collapse is finished I need to callback a function as like change event in jquery ui accordion plugin.
How to add this feature in this plugin.
you dont need the accordion widget for that. you can do this with a few lines of jQuery.
html:
<h3 class="header"> Title 1 </h3>
<div class="content"> Content 1 </div>
<h3 class="header"> Title 2 </h3>
<div class="content"> Content 2 </div>
javascrpt/jQuery:
( function( $ ){ // closure to make sure jQuery = $
$( function(){ // on document load
$( ".header" ).click( function( e ){ // select headers and set onClick event handler
// here you can maybe add a class to an opened header like this
$( this ).toggleClass( "open" );
$( this ).next().toggle( "slow", function(){ // toggle visibility
// what you write here will be executed after the animation
// "this" will refer to the hidden/revealed div element
// if you want to call a function depending on if the
// panel was opened or closed try this
if ( $( this ).is( ":visible" ) ) {
tabOpened( e, this );
} else {
tabClosed( e, this );
}
})
}).next().hide()
})
})(jQuery)
and the whole thing working on jsfiddle
http://jsfiddle.net/qpqL9/
You can easily call your function in the callback functions of the animation done on the tabs.
Slight changes in jquery.multi-accordion-1.5.3.js
$div.slideDown('fast', function(){
$div.addClass(options._classes.divActive);
//function to be called after expanding the tabs.
});
$div.slideUp('fast', function(){
$div.removeClass(options._classes.divActive);
//function to be called after collapsing the tabs
});
$.extend($.ui.multiAccordion, {
// private helper method that used to show tabs
_showTab: function($this) {
var $span = $this.children('span.ui-icon');
var $div = $this.next();
var options = this.options;
$this.removeClass('ui-state-default ui-corner-all').addClass('ui-state-active ui-corner-top');
$span.removeClass('ui-icon-triangle-1-e').addClass('ui-icon-triangle-1-s');
// MODIIFICATION
bindThis = this;
var ui = {
tab: $this,
content: $this.next('div')
}
$div.slideDown('fast', function(){
$div.addClass(options._classes.divActive);
// MODIFICATION
bindThis._trigger('tabShownComplete');
});
this._trigger('tabShown', null, ui);
},
// private helper method that used to show tabs
_hideTab: function($this) {
var $span = $this.children('span.ui-icon');
var $div = $this.next();
var options = this.options;
$this.removeClass('ui-state-active ui-corner-top').addClass('ui-state-default ui-corner-all');
$span.removeClass('ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-e');
// MODIIFICATION
bindThis = this;
var ui = {
tab: $this,
content: $this.next('div')
}
$div.slideUp('fast', function(){
$div.removeClass(options._classes.divActive);
// MODIFICATION
bindThis._trigger('tabHiddenComplete', null, ui);
});
this._trigger('tabHidden', null, ui);
}
});
https://gist.github.com/4342758
Have you try the tabHidden and tabShown methods?
// when tab is shown, ui here hold the same as in click event above
tabShown: function(event, ui) {}
// when tab is hidden, ui here hold the same as in click event above
tabHidden: function(event, ui) {}

Categories

Resources