Browse Source

Fix several issues with selector refreshing in popup

pull/1063/head
jlukic 10 years ago
parent
commit
5cd5ae3947
1 changed files with 45 additions and 44 deletions
  1. 89
      src/definitions/modules/popup.js

89
src/definitions/modules/popup.js

@ -13,17 +13,18 @@
$.fn.popup = function(parameters) { $.fn.popup = function(parameters) {
var var
$allModules = $(this),
$document = $(document),
$allModules = $(this),
$document = $(document),
moduleSelector = $allModules.selector || '',
moduleSelector = $allModules.selector || '',
time = new Date().getTime(),
performance = [],
hasTouch = ('ontouchstart' in document.documentElement),
time = new Date().getTime(),
performance = [],
query = arguments[0],
methodInvoked = (typeof query == 'string'),
queryArguments = [].slice.call(arguments, 1),
query = arguments[0],
methodInvoked = (typeof query == 'string'),
queryArguments = [].slice.call(arguments, 1),
returnedValue returnedValue
; ;
@ -51,18 +52,8 @@ $.fn.popup = function(parameters) {
$window = $(window), $window = $(window),
$body = $('body'), $body = $('body'),
$popup = (settings.popup)
? $(settings.popup)
: (settings.inline)
? $target.next(settings.selector.popup)
: $context.find(settings.selector.popup).last(),
$offsetParent = (settings.popup)
? $popup.offsetParent()
: (settings.inline)
? $target.offsetParent()
: $body,
$popup,
$offsetParent,
searchDepth = 0, searchDepth = 0,
@ -76,6 +67,7 @@ $.fn.popup = function(parameters) {
// binds events // binds events
initialize: function() { initialize: function() {
module.debug('Initializing module', $module); module.debug('Initializing module', $module);
module.refresh();
if(settings.on == 'click') { if(settings.on == 'click') {
$module $module
.on('click', module.toggle) .on('click', module.toggle)
@ -111,24 +103,27 @@ $.fn.popup = function(parameters) {
}, },
refresh: function() { refresh: function() {
if(settings.popup) {
$popup = $(settings.popup);
$offsetParent = $popup.offsetParent();
}
else if(settings.inline) {
$popup = $target.next(selector.popup);
$offsetParent = $target.offsetParent();
}
else {
$popup = $context.find(selector.popup).last();
}
$popup = (settings.popup)
? $(settings.popup)
: (settings.inline)
? $target.next(settings.selector.popup)
: false
;
$offsetParent = (settings.popup)
? $popup.offsetParent()
: (settings.inline)
? $target.offsetParent()
: $body
;
}, },
destroy: function() { destroy: function() {
module.debug('Destroying previous module'); module.debug('Destroying previous module');
$popup
.remove()
;
if($popup) {
$popup
.remove()
;
}
$module $module
.off(eventNamespace) .off(eventNamespace)
.removeData(moduleNamespace) .removeData(moduleNamespace)
@ -171,7 +166,6 @@ $.fn.popup = function(parameters) {
// generates popup html from metadata // generates popup html from metadata
create: function() { create: function() {
module.debug('Creating pop-up html');
var var
html = $module.data(metadata.html) || settings.html, html = $module.data(metadata.html) || settings.html,
variation = $module.data(metadata.variation) || settings.variation, variation = $module.data(metadata.variation) || settings.variation,
@ -179,8 +173,9 @@ $.fn.popup = function(parameters) {
content = $module.data(metadata.content) || $module.attr('title') || settings.content content = $module.data(metadata.content) || $module.attr('title') || settings.content
; ;
if(html || content || title) { if(html || content || title) {
module.debug('Creating pop-up html');
if(!html) { if(!html) {
html = settings.template({
html = settings.templates.popup({
title : title, title : title,
content : content content : content
}); });
@ -241,7 +236,7 @@ $.fn.popup = function(parameters) {
if( !module.exists() ) { if( !module.exists() ) {
module.create(); module.create();
} }
if( module.set.position() ) {
if( $popup && module.set.position() ) {
module.save.conditions(); module.save.conditions();
module.animate.show(callback); module.animate.show(callback);
} }
@ -279,6 +274,9 @@ $.fn.popup = function(parameters) {
}, },
exists: function() { exists: function() {
if(!$popup) {
return false;
}
if(settings.inline) { if(settings.inline) {
return ( $popup.size() !== 0 ); return ( $popup.size() !== 0 );
} }
@ -573,7 +571,10 @@ $.fn.popup = function(parameters) {
position = module.get.nextPosition(position); position = module.get.nextPosition(position);
searchDepth++; searchDepth++;
module.debug('Trying new position', position); module.debug('Trying new position', position);
return module.set.position(position);
return ($popup)
? module.set.position(position)
: false
;
} }
else { else {
module.error(error.recursion); module.error(error.recursion);
@ -609,7 +610,7 @@ $.fn.popup = function(parameters) {
$document $document
.on('click' + eventNamespace, function(event) { .on('click' + eventNamespace, function(event) {
module.verbose('Pop-up clickaway intent detected'); module.verbose('Pop-up clickaway intent detected');
$.proxy(module.hideGracefully, this)(event);
$.proxy(module.hideGracefully, element)(event);
}) })
; ;
} }
@ -629,10 +630,10 @@ $.fn.popup = function(parameters) {
is: { is: {
animating: function() { animating: function() {
return ( $popup.is(':animated') || $popup.hasClass(className.animating) );
return ( $popup && $popup.is(':animated') || $popup.hasClass(className.animating) );
}, },
visible: function() { visible: function() {
return $popup.is(':visible');
return $popup && $popup.is(':visible');
}, },
hidden: function() { hidden: function() {
return !module.is.visible(); return !module.is.visible();
@ -844,7 +845,7 @@ $.fn.popup.settings = {
onShow : function(){}, onShow : function(){},
onHide : function(){}, onHide : function(){},
variation : 'inverted',
variation : '',
content : false, content : false,
html : false, html : false,
title : false, title : false,
@ -853,7 +854,7 @@ $.fn.popup.settings = {
closable : true, closable : true,
context : 'body', context : 'body',
position : 'top center',
position : 'top left',
delay : { delay : {
show : 50, show : 50,
hide : 0 hide : 0
@ -862,7 +863,7 @@ $.fn.popup.settings = {
target : false, target : false,
popup : false, popup : false,
inline : false, inline : false,
preserve : false,
preserve : true,
hoverable : false, hoverable : false,
duration : 200, duration : 200,

Loading…
Cancel
Save