From a0f4fec6c75cc19abadec0704913dc8e54034db9 Mon Sep 17 00:00:00 2001 From: Craig Michael Thompson Date: Thu, 22 Jul 2010 23:23:21 +0100 Subject: [PATCH] Fixed typo in previous commits in core.js and tips.js causing errors. Also optimized ipts plugin further. --- src/bgiframe.js | 2 +- src/core.js | 50 ++++++++++++++++++++----------------------------- src/tips.js | 49 ++++++++++++++++++++++++++---------------------- 3 files changed, 48 insertions(+), 53 deletions(-) diff --git a/src/bgiframe.js b/src/bgiframe.js index db548f6b..6ba1c0d6 100644 --- a/src/bgiframe.js +++ b/src/bgiframe.js @@ -3,7 +3,7 @@ function BGIFrame(qTip) { var self = this, tooltip = qTip.elements.tooltip, - ns = '.bgiframe-' + qTip.id, + namespace = '.bgiframe-' + qTip.id, events = 'tooltipmove'+namespace+' tooltipshow'+namespace; self.frame = NULL; diff --git a/src/core.js b/src/core.js index 2b621c9c..989f1a03 100644 --- a/src/core.js +++ b/src/core.js @@ -182,6 +182,17 @@ function QTip(target, options, id) tooltip.width(newWidth); } + function removeTitle() + { + var elems = self.elements; + + if(elems.title) { + elems.titlebar.remove(); + elems.titlebar = elems.title = elems.button = NULL; + elems.tooltip.removeAttr('aria-labelledby'); + } + } + function createTitle() { var elems = self.elements, @@ -191,14 +202,14 @@ function QTip(target, options, id) if(elems.titlebar) { removeTitle(); } // Create title bar and title elements - elem.titlebar = $('
', { - classes: 'ui-tooltip-wrapper' + (options.style.widget ? 'ui-widget-header' : ''), + elems.titlebar = $('
', { + 'class': 'ui-tooltip-titlebar ' + (options.style.widget ? 'ui-widget-header' : '') }) .append( elems.title = $('
', { - id: 'ui-tooltip-'+id+'-title', - classes: 'ui-tooltip-title', - html: options.content.title.text + 'id': 'ui-tooltip-'+id+'-title', + 'class': 'ui-tooltip-title', + 'html': options.content.title.text }) ) .prependTo(elems.wrapper); @@ -210,14 +221,14 @@ function QTip(target, options, id) elems.button = button; } else if('string' === typeof button) { - elems.button = $('', { html: button }); + elems.button = $('', { 'html': button }); } else { elems.button = $('', { - classes: 'ui-state-default' + 'class': 'ui-state-default' }) .append( - $('', { classes: 'ui-icon ui-icon-close' }) + $('', { 'class': 'ui-icon ui-icon-close' }) ); } @@ -228,7 +239,7 @@ function QTip(target, options, id) .addClass('ui-tooltip-' + (button === TRUE ? 'close' : 'button')) .hover(function(event){ $(this).toggleClass('ui-state-hover', event.type === 'mouseenter'); }) .click(function() { - !elems.tooltip.hasClass('ui-state-disabled') && self.hide(); + if(!elems.tooltip.hasClass('ui-state-disabled')) { self.hide(); } return FALSE; }) .bind('mousedown keydown mouseup keyup mouseout', function(event) { @@ -237,17 +248,6 @@ function QTip(target, options, id) } } - function removeTitle() - { - var elems = self.elements; - - if(elems.title) { - elems.titlebar.remove(); - elems.titlebar = elems.title = elems.button = NULL; - elems.tooltip.removeAttr('aria-labelledby'); - } - } - function updateTitle(content) { // Make sure tooltip is rendered and if not, return @@ -440,16 +440,6 @@ function QTip(target, options, id) if(options.position.adjust.screen || (IE6 && targets.tooltip.css('position') === 'fixed')) { $(document).bind('scroll'+namespace, repositionMethod); } - - // Apply automatic position: fixed override - if() { - // Set positioning to absolute - tooltip.css({ position: 'absolute' }); - - // Reposition tooltip when window is scrolled - $(window).bind('scroll'+self.ns, self.scroll); - } - // Hide tooltip on document mousedown if unfocus events are enabled if((/unfocus/i).test(options.hide.event)) { diff --git a/src/tips.js b/src/tips.js index 8aac32a4..a8ed527a 100644 --- a/src/tips.js +++ b/src/tips.js @@ -23,8 +23,11 @@ function calculateTip(corner, width, height) } function Tip(qTip, command) - +{ var self = this, + opts = qTip.options.style.tip, + tooltip = qTip.elements.tooltip, + wrapper = qTip.elements.wrapper, tip = qTip.elements.tip = $(), cache = { top: 0, @@ -32,13 +35,13 @@ function Tip(qTip, command) corner: { string: function(){} } }, size = { - width: qTip.options.style.tip.width, - height: qTip.options.style.tip.height + width: opts.width, + height: opts.height }, color = { }, - border = qTip.options.style.tip.border || 0, - adjust = qTip.options.style.tip.adjust || 0, - method = qTip.options.style.tip.method || FALSE; + border = opts.border || 0, + adjust = opts.adjust || 0, + method = opts.method || FALSE; self.corner = NULL; self.mimic = NULL; @@ -51,7 +54,7 @@ function Tip(qTip, command) }, '^style.tip.(corner|mimic|method|border)': function() { // Re-determine tip type and update - border = qTip.options.style.tip.border; + border = opts.border; self.detectCorner(); self.update(); @@ -63,8 +66,8 @@ function Tip(qTip, command) '^style.tip.(height|width)': function() { // Re-set dimensions and redraw the tip size = { - width: qTip.options.style.tip.width, - height: qTip.options.style.tip.height + width: opts.width, + height: opts.height }; self.create(); self.update(); @@ -81,7 +84,7 @@ function Tip(qTip, command) function position(corner) { // Return if tips are disabled or tip is not yet rendered - if(qTip.options.style.tip.corner === FALSE || !tip) { return FALSE; } + if(opts.corner === FALSE || !tip) { return FALSE; } // Inherit corner if not provided corner = corner || self.corner; @@ -123,8 +126,8 @@ function Tip(qTip, command) // Determine adjustments offset = size[ (corner.precedance === 'x') ? 'width' : 'height' ]; - if(qTip.options.style.tip.border) { - offset -= parseInt(qTip.elements.wrapper.css('border-' + corner[ corner.precedance ] + '-width'), 10); + if(border) { + offset -= parseInt(wrapper.css('border-' + corner[ corner.precedance ] + '-width'), 10); } // Adjust secondary corners @@ -136,7 +139,7 @@ function Tip(qTip, command) } } - function adjust(event, api, position) { + function reposition(event, api, position) { // Only continue if tip adjustments are enabled if(!self.corner.adjust) { return FALSE; @@ -146,7 +149,7 @@ function Tip(qTip, command) newType = self.mimic.adjust ? $.extend({}, self.mimic) : null, precedance = newCorner.precedance === 'y' ? ['y', 'top', 'left', 'height'] : ['x', 'left', 'top', 'width'], adjusted = position.adjusted, - offset = parseInt(qTip.elements.wrapper.css('border-' + newCorner[ precedance[0] ] + '-width'), 10), + offset = parseInt(wrapper.css('border-' + newCorner[ precedance[0] ] + '-width'), 10), walk = [newCorner, newType]; // Adjust tip corners @@ -183,8 +186,8 @@ function Tip(qTip, command) color.border = tip.get(0).style ? tip.get(0).style['border' + precedance.charAt(0) + precedance.substr(1) + 'Color'] : tip.css(borderSide) || 'transparent'; // Make sure colours are valid and reset background and border properties - if((/rgba?\(0, 0, 0(, 0)?\)|transparent/i).test(color.fill)) { color.fill = qTip.elements.wrapper.css(border ? 'background-color' : borderSide); } - if(!color.border || (/rgba?\(0, 0, 0(, 0)?\)|transparent/i).test(color.border)) { color.border = qTip.elements.wrapper.css(borderSide) || color.fill; } + if((/rgba?\(0, 0, 0(, 0)?\)|transparent/i).test(color.fill)) { color.fill = wrapper.css(border ? 'background-color' : borderSide); } + if(!color.border || (/rgba?\(0, 0, 0(, 0)?\)|transparent/i).test(color.border)) { color.border = wrapper.css(borderSide) || color.fill; } $('*', tip).add(tip).css('background-color', 'transparent').css('border', 0); } @@ -197,7 +200,7 @@ function Tip(qTip, command) if(properties === FALSE){ return FALSE; } // Bind update events - qTip.elements.tooltip.bind('tooltipmove.tip', adjust); + tooltip.bind('tooltipmove.tip', reposition); // Check if rendering method is possible and if not fall back if(method === TRUE) { @@ -222,8 +225,8 @@ function Tip(qTip, command) detectCorner: function() { - var corner = qTip.options.style.tip.corner, - mimic = qTip.options.style.tip.mimic || corner, + var corner = opts.corner, + mimic = opts.mimic || corner, at = qTip.options.position.at, my = qTip.options.position.my; if(my.string) { my = my.string(); } @@ -261,7 +264,7 @@ function Tip(qTip, command) // Create tip element and prepend to the tooltip if needed if(tip){ tip.remove(); } - tip = $('
').css(size).prependTo(qTip.elements.tooltip); + tip = $('
').css(size).prependTo(tooltip); // Create tip element switch(method) @@ -291,7 +294,9 @@ function Tip(qTip, command) update: function(corner, mimic) { - var regular = 'px solid ', + var width = size.width, + height = size.height, + regular = 'px solid ', transparent = 'px dashed transparent', // Dashed IE6 border-transparency hack. Awesome! i = border > 0 ? 0 : 1, translate = Math.ceil(border / 2 + 0.5), @@ -435,7 +440,7 @@ function Tip(qTip, command) } // Remove bound events - qTip.elements.tooltip.unbind('tooltipmove.tip'); + tooltip.unbind('tooltipmove.tip'); } }); }