no writes to $.Poshytip if it is not loaded

This commit is contained in:
vitalets
2013-03-17 20:55:23 +04:00
parent 6b557bbb9f
commit 92940bb474
2 changed files with 93 additions and 86 deletions

@ -2,6 +2,11 @@ X-editable changelog
============================= =============================
Version 1.4.4 wip
----------------------------
[bug] editable-poshytip on inline mode tries to write in $.Poshytip (vitalets)
Version 1.4.3 Mar 8, 2013 Version 1.4.3 Mar 8, 2013
---------------------------- ----------------------------
[bug #32] hotfix for jQuery UI 1.9+ (vitalets) [bug #32] hotfix for jQuery UI 1.9+ (vitalets)

@ -105,99 +105,101 @@
* see https://github.com/vadikom/poshytip/issues/7 * see https://github.com/vadikom/poshytip/issues/7
*/ */
/*jshint eqeqeq:false, curly: false*/ /*jshint eqeqeq:false, curly: false*/
var tips = [], if($.Poshytip) { //need this check, because in inline mode poshytip may not be loaded!
reBgImage = /^url\(["']?([^"'\)]*)["']?\);?$/i, var tips = [],
rePNG = /\.png$/i, reBgImage = /^url\(["']?([^"'\)]*)["']?\);?$/i,
ie6 = !!window.createPopup && document.documentElement.currentStyle.minWidth == 'undefined'; rePNG = /\.png$/i,
ie6 = !!window.createPopup && document.documentElement.currentStyle.minWidth == 'undefined';
$.Poshytip.prototype.refresh = function(async) {
if (this.disabled) $.Poshytip.prototype.refresh = function(async) {
return; if (this.disabled)
return;
var currPos;
if (async) { var currPos;
if (!this.$tip.data('active')) if (async) {
return; if (!this.$tip.data('active'))
// save current position as we will need to animate return;
currPos = {left: this.$tip.css('left'), top: this.$tip.css('top')}; // save current position as we will need to animate
} currPos = {left: this.$tip.css('left'), top: this.$tip.css('top')};
}
// reset position to avoid text wrapping, etc. // reset position to avoid text wrapping, etc.
this.$tip.css({left: 0, top: 0}).appendTo(document.body); this.$tip.css({left: 0, top: 0}).appendTo(document.body);
// save default opacity // save default opacity
if (this.opacity === undefined) if (this.opacity === undefined)
this.opacity = this.$tip.css('opacity'); this.opacity = this.$tip.css('opacity');
// check for images - this code is here (i.e. executed each time we show the tip and not on init) due to some browser inconsistencies // check for images - this code is here (i.e. executed each time we show the tip and not on init) due to some browser inconsistencies
var bgImage = this.$tip.css('background-image').match(reBgImage), var bgImage = this.$tip.css('background-image').match(reBgImage),
arrow = this.$arrow.css('background-image').match(reBgImage); arrow = this.$arrow.css('background-image').match(reBgImage);
if (bgImage) { if (bgImage) {
var bgImagePNG = rePNG.test(bgImage[1]); var bgImagePNG = rePNG.test(bgImage[1]);
// fallback to background-color/padding/border in IE6 if a PNG is used // fallback to background-color/padding/border in IE6 if a PNG is used
if (ie6 && bgImagePNG) { if (ie6 && bgImagePNG) {
this.$tip.css('background-image', 'none'); this.$tip.css('background-image', 'none');
this.$inner.css({margin: 0, border: 0, padding: 0}); this.$inner.css({margin: 0, border: 0, padding: 0});
bgImage = bgImagePNG = false; bgImage = bgImagePNG = false;
} else { } else {
this.$tip.prepend('<table class="fallback" border="0" cellpadding="0" cellspacing="0"><tr><td class="tip-top tip-bg-image" colspan="2"><span></span></td><td class="tip-right tip-bg-image" rowspan="2"><span></span></td></tr><tr><td class="tip-left tip-bg-image" rowspan="2"><span></span></td><td></td></tr><tr><td class="tip-bottom tip-bg-image" colspan="2"><span></span></td></tr></table>') this.$tip.prepend('<table class="fallback" border="0" cellpadding="0" cellspacing="0"><tr><td class="tip-top tip-bg-image" colspan="2"><span></span></td><td class="tip-right tip-bg-image" rowspan="2"><span></span></td></tr><tr><td class="tip-left tip-bg-image" rowspan="2"><span></span></td><td></td></tr><tr><td class="tip-bottom tip-bg-image" colspan="2"><span></span></td></tr></table>')
.css({border: 0, padding: 0, 'background-image': 'none', 'background-color': 'transparent'}) .css({border: 0, padding: 0, 'background-image': 'none', 'background-color': 'transparent'})
.find('.tip-bg-image').css('background-image', 'url("' + bgImage[1] +'")').end() .find('.tip-bg-image').css('background-image', 'url("' + bgImage[1] +'")').end()
.find('td').eq(3).append(this.$inner); .find('td').eq(3).append(this.$inner);
} }
// disable fade effect in IE due to Alpha filter + translucent PNG issue // disable fade effect in IE due to Alpha filter + translucent PNG issue
if (bgImagePNG && !$.support.opacity) if (bgImagePNG && !$.support.opacity)
this.opts.fade = false; this.opts.fade = false;
} }
// IE arrow fixes // IE arrow fixes
if (arrow && !$.support.opacity) { if (arrow && !$.support.opacity) {
// disable arrow in IE6 if using a PNG // disable arrow in IE6 if using a PNG
if (ie6 && rePNG.test(arrow[1])) { if (ie6 && rePNG.test(arrow[1])) {
arrow = false; arrow = false;
this.$arrow.css('background-image', 'none'); this.$arrow.css('background-image', 'none');
} }
// disable fade effect in IE due to Alpha filter + translucent PNG issue // disable fade effect in IE due to Alpha filter + translucent PNG issue
this.opts.fade = false; this.opts.fade = false;
} }
var $table = this.$tip.find('table.fallback'); var $table = this.$tip.find('table.fallback');
if (ie6) { if (ie6) {
// fix min/max-width in IE6 // fix min/max-width in IE6
this.$tip[0].style.width = ''; this.$tip[0].style.width = '';
$table.width('auto').find('td').eq(3).width('auto'); $table.width('auto').find('td').eq(3).width('auto');
var tipW = this.$tip.width(), var tipW = this.$tip.width(),
minW = parseInt(this.$tip.css('min-width'), 10), minW = parseInt(this.$tip.css('min-width'), 10),
maxW = parseInt(this.$tip.css('max-width'), 10); maxW = parseInt(this.$tip.css('max-width'), 10);
if (!isNaN(minW) && tipW < minW) if (!isNaN(minW) && tipW < minW)
tipW = minW; tipW = minW;
else if (!isNaN(maxW) && tipW > maxW) else if (!isNaN(maxW) && tipW > maxW)
tipW = maxW; tipW = maxW;
this.$tip.add($table).width(tipW).eq(0).find('td').eq(3).width('100%'); this.$tip.add($table).width(tipW).eq(0).find('td').eq(3).width('100%');
} else if ($table[0]) { } else if ($table[0]) {
// fix the table width if we are using a background image // fix the table width if we are using a background image
// IE9, FF4 use float numbers for width/height so use getComputedStyle for them to avoid text wrapping // IE9, FF4 use float numbers for width/height so use getComputedStyle for them to avoid text wrapping
// for details look at: http://vadikom.com/dailies/offsetwidth-offsetheight-useless-in-ie9-firefox4/ // for details look at: http://vadikom.com/dailies/offsetwidth-offsetheight-useless-in-ie9-firefox4/
$table.width('auto').find('td').eq(3).width('auto').end().end().width(document.defaultView && document.defaultView.getComputedStyle && parseFloat(document.defaultView.getComputedStyle(this.$tip[0], null).width) || this.$tip.width()).find('td').eq(3).width('100%'); $table.width('auto').find('td').eq(3).width('auto').end().end().width(document.defaultView && document.defaultView.getComputedStyle && parseFloat(document.defaultView.getComputedStyle(this.$tip[0], null).width) || this.$tip.width()).find('td').eq(3).width('100%');
} }
this.tipOuterW = this.$tip.outerWidth(); this.tipOuterW = this.$tip.outerWidth();
this.tipOuterH = this.$tip.outerHeight(); this.tipOuterH = this.$tip.outerHeight();
this.calcPos(); this.calcPos();
// position and show the arrow image // position and show the arrow image
if (arrow && this.pos.arrow) { if (arrow && this.pos.arrow) {
this.$arrow[0].className = 'tip-arrow tip-arrow-' + this.pos.arrow; this.$arrow[0].className = 'tip-arrow tip-arrow-' + this.pos.arrow;
this.$arrow.css('visibility', 'inherit'); this.$arrow.css('visibility', 'inherit');
} }
if (async) { if (async) {
this.asyncAnimating = true; this.asyncAnimating = true;
var self = this; var self = this;
this.$tip.css(currPos).animate({left: this.pos.l, top: this.pos.t}, 200, function() { self.asyncAnimating = false; }); this.$tip.css(currPos).animate({left: this.pos.l, top: this.pos.t}, 200, function() { self.asyncAnimating = false; });
} else { } else {
this.$tip.css({left: this.pos.l, top: this.pos.t}); this.$tip.css({left: this.pos.l, top: this.pos.t});
} }
}; };
}
/*jshinteqeqeq: true, curly: true*/ /*jshinteqeqeq: true, curly: true*/
}(window.jQuery)); }(window.jQuery));