(function( window, document, undefined ) {// Uses AMD or browser globals to create a jQuery plugin. (function( factory ) { "use strict"; if(typeof define === 'function' && define.amd) { define(['jquery'], factory); } else if(jQuery && !jQuery.fn.qtip) { factory(jQuery); } } (function($) { "use strict"; // Enable ECMAScript "strict" operation for this function. See more: http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/;// Munge the primitives - Paul Irish tip var TRUE = true, FALSE = false, NULL = null,// Common variables X = 'x', Y = 'y', WIDTH = 'width', HEIGHT = 'height',// Positioning sides TOP = 'top', LEFT = 'left', BOTTOM = 'bottom', RIGHT = 'right', CENTER = 'center',// Position adjustment types FLIP = 'flip', FLIPINVERT = 'flipinvert', SHIFT = 'shift',// Shortcut vars QTIP, PROTOTYPE, CORNER, CHECKS, PLUGINS = {}, NAMESPACE = 'qtip', ATTR_HAS = 'data-hasqtip', ATTR_ID = 'data-qtip-id', WIDGET = ['ui-widget', 'ui-tooltip'], SELECTOR = '.'+NAMESPACE, INACTIVE_EVENTS = 'click dblclick mousedown mouseup mousemove mouseleave mouseenter'.split(' '),CLASS_FIXED = NAMESPACE+'-fixed', CLASS_DEFAULT = NAMESPACE + '-default', CLASS_FOCUS = NAMESPACE + '-focus', CLASS_HOVER = NAMESPACE + '-hover', CLASS_DISABLED = NAMESPACE+'-disabled',replaceSuffix = '_replacedByqTip', oldtitle = 'oldtitle', trackingBound,// Browser detection BROWSER = { ie: (function(){ var v = 3, div = document.createElement('div'); while ((div.innerHTML = '')) { if(!div.getElementsByTagName('i')[0]) { break; } } return v > 4 ? v : NaN; }()), ioses: parseFloat( ('' + (/CPU.*OS ([0-9_]{1,5})|(CPU like).*AppleWebKit.*mobiles/i.exec(navigator.userAgent) || [0,''])[1]) .replace('undefined', '3_2').replace('_', '.').replace('_', '') ) || FALSE };;function QTip(target, options, id, attr) { // Elements and ID this.id = id; this.target = target; this.tooltip = NULL; this.elements = { target: target }; // Internal constructs this._id = NAMESPACE + '-' + id; this.timers = { img: {} }; this.options = options; this.plugins = {}; // Cache object this.cache = { event: {}, target: $(), disabled: FALSE, attr: attr, onTooltip: FALSE, lastClass: '' }; // Set the initial flags this.rendered = this.destroyed = this.disabled = this.waiting = this.hiddenDuringWait = this.positioning = this.triggering = FALSE; } PROTOTYPE = QTip.prototype;PROTOTYPE._when = function(deferreds) { return $.when.apply($, deferreds); };PROTOTYPE.render = function(show) { if(this.rendered || this.destroyed) { return this; } // If tooltip has already been rendered, exit var self = this, options = this.options, cache = this.cache, elements = this.elements, text = options.content.text, title = options.content.title, button = options.content.button, posOptions = options.position, namespace = '.'+this._id+' ', deferreds = [], tooltip; // Add ARIA attributes to target $.attr(this.target[0], 'aria-describedby', this._id); // Create tooltip element this.tooltip = elements.tooltip = tooltip = $('
', { 'id': this._id, 'class': [ NAMESPACE, CLASS_DEFAULT, options.style.classes, NAMESPACE + '-pos-' + options.position.my.abbrev() ].join(' '), 'width': options.style.width || '', 'height': options.style.height || '', 'tracking': posOptions.target === 'mouse' && posOptions.adjust.mouse, 'role': 'alert', 'aria-live': 'polite', 'aria-atomic': FALSE, 'aria-describedby': this._id + '-content', 'aria-hidden': TRUE }) .toggleClass(CLASS_DISABLED, this.disabled) .attr(ATTR_ID, this.id) .data(NAMESPACE, this) .appendTo(posOptions.container) .append( // Create content element elements.content = $('
', { 'class': NAMESPACE + '-content', 'id': this._id + '-content', 'aria-atomic': TRUE }) ); // Set rendered flag and prevent redundant reposition calls for now this.rendered = -1; this.positioning = TRUE; // Create title... if(title) { this._createTitle(); // Update title only if its not a callback (called in toggle if so) if(!$.isFunction(title)) { deferreds.push( this._updateTitle(title, FALSE) ); } } // Create button if(button) { this._createButton(); } // Set proper rendered flag and update content if not a callback function (called in toggle) if(!$.isFunction(text)) { deferreds.push( this._updateContent(text, FALSE) ); } this.rendered = TRUE; // Setup widget classes this._setWidget(); // Initialize 'render' plugins $.each(PLUGINS, function(name) { var instance; if(this.initialize === 'render' && (instance = this(self))) { self.plugins[name] = instance; } }); // Unassign initial events and assign proper events this._unassignEvents(); this._assignEvents(); // When deferreds have completed this._when(deferreds).then(function() { // tooltiprender event self._trigger('render'); // Reset flags self.positioning = FALSE; // Show tooltip if not hidden during wait period if(!self.hiddenDuringWait && (options.show.ready || show)) { self.toggle(TRUE, cache.event, FALSE); } self.hiddenDuringWait = FALSE; }); // Expose API QTIP.api[this.id] = this; return this; };PROTOTYPE.destroy = function(immediate) { // Set flag the signify destroy is taking place to plugins // and ensure it only gets destroyed once! if(this.destroyed) { return this.target; } function process() { if(this.destroyed) { return; } this.destroyed = TRUE; var target = this.target, title = target.attr(oldtitle); // Destroy tooltip if rendered if(this.rendered) { this.tooltip.stop(1,0).find('*').remove().end().remove(); } // Destroy all plugins $.each(this.plugins, function(name) { this.destroy && this.destroy(); }); // Clear timers and remove bound events clearTimeout(this.timers.show); clearTimeout(this.timers.hide); this._unassignEvents(); // Remove api object and ARIA attributes target.removeData(NAMESPACE) .removeAttr(ATTR_ID) .removeAttr(ATTR_HAS) .removeAttr('aria-describedby'); // Reset old title attribute if removed if(this.options.suppress && title) { target.attr('title', title).removeAttr(oldtitle); } // Remove qTip events associated with this API this._unbind(target); // Remove ID from used id objects, and delete object references // for better garbage collection and leak protection this.options = this.elements = this.cache = this.timers = this.plugins = this.mouse = NULL; // Delete epoxsed API object delete QTIP.api[this.id]; } // If an immediate destory is needed if((immediate !== TRUE || this.triggering === 'hide') && this.rendered) { this.tooltip.one('tooltiphidden', $.proxy(process, this)); !this.triggering && this.hide(); } // If we're not in the process of hiding... process else { process.call(this); } return this.target; };;function invalidOpt(a) { return a === NULL || $.type(a) !== 'object'; }function invalidContent(c) { return !( $.isFunction(c) || (c && c.attr) || c.length || ($.type(c) === 'object' && (c.jquery || c.then) )); }// Option object sanitizer function sanitizeOptions(opts) { var content, text, ajax, once; if(invalidOpt(opts)) { return FALSE; } if(invalidOpt(opts.metadata)) { opts.metadata = { type: opts.metadata }; } if('content' in opts) { content = opts.content; if(invalidOpt(content) || content.jquery || content.done) { content = opts.content = { text: (text = invalidContent(content) ? FALSE : content) }; } else { text = content.text; } // DEPRECATED - Old content.ajax plugin functionality // Converts it into the proper Deferred syntax if('ajax' in content) { ajax = content.ajax; once = ajax && ajax.once !== FALSE; delete content.ajax; content.text = function(event, api) { var loading = text || $(this).attr(api.options.content.attr) || 'Loading...', deferred = $.ajax( $.extend({}, ajax, { context: api }) ) .then(ajax.success, NULL, ajax.error) .then(function(content) { if(content && once) { api.set('content.text', content); } return content; }, function(xhr, status, error) { if(api.destroyed || xhr.status === 0) { return; } api.set('content.text', status + ': ' + error); }); return !once ? (api.set('content.text', loading), deferred) : loading; }; } if('title' in content) { if(!invalidOpt(content.title)) { content.button = content.title.button; content.title = content.title.text; } if(invalidContent(content.title || FALSE)) { content.title = FALSE; } } } if('position' in opts && invalidOpt(opts.position)) { opts.position = { my: opts.position, at: opts.position }; } if('show' in opts && invalidOpt(opts.show)) { opts.show = opts.show.jquery ? { target: opts.show } : opts.show === TRUE ? { ready: TRUE } : { event: opts.show }; } if('hide' in opts && invalidOpt(opts.hide)) { opts.hide = opts.hide.jquery ? { target: opts.hide } : { event: opts.hide }; } if('style' in opts && invalidOpt(opts.style)) { opts.style = { classes: opts.style }; } // Sanitize plugin options $.each(PLUGINS, function() { this.sanitize && this.sanitize(opts); }); return opts; }// Setup builtin .set() option checks CHECKS = PROTOTYPE.checks = { builtin: { // Core checks '^id$': function(obj, o, v, prev) { var id = v === TRUE ? QTIP.nextid : v, new_id = NAMESPACE + '-' + id; if(id !== FALSE && id.length > 0 && !$('#'+new_id).length) { this._id = new_id; if(this.rendered) { this.tooltip[0].id = this._id; this.elements.content[0].id = this._id + '-content'; this.elements.title[0].id = this._id + '-title'; } } else { obj[o] = prev; } }, '^prerender': function(obj, o, v) { v && !this.rendered && this.render(this.options.show.ready); }, // Content checks '^content.text$': function(obj, o, v) { this._updateContent(v); }, '^content.attr$': function(obj, o, v, prev) { if(this.options.content.text === this.target.attr(prev)) { this._updateContent( this.target.attr(v) ); } }, '^content.title$': function(obj, o, v) { // Remove title if content is null if(!v) { return this._removeTitle(); } // If title isn't already created, create it now and update v && !this.elements.title && this._createTitle(); this._updateTitle(v); }, '^content.button$': function(obj, o, v) { this._updateButton(v); }, '^content.title.(text|button)$': function(obj, o, v) { this.set('content.'+o, v); // Backwards title.text/button compat }, // Position checks '^position.(my|at)$': function(obj, o, v){ 'string' === typeof v && (obj[o] = new CORNER(v, o === 'at')); }, '^position.container$': function(obj, o, v){ this.rendered && this.tooltip.appendTo(v); }, // Show checks '^show.ready$': function(obj, o, v) { v && (!this.rendered && this.render(TRUE) || this.toggle(TRUE)); }, // Style checks '^style.classes$': function(obj, o, v, p) { this.rendered && this.tooltip.removeClass(p).addClass(v); }, '^style.(width|height)': function(obj, o, v) { this.rendered && this.tooltip.css(o, v); }, '^style.widget|content.title': function() { this.rendered && this._setWidget(); }, '^style.def': function(obj, o, v) { this.rendered && this.tooltip.toggleClass(CLASS_DEFAULT, !!v); }, // Events check '^events.(render|show|move|hide|focus|blur)$': function(obj, o, v) { this.rendered && this.tooltip[($.isFunction(v) ? '' : 'un') + 'bind']('tooltip'+o, v); }, // Properties which require event reassignment '^(show|hide|position).(event|target|fixed|inactive|leave|distance|viewport|adjust)': function() { if(!this.rendered) { return; } // Set tracking flag var posOptions = this.options.position; this.tooltip.attr('tracking', posOptions.target === 'mouse' && posOptions.adjust.mouse); // Reassign events this._unassignEvents(); this._assignEvents(); } } };// Dot notation converter function convertNotation(options, notation) { var i = 0, obj, option = options, // Split notation into array levels = notation.split('.'); // Loop through while( option = option[ levels[i++] ] ) { if(i < levels.length) { obj = option; } } return [obj || options, levels.pop()]; }PROTOTYPE.get = function(notation) { if(this.destroyed) { return this; } var o = convertNotation(this.options, notation.toLowerCase()), result = o[0][ o[1] ]; return result.precedance ? result.string() : result; };function setCallback(notation, args) { var category, rule, match; for(category in this.checks) { for(rule in this.checks[category]) { if(match = (new RegExp(rule, 'i')).exec(notation)) { args.push(match); if(category === 'builtin' || this.plugins[category]) { this.checks[category][rule].apply( this.plugins[category] || this, args ); } } } } }var rmove = /^position\.(my|at|adjust|target|container|viewport)|style|content|show\.ready/i, rrender = /^prerender|show\.ready/i;PROTOTYPE.set = function(option, value) { if(this.destroyed) { return this; } var rendered = this.rendered, reposition = FALSE, options = this.options, checks = this.checks, name; // Convert singular option/value pair into object form if('string' === typeof option) { name = option; option = {}; option[name] = value; } else { option = $.extend({}, option); } // Set all of the defined options to their new values $.each(option, function(notation, value) { if(rendered && rrender.test(notation)) { delete option[notation]; return; } // Set new obj value var obj = convertNotation(options, notation.toLowerCase()), previous; previous = obj[0][ obj[1] ]; obj[0][ obj[1] ] = value && value.nodeType ? $(value) : value; // Also check if we need to reposition reposition = rmove.test(notation) || reposition; // Set the new params for the callback option[notation] = [obj[0], obj[1], value, previous]; }); // Re-sanitize options sanitizeOptions(options); this.positioning = TRUE; $.each(option, $.proxy(setCallback, this)); this.positioning = FALSE; // Update position if needed if(this.rendered && this.tooltip[0].offsetWidth > 0 && reposition) { this.reposition( options.position.target === 'mouse' ? NULL : this.cache.event ); } return this; };;PROTOTYPE._update = function(content, element, reposition) { var self = this, cache = this.cache; // Make sure tooltip is rendered and content is defined. If not return if(!this.rendered || !content) { return FALSE; } // Use function to parse content if($.isFunction(content)) { content = content.call(this.elements.target, cache.event, this) || ''; } // Handle deferred content if($.isFunction(content.then)) { cache.waiting = TRUE; return content.then(function(c) { cache.waiting = FALSE; return self._update(c, element); }, NULL, function(e) { return self._update(e, element); }); } // If content is null... return false if(content === FALSE || (!content && content !== '')) { return FALSE; } // Append new content if its a DOM array and show it if hidden if(content.jquery && content.length > 0) { element.empty().append( content.css({ display: 'block', visibility: 'visible' }) ); } // Content is a regular string, insert the new content else { element.html(content); } // Wait for content to be loaded, and reposition return this._waitForContent(element).then(function(images) { if(images.images && images.images.length && self.rendered && self.tooltip[0].offsetWidth > 0) { self.reposition(cache.event, !images.length); } }); };PROTOTYPE._waitForContent = function(element) { var cache = this.cache; // Set flag cache.waiting = TRUE; // If imagesLoaded is included, ensure images have loaded and return promise return ( $.fn.imagesLoaded ? element.imagesLoaded() : $.Deferred().resolve([]) ) .done(function() { cache.waiting = FALSE; }) .promise(); };PROTOTYPE._updateContent = function(content, reposition) { this._update(content, this.elements.content, reposition); };PROTOTYPE._updateTitle = function(content, reposition) { if(this._update(content, this.elements.title, reposition) === FALSE) { this._removeTitle(FALSE); } };PROTOTYPE._createTitle = function() { var elements = this.elements, id = this._id+'-title'; // Destroy previous title element, if present if(elements.titlebar) { this._removeTitle(); } // Create title bar and title elements elements.titlebar = $('
', { 'class': NAMESPACE + '-titlebar ' + (this.options.style.widget ? createWidgetClass('header') : '') }) .append( elements.title = $('
', { 'id': id, 'class': NAMESPACE + '-title', 'aria-atomic': TRUE }) ) .insertBefore(elements.content) // Button-specific events .delegate('.qtip-close', 'mousedown keydown mouseup keyup mouseout', function(event) { $(this).toggleClass('ui-state-active ui-state-focus', event.type.substr(-4) === 'down'); }) .delegate('.qtip-close', 'mouseover mouseout', function(event){ $(this).toggleClass('ui-state-hover', event.type === 'mouseover'); }); // Create button if enabled if(this.options.content.button) { this._createButton(); } };PROTOTYPE._removeTitle = function(reposition) { var elements = this.elements; if(elements.title) { elements.titlebar.remove(); elements.titlebar = elements.title = elements.button = NULL; // Reposition if enabled if(reposition !== FALSE) { this.reposition(); } } };;PROTOTYPE.reposition = function(event, effect) { if(!this.rendered || this.positioning || this.destroyed) { return this; } // Set positioning flag this.positioning = TRUE; var cache = this.cache, tooltip = this.tooltip, posOptions = this.options.position, target = posOptions.target, my = posOptions.my, at = posOptions.at, viewport = posOptions.viewport, container = posOptions.container, adjust = posOptions.adjust, method = adjust.method.split(' '), tooltipWidth = tooltip.outerWidth(FALSE), tooltipHeight = tooltip.outerHeight(FALSE), targetWidth = 0, targetHeight = 0, type = tooltip.css('position'), position = { left: 0, top: 0 }, visible = tooltip[0].offsetWidth > 0, isScroll = event && event.type === 'scroll', win = $(window), doc = container[0].ownerDocument, mouse = this.mouse, pluginCalculations, offset; // Check if absolute position was passed if($.isArray(target) && target.length === 2) { // Force left top and set position at = { x: LEFT, y: TOP }; position = { left: target[0], top: target[1] }; } // Check if mouse was the target else if(target === 'mouse') { // Force left top to allow flipping at = { x: LEFT, y: TOP }; // Use the cached mouse coordinates if available, or passed event has no coordinates if(mouse && mouse.pageX && (adjust.mouse || !event || !event.pageX) ) { event = mouse; } // If the passed event has no coordinates (such as a scroll event) else if(!event || !event.pageX) { // Use the mouse origin that caused the show event, if distance hiding is enabled if((!adjust.mouse || this.options.show.distance) && cache.origin && cache.origin.pageX) { event = cache.origin; } // Use cached event for resize/scroll events else if(!event || (event && (event.type === 'resize' || event.type === 'scroll'))) { event = cache.event; } } // Calculate body and container offset and take them into account below if(type !== 'static') { position = container.offset(); } if(doc.body.offsetWidth !== (window.innerWidth || doc.documentElement.clientWidth)) { offset = $(document.body).offset(); } // Use event coordinates for position position = { left: event.pageX - position.left + (offset && offset.left || 0), top: event.pageY - position.top + (offset && offset.top || 0) }; // Scroll events are a pain, some browsers if(adjust.mouse && isScroll && mouse) { position.left -= (mouse.scrollX || 0) - win.scrollLeft(); position.top -= (mouse.scrollY || 0) - win.scrollTop(); } } // Target wasn't mouse or absolute... else { // Check if event targetting is being used if(target === 'event') { if(event && event.target && event.type !== 'scroll' && event.type !== 'resize') { cache.target = $(event.target); } else if(!event.target) { cache.target = this.elements.target; } } else if(target !== 'event'){ cache.target = $(target.jquery ? target : this.elements.target); } target = cache.target; // Parse the target into a jQuery object and make sure there's an element present target = $(target).eq(0); if(target.length === 0) { return this; } // Check if window or document is the target else if(target[0] === document || target[0] === window) { targetWidth = BROWSER.ioses ? window.innerWidth : target.width(); targetHeight = BROWSER.ioses ? window.innerHeight : target.height(); if(target[0] === window) { position = { top: (viewport || target).scrollTop(), left: (viewport || target).scrollLeft() }; } } // Check if the target is an element else if(PLUGINS.imagemap && target.is('area')) { pluginCalculations = PLUGINS.imagemap(this, target, at, PLUGINS.viewport ? method : FALSE); } // Check if the target is an SVG element else if(PLUGINS.svg && target && target[0].ownerSVGElement) { pluginCalculations = PLUGINS.svg(this, target, at, PLUGINS.viewport ? method : FALSE); } // Otherwise use regular jQuery methods else { targetWidth = target.outerWidth(FALSE); targetHeight = target.outerHeight(FALSE); position = target.offset(); } // Parse returned plugin values into proper variables if(pluginCalculations) { targetWidth = pluginCalculations.width; targetHeight = pluginCalculations.height; offset = pluginCalculations.offset; position = pluginCalculations.position; } // Adjust position to take into account offset parents position = this.reposition.offset(target, position, container); // Adjust for position.fixed tooltips (and also ioses scroll bug in v3.2-4.0 & v4.3-4.3.2) if((BROWSER.ioses > 3.1 && BROWSER.ioses < 4.1) || (BROWSER.ioses >= 4.3 && BROWSER.ioses < 4.33) || (!BROWSER.ioses && type === 'fixed') ){ position.left -= win.scrollLeft(); position.top -= win.scrollTop(); } // Adjust position relative to target if(!pluginCalculations || (pluginCalculations && pluginCalculations.adjustable !== FALSE)) { position.left += at.x === RIGHT ? targetWidth : at.x === CENTER ? targetWidth / 2 : 0; position.top += at.y === BOTTOM ? targetHeight : at.y === CENTER ? targetHeight / 2 : 0; } } // Adjust position relative to tooltip position.left += adjust.x + (my.x === RIGHT ? -tooltipWidth : my.x === CENTER ? -tooltipWidth / 2 : 0); position.top += adjust.y + (my.y === BOTTOM ? -tooltipHeight : my.y === CENTER ? -tooltipHeight / 2 : 0); // Use viewport adjustment plugin if enabled if(PLUGINS.viewport) { position.adjusted = PLUGINS.viewport( this, position, posOptions, targetWidth, targetHeight, tooltipWidth, tooltipHeight ); // Apply offsets supplied by positioning plugin (if used) if(offset && position.adjusted.left) { position.left += offset.left; } if(offset && position.adjusted.top) { position.top += offset.top; } } // Viewport adjustment is disabled, set values to zero else { position.adjusted = { left: 0, top: 0 }; } // tooltipmove event if(!this._trigger('move', [position, viewport.elem || viewport], event)) { return this; } delete position.adjusted; // If effect is disabled, target it mouse, no animation is defined or positioning gives NaN out, set CSS directly if(effect === FALSE || !visible || isNaN(position.left) || isNaN(position.top) || target === 'mouse' || !$.isFunction(posOptions.effect)) { tooltip.css(position); } // Use custom function if provided else if($.isFunction(posOptions.effect)) { posOptions.effect.call(tooltip, this, $.extend({}, position)); tooltip.queue(function(next) { // Reset attributes to avoid cross-browser rendering bugs $(this).css({ opacity: '', height: '' }); if(BROWSER.ie) { this.style.removeAttribute('filter'); } next(); }); } // Set positioning flag this.positioning = FALSE; return this; };// Custom (more correct for qTip!) offset calculator PROTOTYPE.reposition.offset = function(elem, pos, container) { if(!container[0]) { return pos; } var ownerDocument = $(elem[0].ownerDocument), quirks = !!BROWSER.ie && document.compatMode !== 'CSS1Compat', parent = container[0], scrolled, position, parentOffset, overflow; function scroll(e, i) { pos.left += i * e.scrollLeft(); pos.top += i * e.scrollTop(); } // Compensate for non-static containers offset do { if((position = $.css(parent, 'position')) !== 'static') { if(position === 'fixed') { parentOffset = parent.getBoundingClientRect(); scroll(ownerDocument, -1); } else { parentOffset = $(parent).position(); parentOffset.left += (parseFloat($.css(parent, 'borderLeftWidth')) || 0); parentOffset.top += (parseFloat($.css(parent, 'borderTopWidth')) || 0); } pos.left -= parentOffset.left + (parseFloat($.css(parent, 'marginLeft')) || 0); pos.top -= parentOffset.top + (parseFloat($.css(parent, 'marginTop')) || 0); // If this is the first parent element with an overflow of "scroll" or "auto", store it if(!scrolled && (overflow = $.css(parent, 'overflow')) !== 'hidden' && overflow !== 'visible') { scrolled = $(parent); } } } while((parent = parent.offsetParent)); // Compensate for containers scroll if it also has an offsetParent (or in IE quirks mode) if(scrolled && (scrolled[0] !== ownerDocument[0] || quirks)) { scroll(scrolled, 1); } return pos; };// Corner class var C = (CORNER = PROTOTYPE.reposition.Corner = function(corner, forceY) { corner = ('' + corner).replace(/([A-Z])/, ' $1').replace(/middle/gi, CENTER).toLowerCase(); this.x = (corner.match(/left|right/i) || corner.match(/center/) || ['inherit'])[0].toLowerCase(); this.y = (corner.match(/top|bottom|center/i) || ['inherit'])[0].toLowerCase(); this.forceY = !!forceY; var f = corner.charAt(0); this.precedance = (f === 't' || f === 'b' ? Y : X); }).prototype;C.invert = function(z, center) { this[z] = this[z] === LEFT ? RIGHT : this[z] === RIGHT ? LEFT : center || this[z]; };C.string = function() { var x = this.x, y = this.y; return x === y ? x : this.precedance === Y || (this.forceY && y !== 'center') ? y+' '+x : x+' '+y; };C.abbrev = function() { var result = this.string().split(' '); return result[0].charAt(0) + (result[1] && result[1].charAt(0) || ''); };C.clone = function() { return new CORNER( this.string(), this.forceY ); };; PROTOTYPE.toggle = function(state, event) { var cache = this.cache, options = this.options, tooltip = this.tooltip; // Try to prevent flickering when tooltip overlaps show element if(event) { if((/over|enter/).test(event.type) && (/out|leave/).test(cache.event.type) && options.show.target.add(event.target).length === options.show.target.length && tooltip.has(event.relatedTarget).length) { return this; } // Cache event cache.event = cloneEvent(event); } // If we're currently waiting and we've just hidden... stop it this.waiting && !state && (this.hiddenDuringWait = TRUE); // Render the tooltip if showing and it isn't already if(!this.rendered) { return state ? this.render(1) : this; } else if(this.destroyed || this.disabled) { return this; } var type = state ? 'show' : 'hide', opts = this.options[type], otherOpts = this.options[ !state ? 'show' : 'hide' ], posOptions = this.options.position, contentOptions = this.options.content, width = this.tooltip.css('width'), visible = this.tooltip.is(':visible'), animate = state || opts.target.length === 1, sameTarget = !event || opts.target.length < 2 || cache.target[0] === event.target, identicalState, allow, showEvent, delay, after; // Detect state if valid one isn't provided if((typeof state).search('boolean|number')) { state = !visible; } // Check if the tooltip is in an identical state to the new would-be state identicalState = !tooltip.is(':animated') && visible === state && sameTarget; // Fire tooltip(show/hide) event and check if destroyed allow = !identicalState ? !!this._trigger(type, [90]) : NULL; // Check to make sure the tooltip wasn't destroyed in the callback if(this.destroyed) { return this; } // If the user didn't stop the method prematurely and we're showing the tooltip, focus it if(allow !== FALSE && state) { this.focus(event); } // If the state hasn't changed or the user stopped it, return early if(!allow || identicalState) { return this; } // Set ARIA hidden attribute $.attr(tooltip[0], 'aria-hidden', !!!state); // Execute state specific properties if(state) { // Store show origin coordinates cache.origin = cloneEvent(this.mouse); // Update tooltip content & title if it's a dynamic function if($.isFunction(contentOptions.text)) { this._updateContent(contentOptions.text, FALSE); } if($.isFunction(contentOptions.title)) { this._updateTitle(contentOptions.title, FALSE); } // Cache mousemove events for positioning purposes (if not already tracking) if(!trackingBound && posOptions.target === 'mouse' && posOptions.adjust.mouse) { $(document).bind('mousemove.'+NAMESPACE, this._storeMouse); trackingBound = TRUE; } // Update the tooltip position (set width first to prevent viewport/max-width issues) if(!width) { tooltip.css('width', tooltip.outerWidth(FALSE)); } this.reposition(event, arguments[2]); if(!width) { tooltip.css('width', ''); } // Hide other tooltips if tooltip is solo if(!!opts.solo) { (typeof opts.solo === 'string' ? $(opts.solo) : $(SELECTOR, opts.solo)) .not(tooltip).not(opts.target).qtip('hide', $.Event('tooltipsolo')); } } else { // Clear show timer if we're hiding clearTimeout(this.timers.show); // Remove cached origin on hide delete cache.origin; // Remove mouse tracking event if not needed (all tracking qTips are hidden) if(trackingBound && !$(SELECTOR+'[tracking="true"]:visible', opts.solo).not(tooltip).length) { $(document).unbind('mousemove.'+NAMESPACE); trackingBound = FALSE; } // Blur the tooltip this.blur(event); } // Define post-animation, state specific properties after = $.proxy(function() { if(state) { // Prevent antialias from disappearing in IE by removing filter if(BROWSER.ie) { tooltip[0].style.removeAttribute('filter'); } // Remove overflow setting to prevent tip bugs tooltip.css('overflow', ''); // Autofocus elements if enabled if('string' === typeof opts.autofocus) { $(this.options.show.autofocus, tooltip).focus(); } // If set, hide tooltip when inactive for delay period this.options.show.target.trigger('qtip-'+this.id+'-inactive'); } else { // Reset CSS states tooltip.css({ display: '', visibility: '', opacity: '', left: '', top: '' }); } // tooltipvisible/tooltiphidden events this._trigger(state ? 'visible' : 'hidden'); }, this); // If no effect type is supplied, use a simple toggle if(opts.effect === FALSE || animate === FALSE) { tooltip[ type ](); after(); } // Use custom function if provided else if($.isFunction(opts.effect)) { tooltip.stop(1, 1); opts.effect.call(tooltip, this); tooltip.queue('fx', function(n) { after(); n(); }); } // Use basic fade function by default else { tooltip.fadeTo(90, state ? 1 : 0, after); } // If inactive hide method is set, active it if(state) { opts.target.trigger('qtip-'+this.id+'-inactive'); } return this; };PROTOTYPE.show = function(event) { return this.toggle(TRUE, event); };PROTOTYPE.hide = function(event) { return this.toggle(FALSE, event); };;PROTOTYPE.focus = function(event) { if(!this.rendered || this.destroyed) { return this; } var qtips = $(SELECTOR), tooltip = this.tooltip, curIndex = parseInt(tooltip[0].style.zIndex, 10), newIndex = QTIP.zindex + qtips.length, focusedElem; // Only update the z-index if it has changed and tooltip is not already focused if(!tooltip.hasClass(CLASS_FOCUS)) { // tooltipfocus event if(this._trigger('focus', [newIndex], event)) { // Only update z-index's if they've changed if(curIndex !== newIndex) { // Reduce our z-index's and keep them properly ordered qtips.each(function() { if(this.style.zIndex > curIndex) { this.style.zIndex = this.style.zIndex - 1; } }); // Fire blur event for focused tooltip qtips.filter('.' + CLASS_FOCUS).qtip('blur', event); } // Set the new z-index tooltip.addClass(CLASS_FOCUS)[0].style.zIndex = newIndex; } } return this; };PROTOTYPE.blur = function(event) { if(!this.rendered || this.destroyed) { return this; } // Set focused status to FALSE this.tooltip.removeClass(CLASS_FOCUS); // tooltipblur event this._trigger('blur', [ this.tooltip.css('zIndex') ], event); return this; };;PROTOTYPE.disable = function(state) { if(this.destroyed) { return this; } // If 'toggle' is passed, toggle the current state if(state === 'toggle') { state = !(this.rendered ? this.tooltip.hasClass(CLASS_DISABLED) : this.disabled); } // Disable if no state passed else if('boolean' !== typeof state) { state = TRUE; } if(this.rendered) { this.tooltip.toggleClass(CLASS_DISABLED, state) .attr('aria-disabled', state); } this.disabled = !!state; return this; };PROTOTYPE.enable = function() { return this.disable(FALSE); };;PROTOTYPE._createButton = function() { var self = this, elements = this.elements, tooltip = elements.tooltip, button = this.options.content.button, isString = typeof button === 'string', close = isString ? button : 'Close tooltip'; if(elements.button) { elements.button.remove(); } // Use custom button if one was supplied by user, else use default if(button.jquery) { elements.button = button; } else { elements.button = $('', { 'class': 'qtip-close ' + (this.options.style.widget ? '' : NAMESPACE+'-icon'), 'title': close, 'aria-label': close }) .prepend( $('', { 'class': 'ui-icon ui-icon-close', 'html': '×' }) ); } // Create button and setup attributes elements.button.appendTo(elements.titlebar || tooltip) .attr('role', 'button') .click(function(event) { if(!tooltip.hasClass(CLASS_DISABLED)) { self.hide(event); } return FALSE; }); };PROTOTYPE._updateButton = function(button) { // Make sure tooltip is rendered and if not, return if(!this.rendered) { return FALSE; } var elem = this.elements.button; if(button) { this._createButton(); } else { elem.remove(); } };;// Widget class creator function createWidgetClass(cls) { return WIDGET.concat('').join(cls ? '-'+cls+' ' : ' '); }// Widget class setter method PROTOTYPE._setWidget = function() { var on = this.options.style.widget, elements = this.elements, tooltip = elements.tooltip, disabled = tooltip.hasClass(CLASS_DISABLED); tooltip.removeClass(CLASS_DISABLED); CLASS_DISABLED = on ? 'ui-state-disabled' : 'qtip-disabled'; tooltip.toggleClass(CLASS_DISABLED, disabled); tooltip.toggleClass('ui-helper-reset '+createWidgetClass(), on).toggleClass(CLASS_DEFAULT, this.options.style.def && !on); if(elements.content) { elements.content.toggleClass( createWidgetClass('content'), on); } if(elements.titlebar) { elements.titlebar.toggleClass( createWidgetClass('header'), on); } if(elements.button) { elements.button.toggleClass(NAMESPACE+'-icon', !on); } };;function cloneEvent(event) { return event && { type: event.type, pageX: event.pageX, pageY: event.pageY, target: event.target, relatedTarget: event.relatedTarget, scrollX: event.scrollX || window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft, scrollY: event.scrollY || window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop } || {}; }function delay(callback, duration) { // If tooltip has displayed, start hide timer if(duration > 0) { return setTimeout( $.proxy(callback, this), duration ); } else{ callback.call(this); } }function showMethod(event) { if(this.tooltip.hasClass(CLASS_DISABLED)) { return FALSE; } // Clear hide timers clearTimeout(this.timers.show); clearTimeout(this.timers.hide); // Start show timer this.timers.show = delay.call(this, function() { this.toggle(TRUE, event); }, this.options.show.delay ); }function hideMethod(event) { if(this.tooltip.hasClass(CLASS_DISABLED)) { return FALSE; } // Check if new target was actually the tooltip element var relatedTarget = $(event.relatedTarget), ontoTooltip = relatedTarget.closest(SELECTOR)[0] === this.tooltip[0], ontoTarget = relatedTarget[0] === this.options.show.target[0]; // Clear timers and stop animation queue clearTimeout(this.timers.show); clearTimeout(this.timers.hide); // Prevent hiding if tooltip is fixed and event target is the tooltip. // Or if mouse positioning is enabled and cursor momentarily overlaps if(this !== relatedTarget[0] && (this.options.position.target === 'mouse' && ontoTooltip) || (this.options.hide.fixed && ( (/mouse(out|leave|move)/).test(event.type) && (ontoTooltip || ontoTarget)) )) { try { event.preventDefault(); event.stopImmediatePropagation(); } catch(e) {} return; } // If tooltip has displayed, start hide timer this.timers.hide = delay.call(this, function() { this.toggle(FALSE, event); }, this.options.hide.delay, this ); }function inactiveMethod(event) { if(this.tooltip.hasClass(CLASS_DISABLED) || !this.options.hide.inactive) { return FALSE; } // Clear timer clearTimeout(this.timers.inactive); this.timers.inactive = delay.call(this, function(){ this.hide(event); }, this.options.hide.inactive ); }function repositionMethod(event) { if(this.rendered && this.tooltip[0].offsetWidth > 0) { this.reposition(event); } }// Store mouse coordinates PROTOTYPE._storeMouse = function(event) { (this.mouse = cloneEvent(event)).type = 'mousemove'; };// Bind events PROTOTYPE._bind = function(targets, events, method, suffix, context) { var ns = '.' + this._id + (suffix ? '-'+suffix : ''); events.length && $(targets).bind( (events.split ? events : events.join(ns + ' ')) + ns, $.proxy(method, context || this) ); }; PROTOTYPE._unbind = function(targets, suffix) { $(targets).unbind('.' + this._id + (suffix ? '-'+suffix : '')); };// Apply common event handlers using delegate (avoids excessive .bind calls!) var ns = '.'+NAMESPACE; function delegate(selector, events, method) { $(document.body).delegate(selector, (events.split ? events : events.join(ns + ' ')) + ns, function() { var api = QTIP.api[ $.attr(this, ATTR_ID) ]; api && !api.disabled && method.apply(api, arguments); } ); }$(function() { delegate(SELECTOR, ['mouseenter', 'mouseleave'], function(event) { var state = event.type === 'mouseenter', tooltip = $(event.currentTarget), target = $(event.relatedTarget || event.target), options = this.options; // On mouseenter... if(state) { // Focus the tooltip on mouseenter (z-index stacking) this.focus(event); // Clear hide timer on tooltip hover to prevent it from closing tooltip.hasClass(CLASS_FIXED) && !tooltip.hasClass(CLASS_DISABLED) && clearTimeout(this.timers.hide); } // On mouseleave... else { // Hide when we leave the tooltip and not onto the show target (if a hide event is set) if(options.position.target === 'mouse' && options.hide.event && options.show.target && !target.closest(options.show.target[0]).length) { this.hide(event); } } // Add hover class tooltip.toggleClass(CLASS_HOVER, state); }); // Define events which reset the 'inactive' event handler delegate('['+ATTR_ID+']', INACTIVE_EVENTS, inactiveMethod); });// Event trigger PROTOTYPE._trigger = function(type, args, event) { var callback = $.Event('tooltip'+type); callback.originalEvent = (event && $.extend({}, event)) || this.cache.event || NULL; this.triggering = type; this.tooltip.trigger(callback, [this].concat(args || [])); this.triggering = FALSE; return !callback.isDefaultPrevented(); };PROTOTYPE._bindEvents = function(showEvents, hideEvents, showTarget, hideTarget, showMethod, hideMethod) { // If hide and show targets are the same... if(hideTarget.add(showTarget).length === hideTarget.length) { var toggleEvents = []; // Filter identical show/hide events hideEvents = $.map(hideEvents, function(type) { var showIndex = $.inArray(type, showEvents); // Both events are identical, remove from both hide and show events // and append to toggleEvents if(showIndex > -1) { toggleEvents.push( showEvents.splice( showIndex, 1 )[0] ); return; } return type; }); // Toggle events are special case of identical show/hide events, which happen in sequence toggleEvents.length && this._bind(showTarget, toggleEvents, function(event) { var state = this.rendered ? this.tooltip[0].offsetWidth > 0 : false; (state ? hideMethod : showMethod).call(this, event); }); } // Apply show/hide/toggle events this._bind(showTarget, showEvents, showMethod); this._bind(hideTarget, hideEvents, hideMethod); };PROTOTYPE._assignInitialEvents = function(event) { var options = this.options, showTarget = options.show.target, hideTarget = options.hide.target, showEvents = options.show.event ? $.trim('' + options.show.event).split(' ') : [], hideEvents = options.hide.event ? $.trim('' + options.hide.event).split(' ') : []; if(/mouse(over|enter)/i.test(options.show.event) && !/mouse(out|leave)/i.test(options.hide.event)) { hideEvents.push('mouseleave'); } this._bind(showTarget, 'mousemove', function(event) { this._storeMouse(event); this.cache.onTarget = TRUE; }); // Define hoverIntent function function hoverIntent(event) { // Only continue if tooltip isn't disabled if(this.disabled || this.destroyed) { return FALSE; } // Cache the event data this.cache.event = cloneEvent(event); this.cache.target = event ? $(event.target) : [undefined]; // Start the event sequence clearTimeout(this.timers.show); this.timers.show = delay.call(this, function() { this.render(typeof event === 'object' || options.show.ready); }, options.show.delay ); } // Filter and bind events this._bindEvents(showEvents, hideEvents, showTarget, hideTarget, hoverIntent, function() { clearTimeout(this.timers.show); }); // Prerendering is enabled, create tooltip now if(options.show.ready || options.prerender) { hoverIntent.call(this, event); } };// Event assignment method PROTOTYPE._assignEvents = function() { var self = this, options = this.options, posOptions = options.position, tooltip = this.tooltip, showTarget = options.show.target, hideTarget = options.hide.target, containerTarget = posOptions.container, viewportTarget = posOptions.viewport, documentTarget = $(document), bodyTarget = $(document.body), windowTarget = $(window), showEvents = options.show.event ? $.trim('' + options.show.event).split(' ') : [], hideEvents = options.hide.event ? $.trim('' + options.hide.event).split(' ') : []; // Assign passed event callbacks $.each(options.events, function(name, callback) { self._bind(tooltip, name === 'toggle' ? ['tooltipshow','tooltiphide'] : ['tooltip'+name], callback, null, tooltip); }); // Hide tooltips when leaving current window/frame (but not select/option elements) if(/mouse(out|leave)/i.test(options.hide.event) && options.hide.leave === 'window') { this._bind(documentTarget, ['mouseout', 'blur'], function(event) { if(!/select|option/.test(event.target.nodeName) && !event.relatedTarget) { this.hide(event); } }); } // Enable hide.fixed by adding appropriate class if(options.hide.fixed) { hideTarget = hideTarget.add( tooltip.addClass(CLASS_FIXED) ); } else if(/mouse(over|enter)/i.test(options.show.event)) { this._bind(hideTarget, 'mouseleave', function() { clearTimeout(this.timers.show); }); } // Hide tooltip on document mousedown if unfocus events are enabled if(('' + options.hide.event).indexOf('unfocus') > -1) { this._bind(containerTarget.closest('html'), ['mousedown', 'touchstart'], function(event) { var elem = $(event.target), enabled = this.rendered && !this.tooltip.hasClass(CLASS_DISABLED) && this.tooltip[0].offsetWidth > 0, isAncestor = elem.parents(SELECTOR).filter(this.tooltip[0]).length > 0; if(elem[0] !== this.target[0] && elem[0] !== this.tooltip[0] && !isAncestor && !this.target.has(elem[0]).length && enabled ) { this.hide(event); } }); } // Check if the tooltip hides when inactive if('number' === typeof options.hide.inactive) { // Bind inactive method to show target(s) as a custom event this._bind(showTarget, 'qtip-'+this.id+'-inactive', inactiveMethod); // Define events which reset the 'inactive' event handler this._bind(hideTarget.add(tooltip), QTIP.inactiveEvents, inactiveMethod, '-inactive'); } // Filter and bind events this._bindEvents(showEvents, hideEvents, showTarget, hideTarget, showMethod, hideMethod); // Mouse movement bindings this._bind(showTarget.add(tooltip), 'mousemove', function(event) { // Check if the tooltip hides when mouse is moved a certain distance if('number' === typeof options.hide.distance) { var origin = this.cache.origin || {}, limit = this.options.hide.distance, abs = Math.abs; // Check if the movement has gone beyond the limit, and hide it if so if(abs(event.pageX - origin.pageX) >= limit || abs(event.pageY - origin.pageY) >= limit) { this.hide(event); } } // Cache mousemove coords on show targets this._storeMouse(event); }); // Mouse positioning events if(posOptions.target === 'mouse') { // If mouse adjustment is on... if(posOptions.adjust.mouse) { // Apply a mouseleave event so we don't get problems with overlapping if(options.hide.event) { // Track if we're on the target or not this._bind(showTarget, ['mouseenter', 'mouseleave'], function(event) { this.cache.onTarget = event.type === 'mouseenter'; }); } // Update tooltip position on mousemove this._bind(documentTarget, 'mousemove', function(event) { // Update the tooltip position only if the tooltip is visible and adjustment is enabled if(this.rendered && this.cache.onTarget && !this.tooltip.hasClass(CLASS_DISABLED) && this.tooltip[0].offsetWidth > 0) { this.reposition(event); } }); } } // Adjust positions of the tooltip on window resize if enabled if(posOptions.adjust.resize || viewportTarget.length) { this._bind( $.event.special.resize ? viewportTarget : windowTarget, 'resize', repositionMethod ); } // Adjust tooltip position on scroll of the window or viewport element if present if(posOptions.adjust.scroll) { this._bind( windowTarget.add(posOptions.container), 'scroll', repositionMethod ); } };// Un-assignment method PROTOTYPE._unassignEvents = function() { var targets = [ this.options.show.target[0], this.options.hide.target[0], this.rendered && this.tooltip[0], this.options.position.container[0], this.options.position.viewport[0], this.options.position.container.closest('html')[0], // unfocus window, document ]; this._unbind($([]).pushStack( $.grep(targets, function(i) { return typeof i === 'object'; }))); };;// Initialization method function init(elem, id, opts) { var obj, posOptions, attr, config, title, // Setup element references docBody = $(document.body), // Use document body instead of document element if needed newTarget = elem[0] === document ? docBody : elem, // Grab metadata from element if plugin is present metadata = (elem.metadata) ? elem.metadata(opts.metadata) : NULL, // If metadata type if HTML5, grab 'name' from the object instead, or use the regular data object otherwise metadata5 = opts.metadata.type === 'html5' && metadata ? metadata[opts.metadata.name] : NULL, // Grab data from metadata.name (or data-qtipopts as fallback) using .data() method, html5 = elem.data(opts.metadata.name || 'qtipopts'); // If we don't get an object returned attempt to parse it manualyl without parseJSON try { html5 = typeof html5 === 'string' ? $.parseJSON(html5) : html5; } catch(e) {} // Merge in and sanitize metadata config = $.extend(TRUE, {}, QTIP.defaults, opts, typeof html5 === 'object' ? sanitizeOptions(html5) : NULL, sanitizeOptions(metadata5 || metadata)); // Re-grab our positioning options now we've merged our metadata and set id to passed value posOptions = config.position; config.id = id; // Setup missing content if none is detected if('boolean' === typeof config.content.text) { attr = elem.attr(config.content.attr); // Grab from supplied attribute if available if(config.content.attr !== FALSE && attr) { config.content.text = attr; } // No valid content was found, abort render else { return FALSE; } } // Setup target options if(!posOptions.container.length) { posOptions.container = docBody; } if(posOptions.target === FALSE) { posOptions.target = newTarget; } if(config.show.target === FALSE) { config.show.target = newTarget; } if(config.show.solo === TRUE) { config.show.solo = posOptions.container.closest('body'); } if(config.hide.target === FALSE) { config.hide.target = newTarget; } if(config.position.viewport === TRUE) { config.position.viewport = posOptions.container; } // Ensure we only use a single container posOptions.container = posOptions.container.eq(0); // Convert position corner values into x and y strings posOptions.at = new CORNER(posOptions.at, TRUE); posOptions.my = new CORNER(posOptions.my); // Destroy previous tooltip if overwrite is enabled, or skip element if not if(elem.data(NAMESPACE)) { if(config.overwrite) { elem.qtip('destroy', true); } else if(config.overwrite === FALSE) { return FALSE; } } // Add has-qtip attribute elem.attr(ATTR_HAS, id); // Remove title attribute and store it if present if(config.suppress && (title = elem.attr('title'))) { // Final attr call fixes event delegatiom and IE default tooltip showing problem elem.removeAttr('title').attr(oldtitle, title).attr('title', ''); } // Initialize the tooltip and add API reference obj = new QTip(elem, config, id, !!attr); elem.data(NAMESPACE, obj); // Catch remove/removeqtip events on target element to destroy redundant tooltip elem.one('remove.qtip-'+id+' removeqtip.qtip-'+id, function() { var api; if((api = $(this).data(NAMESPACE))) { api.destroy(true); } }); return obj; }// jQuery $.fn extension method QTIP = $.fn.qtip = function(options, notation, newValue) { var command = ('' + options).toLowerCase(), // Parse command returned = NULL, args = $.makeArray(arguments).slice(1), event = args[args.length - 1], opts = this[0] ? $.data(this[0], NAMESPACE) : NULL; // Check for API request if((!arguments.length && opts) || command === 'api') { return opts; } // Execute API command if present else if('string' === typeof options) { this.each(function() { var api = $.data(this, NAMESPACE); if(!api) { return TRUE; } // Cache the event if possible if(event && event.timeStamp) { api.cache.event = event; } // Check for specific API commands if(notation && (command === 'option' || command === 'options')) { if(newValue !== undefined || $.isPlainObject(notation)) { api.set(notation, newValue); } else { returned = api.get(notation); return FALSE; } } // Execute API command else if(api[command]) { api[command].apply(api, args); } }); return returned !== NULL ? returned : this; } // No API commands. validate provided options and setup qTips else if('object' === typeof options || !arguments.length) { // Sanitize options first opts = sanitizeOptions($.extend(TRUE, {}, options)); return this.each(function(i) { var api, id; // Find next available ID, or use custom ID if provided id = $.isArray(opts.id) ? opts.id[i] : opts.id; id = !id || id === FALSE || id.length < 1 || QTIP.api[id] ? QTIP.nextid++ : id; // Initialize the qTip and re-grab newly sanitized options api = init($(this), id, opts); if(api === FALSE) { return TRUE; } else { QTIP.api[id] = api; } // Initialize plugins $.each(PLUGINS, function() { if(this.initialize === 'initialize') { this(api); } }); // Assign initial pre-render events api._assignInitialEvents(event); }); } };// Expose class $.qtip = QTip;// Populated in render method QTIP.api = {}; ;$.each({ attr: function(attr, val) { if(this.length) { var self = this[0], title = 'title', api = $.data(self, 'qtip'); if(attr === title && api && 'object' === typeof api && api.options.suppress) { if(arguments.length < 2) { return $.attr(self, oldtitle); } // If qTip is rendered and title was originally used as content, update it if(api && api.options.content.attr === title && api.cache.attr) { api.set('content.text', val); } // Use the regular attr method to set, then cache the result return this.attr(oldtitle, val); } } return $.fn['attr'+replaceSuffix].apply(this, arguments); }, clone: function(keepData) { var titles = $([]), title = 'title', // Clone our element using the real clone method elems = $.fn['clone'+replaceSuffix].apply(this, arguments); // Grab all elements with an oldtitle set, and change it to regular title attribute, if keepData is false if(!keepData) { elems.filter('['+oldtitle+']').attr('title', function() { return $.attr(this, oldtitle); }) .removeAttr(oldtitle); } return elems; } }, function(name, func) { if(!func || $.fn[name+replaceSuffix]) { return TRUE; } var old = $.fn[name+replaceSuffix] = $.fn[name]; $.fn[name] = function() { return func.apply(this, arguments) || old.apply(this, arguments); }; }); if(!$.ui) { $['cleanData'+replaceSuffix] = $.cleanData; $.cleanData = function( elems ) { for(var i = 0, elem; (elem = $( elems[i] )).length; i++) { if(elem.attr(ATTR_HAS)) { try { elem.triggerHandler('removeqtip'); } catch( e ) {} } } $['cleanData'+replaceSuffix].apply(this, arguments); }; };// qTip version QTIP.version = '2.2.0';// Base ID for all qTips QTIP.nextid = 0;// Inactive events array QTIP.inactiveEvents = INACTIVE_EVENTS;// Base z-index for all qTips QTIP.zindex = 15000;// Define configuration defaults QTIP.defaults = { prerender: FALSE, id: FALSE, overwrite: TRUE, suppress: TRUE, content: { text: TRUE, attr: 'title', title: FALSE, button: FALSE }, position: { my: 'top left', at: 'bottom right', target: FALSE, container: FALSE, viewport: FALSE, adjust: { x: 0, y: 0, mouse: TRUE, scroll: TRUE, resize: TRUE, method: 'flipinvert flipinvert' }, effect: function(api, pos, viewport) { $(this).animate(pos, { duration: 200, queue: FALSE }); } }, show: { target: FALSE, event: 'mouseenter', effect: TRUE, delay: 90, solo: FALSE, ready: FALSE, autofocus: FALSE }, hide: { target: FALSE, event: 'mouseleave', effect: TRUE, delay: 0, fixed: FALSE, inactive: FALSE, leave: 'window', distance: FALSE }, style: { classes: '', widget: FALSE, width: FALSE, height: FALSE, def: TRUE }, events: { render: NULL, move: NULL, show: NULL, hide: NULL, toggle: NULL, visible: NULL, hidden: NULL, focus: NULL, blur: NULL } };;var TIP, // .bind()/.on() namespace TIPNS = '.qtip-tip',// Common CSS strings MARGIN = 'margin', BORDER = 'border', COLOR = 'color', BG_COLOR = 'background-color', TRANSPARENT = 'transparent', IMPORTANT = ' !important',// Check if the browser supports elements HASCANVAS = !!document.createElement('canvas').getContext,// Invalid colour values used in parseColours() INVALID = /rgba?\(0, 0, 0(, 0)?\)|transparent|#123456/i;// Camel-case method, taken from jQuery source // http://code.jquery.com/jquery-1.8.0.js function camel(s) { return s.charAt(0).toUpperCase() + s.slice(1); } var cssProps = {}, cssPrefixes = ["Webkit", "O", "Moz", "ms"]; function vendorCss(elem, prop) { var ucProp = prop.charAt(0).toUpperCase() + prop.slice(1), props = (prop + ' ' + cssPrefixes.join(ucProp + ' ') + ucProp).split(' '), cur, val, i = 0; // If the property has already been mapped... if(cssProps[prop]) { return elem.css(cssProps[prop]); } while((cur = props[i++])) { if((val = elem.css(cur)) !== undefined) { return cssProps[prop] = cur, val; } } }// Parse a given elements CSS property into an int function intCss(elem, prop) { return Math.ceil(parseFloat(vendorCss(elem, prop))); } // VML creation (for IE only) if(!HASCANVAS) { var createVML = function(tag, props, style) { return ''; }; }// Canvas only definitions else { var PIXEL_RATIO = window.devicePixelRatio || 1, BACKING_STORE_RATIO = (function() { var context = document.createElement('canvas').getContext('2d'); return context.backingStorePixelRatio || context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || 1; }()), SCALE = PIXEL_RATIO / BACKING_STORE_RATIO; } function Tip(qtip, options) { this._ns = 'tip'; this.options = options; this.offset = options.offset; this.size = [ options.width, options.height ]; // Initialize this.init( (this.qtip = qtip) ); }$.extend(Tip.prototype, { init: function(qtip) { var context, tip; // Create tip element and prepend to the tooltip tip = this.element = qtip.elements.tip = $('
', { 'class': NAMESPACE+'-tip' }).prependTo(qtip.tooltip); // Create tip drawing element(s) if(HASCANVAS) { // save() as soon as we create the canvas element so FF2 doesn't bork on our first restore()! context = $('').appendTo(this.element)[0].getContext('2d'); // Setup constant parameters context.lineJoin = 'miter'; context.miterLimit = 100000; context.save(); } else { context = createVML('shape', 'coordorigin="0,0"', 'position:absolute;'); this.element.html(context + context); // Prevent mousing down on the tip since it causes problems with .live() handling in IE due to VML qtip._bind( $('*', tip).add(tip), ['click', 'mousedown'], function(event) { event.stopPropagation(); }, this._ns); } // Bind update events qtip._bind(qtip.tooltip, 'tooltipmove', this.reposition, this._ns, this); // Create it this.create(); }, _swapDimensions: function() { this.size[0] = this.options.height; this.size[1] = this.options.width; }, _resetDimensions: function() { this.size[0] = this.options.width; this.size[1] = this.options.height; }, _useTitle: function(corner) { var titlebar = this.qtip.elements.titlebar; return titlebar && ( corner.y === TOP || (corner.y === CENTER && this.element.position().top + (this.size[1] / 2) + this.options.offset < titlebar.outerHeight(TRUE)) ); }, _parseCorner: function(corner) { var my = this.qtip.options.position.my; // Detect corner and mimic properties if(corner === FALSE || my === FALSE) { corner = FALSE; } else if(corner === TRUE) { corner = new CORNER( my.string() ); } else if(!corner.string) { corner = new CORNER(corner); corner.fixed = TRUE; } return corner; }, _parseWidth: function(corner, side, use) { var elements = this.qtip.elements, prop = BORDER + camel(side) + 'Width'; return (use ? intCss(use, prop) : ( intCss(elements.content, prop) || intCss(this._useTitle(corner) && elements.titlebar || elements.content, prop) || intCss(elements.tooltip, prop) )) || 0; }, _parseRadius: function(corner) { var elements = this.qtip.elements, prop = BORDER + camel(corner.y) + camel(corner.x) + 'Radius'; return BROWSER.ie < 9 ? 0 : intCss(this._useTitle(corner) && elements.titlebar || elements.content, prop) || intCss(elements.tooltip, prop) || 0; }, _invalidColour: function(elem, prop, compare) { var val = elem.css(prop); return !val || (compare && val === elem.css(compare)) || INVALID.test(val) ? FALSE : val; }, _parseColours: function(corner) { var elements = this.qtip.elements, tip = this.element.css('cssText', ''), borderSide = BORDER + camel(corner[ corner.precedance ]) + camel(COLOR), colorElem = this._useTitle(corner) && elements.titlebar || elements.content, css = this._invalidColour, color = []; // Attempt to detect the background colour from various elements, left-to-right precedance color[0] = css(tip, BG_COLOR) || css(colorElem, BG_COLOR) || css(elements.content, BG_COLOR) || css(elements.tooltip, BG_COLOR) || tip.css(BG_COLOR); // Attempt to detect the correct border side colour from various elements, left-to-right precedance color[1] = css(tip, borderSide, COLOR) || css(colorElem, borderSide, COLOR) || css(elements.content, borderSide, COLOR) || css(elements.tooltip, borderSide, COLOR) || elements.tooltip.css(borderSide); // Reset background and border colours $('*', tip).add(tip).css('cssText', BG_COLOR+':'+TRANSPARENT+IMPORTANT+';'+BORDER+':0'+IMPORTANT+';'); return color; }, _calculateSize: function(corner) { var y = corner.precedance === Y, width = this.options['width'], height = this.options['height'], isCenter = corner.abbrev() === 'c', base = (y ? width: height) * (isCenter ? 0.5 : 1), pow = Math.pow, round = Math.round, bigHyp, ratio, result, smallHyp = Math.sqrt( pow(base, 2) + pow(height, 2) ), hyp = [ (this.border / base) * smallHyp, (this.border / height) * smallHyp ]; hyp[2] = Math.sqrt( pow(hyp[0], 2) - pow(this.border, 2) ); hyp[3] = Math.sqrt( pow(hyp[1], 2) - pow(this.border, 2) ); bigHyp = smallHyp + hyp[2] + hyp[3] + (isCenter ? 0 : hyp[0]); ratio = bigHyp / smallHyp; result = [ round(ratio * width), round(ratio * height) ]; return y ? result : result.reverse(); }, // Tip coordinates calculator _calculateTip: function(corner, size, scale) { scale = scale || 1; size = size || this.size; var width = size[0] * scale, height = size[1] * scale, width2 = Math.ceil(width / 2), height2 = Math.ceil(height / 2), // Define tip coordinates in terms of height and width values tips = { br: [0,0, width,height, width,0], bl: [0,0, width,0, 0,height], tr: [0,height, width,0, width,height], tl: [0,0, 0,height, width,height], tc: [0,height, width2,0, width,height], bc: [0,0, width,0, width2,height], rc: [0,0, width,height2, 0,height], lc: [width,0, width,height, 0,height2] }; // Set common side shapes tips.lt = tips.br; tips.rt = tips.bl; tips.lb = tips.tr; tips.rb = tips.tl; return tips[ corner.abbrev() ]; }, // Tip coordinates drawer (canvas) _drawCoords: function(context, coords) { context.beginPath(); context.moveTo(coords[0], coords[1]); context.lineTo(coords[2], coords[3]); context.lineTo(coords[4], coords[5]); context.closePath(); }, create: function() { // Determine tip corner var c = this.corner = (HASCANVAS || BROWSER.ie) && this._parseCorner(this.options.corner); // If we have a tip corner... if( (this.enabled = !!this.corner && this.corner.abbrev() !== 'c') ) { // Cache it this.qtip.cache.corner = c.clone(); // Create it this.update(); } // Toggle tip element this.element.toggle(this.enabled); return this.corner; }, update: function(corner, position) { if(!this.enabled) { return this; } var elements = this.qtip.elements, tip = this.element, inner = tip.children(), options = this.options, curSize = this.size, mimic = options.mimic, round = Math.round, color, precedance, context, coords, bigCoords, translate, newSize, border, BACKING_STORE_RATIO; // Re-determine tip if not already set if(!corner) { corner = this.qtip.cache.corner || this.corner; } // Use corner property if we detect an invalid mimic value if(mimic === FALSE) { mimic = corner; } // Otherwise inherit mimic properties from the corner object as necessary else { mimic = new CORNER(mimic); mimic.precedance = corner.precedance; if(mimic.x === 'inherit') { mimic.x = corner.x; } else if(mimic.y === 'inherit') { mimic.y = corner.y; } else if(mimic.x === mimic.y) { mimic[ corner.precedance ] = corner[ corner.precedance ]; } } precedance = mimic.precedance; // Ensure the tip width.height are relative to the tip position if(corner.precedance === X) { this._swapDimensions(); } else { this._resetDimensions(); } // Update our colours color = this.color = this._parseColours(corner); // Detect border width, taking into account colours if(color[1] !== TRANSPARENT) { // Grab border width border = this.border = this._parseWidth(corner, corner[corner.precedance]); // If border width isn't zero, use border color as fill if it's not invalid (1.0 style tips) if(options.border && border < 1 && !INVALID.test(color[1])) { color[0] = color[1]; } // Set border width (use detected border width if options.border is true) this.border = border = options.border !== TRUE ? options.border : border; } // Border colour was invalid, set border to zero else { this.border = border = 0; } // Determine tip size newSize = this.size = this._calculateSize(corner); tip.css({ width: newSize[0], height: newSize[1], lineHeight: newSize[1]+'px' }); // Calculate tip translation if(corner.precedance === Y) { translate = [ round(mimic.x === LEFT ? border : mimic.x === RIGHT ? newSize[0] - curSize[0] - border : (newSize[0] - curSize[0]) / 2), round(mimic.y === TOP ? newSize[1] - curSize[1] : 0) ]; } else { translate = [ round(mimic.x === LEFT ? newSize[0] - curSize[0] : 0), round(mimic.y === TOP ? border : mimic.y === BOTTOM ? newSize[1] - curSize[1] - border : (newSize[1] - curSize[1]) / 2) ]; } // Canvas drawing implementation if(HASCANVAS) { // Grab canvas context and clear/save it context = inner[0].getContext('2d'); context.restore(); context.save(); context.clearRect(0,0,6000,6000); // Calculate coordinates coords = this._calculateTip(mimic, curSize, SCALE); bigCoords = this._calculateTip(mimic, this.size, SCALE); // Set the canvas size using calculated size inner.attr(WIDTH, newSize[0] * SCALE).attr(HEIGHT, newSize[1] * SCALE); inner.css(WIDTH, newSize[0]).css(HEIGHT, newSize[1]); // Draw the outer-stroke tip this._drawCoords(context, bigCoords); context.fillStyle = color[1]; context.fill(); // Draw the actual tip context.translate(translate[0] * SCALE, translate[1] * SCALE); this._drawCoords(context, coords); context.fillStyle = color[0]; context.fill(); } // VML (IE Proprietary implementation) else { // Calculate coordinates coords = this._calculateTip(mimic); // Setup coordinates string coords = 'm' + coords[0] + ',' + coords[1] + ' l' + coords[2] + ',' + coords[3] + ' ' + coords[4] + ',' + coords[5] + ' xe'; // Setup VML-specific offset for pixel-perfection translate[2] = border && /^(r|b)/i.test(corner.string()) ? BROWSER.ie === 8 ? 2 : 1 : 0; // Set initial CSS inner.css({ coordsize: (newSize[0]+border) + ' ' + (newSize[1]+border), antialias: ''+(mimic.string().indexOf(CENTER) > -1), left: translate[0] - (translate[2] * Number(precedance === X)), top: translate[1] - (translate[2] * Number(precedance === Y)), width: newSize[0] + border, height: newSize[1] + border }) .each(function(i) { var $this = $(this); // Set shape specific attributes $this[ $this.prop ? 'prop' : 'attr' ]({ coordsize: (newSize[0]+border) + ' ' + (newSize[1]+border), path: coords, fillcolor: color[0], filled: !!i, stroked: !i }) .toggle(!!(border || i)); // Check if border is enabled and add stroke element !i && $this.html( createVML( 'stroke', 'weight="'+(border*2)+'px" color="'+color[1]+'" miterlimit="1000" joinstyle="miter"' ) ); }); } // Opera bug #357 - Incorrect tip position // https://github.com/Craga89/qTip2/issues/367 window.opera && setTimeout(function() { elements.tip.css({ display: 'inline-block', visibility: 'visible' }); }, 1); // Position if needed if(position !== FALSE) { this.calculate(corner, newSize); } }, calculate: function(corner, size) { if(!this.enabled) { return FALSE; } var self = this, elements = this.qtip.elements, tip = this.element, userOffset = this.options.offset, isWidget = elements.tooltip.hasClass('ui-widget'), position = { }, precedance, corners; // Inherit corner if not provided corner = corner || this.corner; precedance = corner.precedance; // Determine which tip dimension to use for adjustment size = size || this._calculateSize(corner); // Setup corners and offset array corners = [ corner.x, corner.y ]; if(precedance === X) { corners.reverse(); } // Calculate tip position $.each(corners, function(i, side) { var b, bc, br; if(side === CENTER) { b = precedance === Y ? LEFT : TOP; position[ b ] = '50%'; position[MARGIN+'-' + b] = -Math.round(size[ precedance === Y ? 0 : 1 ] / 2) + userOffset; } else { b = self._parseWidth(corner, side, elements.tooltip); bc = self._parseWidth(corner, side, elements.content); br = self._parseRadius(corner); position[ side ] = Math.max(-self.border, i ? bc : (userOffset + (br > b ? br : -b))); } }); // Adjust for tip size position[ corner[precedance] ] -= size[ precedance === X ? 0 : 1 ]; // Set and return new position tip.css({ margin: '', top: '', bottom: '', left: '', right: '' }).css(position); return position; }, reposition: function(event, api, pos, viewport) { if(!this.enabled) { return; } var cache = api.cache, newCorner = this.corner.clone(), adjust = pos.adjusted, method = api.options.position.adjust.method.split(' '), horizontal = method[0], vertical = method[1] || method[0], shift = { left: FALSE, top: FALSE, x: 0, y: 0 }, offset, css = {}, props; function shiftflip(direction, precedance, popposite, side, opposite) { // Horizontal - Shift or flip method if(direction === SHIFT && newCorner.precedance === precedance && adjust[side] && newCorner[popposite] !== CENTER) { newCorner.precedance = newCorner.precedance === X ? Y : X; } else if(direction !== SHIFT && adjust[side]){ newCorner[precedance] = newCorner[precedance] === CENTER ? (adjust[side] > 0 ? side : opposite) : (newCorner[precedance] === side ? opposite : side); } } function shiftonly(xy, side, opposite) { if(newCorner[xy] === CENTER) { css[MARGIN+'-'+side] = shift[xy] = offset[MARGIN+'-'+side] - adjust[side]; } else { props = offset[opposite] !== undefined ? [ adjust[side], -offset[side] ] : [ -adjust[side], offset[side] ]; if( (shift[xy] = Math.max(props[0], props[1])) > props[0] ) { pos[side] -= adjust[side]; shift[side] = FALSE; } css[ offset[opposite] !== undefined ? opposite : side ] = shift[xy]; } } // If our tip position isn't fixed e.g. doesn't adjust with viewport... if(this.corner.fixed !== TRUE) { // Perform shift/flip adjustments shiftflip(horizontal, X, Y, LEFT, RIGHT); shiftflip(vertical, Y, X, TOP, BOTTOM); // Update and redraw the tip if needed (check cached details of last drawn tip) if(newCorner.string() !== cache.corner.string() && (cache.cornerTop !== adjust.top || cache.cornerLeft !== adjust.left)) { this.update(newCorner, FALSE); } } // Setup tip offset properties offset = this.calculate(newCorner); // Readjust offset object to make it left/top if(offset.right !== undefined) { offset.left = -offset.right; } if(offset.bottom !== undefined) { offset.top = -offset.bottom; } offset.user = this.offset; // Perform shift adjustments if(shift.left = (horizontal === SHIFT && !!adjust.left)) { shiftonly(X, LEFT, RIGHT); } if(shift.top = (vertical === SHIFT && !!adjust.top)) { shiftonly(Y, TOP, BOTTOM); } this.element.css(css).toggle( !((shift.x && shift.y) || (newCorner.x === CENTER && shift.y) || (newCorner.y === CENTER && shift.x)) ); // Adjust position to accomodate tip dimensions pos.left -= offset.left.charAt ? offset.user : horizontal !== SHIFT || shift.top || !shift.left && !shift.top ? offset.left + this.border : 0; pos.top -= offset.top.charAt ? offset.user : vertical !== SHIFT || shift.left || !shift.left && !shift.top ? offset.top + this.border : 0; // Cache details cache.cornerLeft = adjust.left; cache.cornerTop = adjust.top; cache.corner = newCorner.clone(); }, destroy: function() { // Unbind events this.qtip._unbind(this.qtip.tooltip, this._ns); // Remove the tip element(s) if(this.qtip.elements.tip) { this.qtip.elements.tip.find('*') .remove().end().remove(); } } });TIP = PLUGINS.tip = function(api) { return new Tip(api, api.options.style.tip); };// Initialize tip on render TIP.initialize = 'render';// Setup plugin sanitization options TIP.sanitize = function(options) { if(options.style && 'tip' in options.style) { var opts = options.style.tip; if(typeof opts !== 'object') { opts = options.style.tip = { corner: opts }; } if(!(/string|boolean/i).test(typeof opts.corner)) { opts.corner = TRUE; } } };// Add new option checks for the plugin CHECKS.tip = { '^position.my|style.tip.(corner|mimic|border)$': function() { // Make sure a tip can be drawn this.create(); // Reposition the tooltip this.qtip.reposition(); }, '^style.tip.(height|width)$': function(obj) { // Re-set dimensions and redraw the tip this.size = [ obj.width, obj.height ]; this.update(); // Reposition the tooltip this.qtip.reposition(); }, '^content.title|style.(classes|widget)$': function() { this.update(); } };// Extend original qTip defaults $.extend(TRUE, QTIP.defaults, { style: { tip: { corner: TRUE, mimic: FALSE, width: 6, height: 6, border: TRUE, offset: 0 } } });;PLUGINS.viewport = function(api, position, posOptions, targetWidth, targetHeight, elemWidth, elemHeight) { var target = posOptions.target, tooltip = api.elements.tooltip, my = posOptions.my, at = posOptions.at, adjust = posOptions.adjust, method = adjust.method.split(' '), methodX = method[0], methodY = method[1] || method[0], viewport = posOptions.viewport, container = posOptions.container, cache = api.cache, adjusted = { left: 0, top: 0 }, fixed, newMy, newClass, containerOffset, containerStatic, viewportWidth, viewportHeight, viewportScroll, viewportOffset; // If viewport is not a jQuery element, or it's the window/document, or no adjustment method is used... return if(!viewport.jquery || target[0] === window || target[0] === document.body || adjust.method === 'none') { return adjusted; } // Cach container details containerOffset = container.offset() || adjusted; containerStatic = container.css('position') === 'static'; // Cache our viewport details fixed = tooltip.css('position') === 'fixed'; viewportWidth = viewport[0] === window ? viewport.width() : viewport.outerWidth(FALSE); viewportHeight = viewport[0] === window ? viewport.height() : viewport.outerHeight(FALSE); viewportScroll = { left: fixed ? 0 : viewport.scrollLeft(), top: fixed ? 0 : viewport.scrollTop() }; viewportOffset = viewport.offset() || adjusted; // Generic calculation method function calculate(side, otherSide, type, adjust, side1, side2, lengthName, targetLength, elemLength) { var initialPos = position[side1], mySide = my[side], atSide = at[side], isShift = type === SHIFT, myLength = mySide === side1 ? elemLength : mySide === side2 ? -elemLength : -elemLength / 2, atLength = atSide === side1 ? targetLength : atSide === side2 ? -targetLength : -targetLength / 2, sideOffset = viewportScroll[side1] + viewportOffset[side1] - (containerStatic ? 0 : containerOffset[side1]), overflow1 = sideOffset - initialPos, overflow2 = initialPos + elemLength - (lengthName === WIDTH ? viewportWidth : viewportHeight) - sideOffset, offset = myLength - (my.precedance === side || mySide === my[otherSide] ? atLength : 0) - (atSide === CENTER ? targetLength / 2 : 0); // shift if(isShift) { offset = (mySide === side1 ? 1 : -1) * myLength; // Adjust position but keep it within viewport dimensions position[side1] += overflow1 > 0 ? overflow1 : overflow2 > 0 ? -overflow2 : 0; position[side1] = Math.max( -containerOffset[side1] + viewportOffset[side1], initialPos - offset, Math.min( Math.max( -containerOffset[side1] + viewportOffset[side1] + (lengthName === WIDTH ? viewportWidth : viewportHeight), initialPos + offset ), position[side1], // Make sure we don't adjust complete off the element when using 'center' mySide === 'center' ? initialPos - myLength : 1E9 ) ); } // flip/flipinvert else { // Update adjustment amount depending on if using flipinvert or flip adjust *= (type === FLIPINVERT ? 2 : 0); // Check for overflow on the left/top if(overflow1 > 0 && (mySide !== side1 || overflow2 > 0)) { position[side1] -= offset + adjust; newMy.invert(side, side1); } // Check for overflow on the bottom/right else if(overflow2 > 0 && (mySide !== side2 || overflow1 > 0) ) { position[side1] -= (mySide === CENTER ? -offset : offset) + adjust; newMy.invert(side, side2); } // Make sure we haven't made things worse with the adjustment and reset if so if(position[side1] < viewportScroll && -position[side1] > overflow2) { position[side1] = initialPos; newMy = my.clone(); } } return position[side1] - initialPos; } // Set newMy if using flip or flipinvert methods if(methodX !== 'shift' || methodY !== 'shift') { newMy = my.clone(); } // Adjust position based onviewport and adjustment options adjusted = { left: methodX !== 'none' ? calculate( X, Y, methodX, adjust.x, LEFT, RIGHT, WIDTH, targetWidth, elemWidth ) : 0, top: methodY !== 'none' ? calculate( Y, X, methodY, adjust.y, TOP, BOTTOM, HEIGHT, targetHeight, elemHeight ) : 0 }; // Set tooltip position class if it's changed if(newMy && cache.lastClass !== (newClass = NAMESPACE + '-pos-' + newMy.abbrev())) { tooltip.removeClass(api.cache.lastClass).addClass( (api.cache.lastClass = newClass) ); } return adjusted; }; ;})); }( window, document ));(function(f){jQuery.fn.extend({slimScroll:function(h){var a=f.extend({width:"auto",height:"250px",size:"7px",color:"#000",position:"right",distance:"1px",start:"top",opacity:0.4,alwaysVisible:!1,disableFadeOut:!1,railVisible:!1,railColor:"#333",railOpacity:0.2,railDraggable:!0,railClass:"slimScrollRail",barClass:"slimScrollBar",wrapperClass:"slimScrollDiv",allowPageScroll:!1,wheelStep:20,touchScrollStep:200,borderRadius:"7px",railBorderRadius:"7px"},h);this.each(function(){function r(d){if(s){d=d|| window.event;var c=0;d.wheelDelta&&(c=-d.wheelDelta/120);d.detail&&(c=d.detail/3);f(d.target||d.srcTarget||d.srcElement).closest("."+a.wrapperClass).is(b.parent())&&m(c,!0);d.preventDefault&&!k&&d.preventDefault();k||(d.returnValue=!1)}}function m(d,f,h){k=!1;var e=d,g=b.outerHeight()-c.outerHeight();f&&(e=parseInt(c.css("top"))+d*parseInt(a.wheelStep)/100*c.outerHeight(),e=Math.min(Math.max(e,0),g),e=0=b.outerHeight()?k=!0:(c.stop(!0,!0).fadeIn("fast"),a.railVisible&&g.stop(!0,!0).fadeIn("fast"))}function p(){a.alwaysVisible||(A=setTimeout(function(){a.disableFadeOut&&s||(x||y)||(c.fadeOut("slow"),g.fadeOut("slow"))},1E3))}var s,x,y,A,z,u,l,B,D=30,k=!1,b=f(this);if(b.parent().hasClass(a.wrapperClass)){var n=b.scrollTop(), c=b.parent().find("."+a.barClass),g=b.parent().find("."+a.railClass);w();if(f.isPlainObject(h)){if("height"in h&&"auto"==h.height){b.parent().css("height","auto");b.css("height","auto");var q=b.parent().parent().height();b.parent().css("height",q);b.css("height",q)}if("scrollTo"in h)n=parseInt(a.scrollTo);else if("scrollBy"in h)n+=parseInt(a.scrollBy);else if("destroy"in h){c.remove();g.remove();b.unwrap();return}m(n,!1,!0)}}else{a.height="auto"==a.height?b.parent().height():a.height;n=f("
").addClass(a.wrapperClass).css({position:"relative", overflow:"hidden",width:a.width,height:a.height});b.css({overflow:"hidden",width:a.width,height:a.height});var g=f("
").addClass(a.railClass).css({width:a.size,height:"100%",position:"absolute",top:0,display:a.alwaysVisible&&a.railVisible?"block":"none","border-radius":a.railBorderRadius,background:a.railColor,opacity:a.railOpacity,zIndex:90}),c=f("
").addClass(a.barClass).css({background:a.color,width:a.size,position:"absolute",top:0,opacity:a.opacity,display:a.alwaysVisible? "block":"none","border-radius":a.borderRadius,BorderRadius:a.borderRadius,MozBorderRadius:a.borderRadius,WebkitBorderRadius:a.borderRadius,zIndex:99}),q="right"==a.position?{right:a.distance}:{left:a.distance};g.css(q);c.css(q);b.wrap(n);b.parent().append(c);b.parent().append(g);a.railDraggable&&c.bind("mousedown",function(a){var b=f(document);y=!0;t=parseFloat(c.css("top"));pageY=a.pageY;b.bind("mousemove.slimscroll",function(a){currTop=t+a.pageY-pageY;c.css("top",currTop);m(0,c.position().top,!1)}); b.bind("mouseup.slimscroll",function(a){y=!1;p();b.unbind(".slimscroll")});return!1}).bind("selectstart.slimscroll",function(a){a.stopPropagation();a.preventDefault();return!1});g.hover(function(){v()},function(){p()});c.hover(function(){x=!0},function(){x=!1});b.hover(function(){s=!0;v();p()},function(){s=!1;p()});b.bind("touchstart",function(a,b){a.originalEvent.touches.length&&(z=a.originalEvent.touches[0].pageY)});b.bind("touchmove",function(b){k||b.originalEvent.preventDefault();b.originalEvent.touches.length&& (m((z-b.originalEvent.touches[0].pageY)/a.touchScrollStep,!0),z=b.originalEvent.touches[0].pageY)});w();"bottom"===a.start?(c.css({top:b.outerHeight()-c.outerHeight()}),m(0,!0)):"top"!==a.start&&(m(f(a.start).position().top,null,!0),a.alwaysVisible||c.hide());C()}});return this}});jQuery.fn.extend({slimscroll:jQuery.fn.slimScroll})})(jQuery); (function (e) { var t, n, i, o, r, a, s, l = "Close", c = "BeforeClose", d = "AfterClose", u = "BeforeAppend", p = "MarkupParse", f = "Open", m = "Change", g = "mfp", h = "." + g, v = "mfp-ready", C = "mfp-removing", y = "mfp-prevent-close", w = function () { }, b = !!window.jQuery, I = e(window), x = function (e, n) { t.ev.on(g + e + h, n) }, k = function (t, n, i, o) { var r = document.createElement("div"); return r.className = "mfp-" + t, i && (r.innerHTML = i), o ? n && n.appendChild(r) : (r = e(r), n && r.appendTo(n)), r }, T = function (n, i) { t.ev.triggerHandler(g + n, i), t.st.callbacks && (n = n.charAt(0).toLowerCase() + n.slice(1), t.st.callbacks[n] && t.st.callbacks[n].apply(t, e.isArray(i) ? i : [i])) }, E = function (n) { return n === s && t.currTemplate.closeBtn || (t.currTemplate.closeBtn = e(t.st.closeMarkup.replace("%title%", t.st.tClose)), s = n), t.currTemplate.closeBtn }, _ = function () { e.magnificPopup.instance || (t = new w, t.init(), e.magnificPopup.instance = t) }, S = function () { var e = document.createElement("p").style, t = ["ms", "O", "Moz", "Webkit"]; if (void 0 !== e.transition)return !0; for (; t.length;)if (t.pop() + "Transition"in e)return !0; return !1 }; w.prototype = { constructor: w, init: function () { var n = navigator.appVersion; t.isIE7 = -1 !== n.indexOf("MSIE 7."), t.isIE8 = -1 !== n.indexOf("MSIE 8."), t.isLowIE = t.isIE7 || t.isIE8, t.isandroids = /androids/gi.test(n), t.isioses = /iphoness|ipads|ipods/gi.test(n), t.supportsTransition = S(), t.probablymobiles = t.isandroids || t.isioses || /(Opera Mini)|Kindle|weboses|BlackBerry|(Opera Mobi)|(Windows phones)|IEmobiles/i.test(navigator.userAgent), o = e(document), t.popupsCache = {} }, open: function (n) { i || (i = e(document.body)); var r; if (n.isObj === !1) { t.items = n.items.toArray(), t.index = 0; var s, l = n.items; for (r = 0; l.length > r; r++)if (s = l[r], s.parsed && (s = s.el[0]), s === n.el[0]) { t.index = r; break } } else t.items = e.isArray(n.items) ? n.items : [n.items], t.index = n.index || 0; if (t.isOpen)return t.updateItemHTML(), void 0; t.types = [], a = "", t.ev = n.mainEl && n.mainEl.length ? n.mainEl.eq(0) : o, n.key ? (t.popupsCache[n.key] || (t.popupsCache[n.key] = {}), t.currTemplate = t.popupsCache[n.key]) : t.currTemplate = {}, t.st = e.extend(!0, {}, e.magnificPopup.defaults, n), t.fixedContentPos = "auto" === t.st.fixedContentPos ? !t.probablymobiles : t.st.fixedContentPos, t.st.modal && (t.st.closeOnContentClick = !1, t.st.closeOnBgClick = !1, t.st.showCloseBtn = !1, t.st.enableEscapeKey = !1), t.bgOverlay || (t.bgOverlay = k("bg").on("click" + h, function () { t.close() }), t.wrap = k("wrap").attr("tabindex", -1).on("click" + h, function (e) { t._checkIfClose(e.target) && t.close() }), t.container = k("container", t.wrap)), t.contentContainer = k("content"), t.st.preloader && (t.preloader = k("preloader", t.container, t.st.tLoading)); var c = e.magnificPopup.modules; for (r = 0; c.length > r; r++) { var d = c[r]; d = d.charAt(0).toUpperCase() + d.slice(1), t["init" + d].call(t) } T("BeforeOpen"), t.st.showCloseBtn && (t.st.closeBtnInside ? (x(p, function (e, t, n, i) { n.close_replaceWith = E(i.type) }), a += " mfp-close-btn-in") : t.wrap.append(E())), t.st.alignTop && (a += " mfp-align-top"), t.fixedContentPos ? t.wrap.css({ overflow: t.st.overflowY, overflowX: "hidden", overflowY: t.st.overflowY }) : t.wrap.css({ top: I.scrollTop(), position: "absolute" }), (t.st.fixedBgPos === !1 || "auto" === t.st.fixedBgPos && !t.fixedContentPos) && t.bgOverlay.css({ height: o.height(), position: "absolute" }), t.st.enableEscapeKey && o.on("keyup" + h, function (e) { 27 === e.keyCode && t.close() }), I.on("resize" + h, function () { t.updateSize() }), t.st.closeOnContentClick || (a += " mfp-auto-cursor"), a && t.wrap.addClass(a); var u = t.wH = I.height(), m = {}; if (t.fixedContentPos && t._hasScrollBar(u)) { var g = t._getScrollbarSize(); g && (m.marginRight = g) } t.fixedContentPos && (t.isIE7 ? e("body, html").css("overflow", "hidden") : m.overflow = "hidden"); var C = t.st.mainClass; return t.isIE7 && (C += " mfp-ie7"), C && t._addClassToMFP(C), t.updateItemHTML(), T("BuildControls"), e("html").css(m), t.bgOverlay.add(t.wrap).prependTo(t.st.prependTo || i), t._lastFocusedEl = document.activeElement, setTimeout(function () { t.content ? (t._addClassToMFP(v), t._setFocus()) : t.bgOverlay.addClass(v), o.on("focusin" + h, t._onFocusIn) }, 16), t.isOpen = !0, t.updateSize(u), T(f), n }, close: function () { t.isOpen && (T(c), t.isOpen = !1, t.st.removalDelay && !t.isLowIE && t.supportsTransition ? (t._addClassToMFP(C), setTimeout(function () { t._close() }, t.st.removalDelay)) : t._close()) }, _close: function () { T(l); var n = C + " " + v + " "; if (t.bgOverlay.detach(), t.wrap.detach(), t.container.empty(), t.st.mainClass && (n += t.st.mainClass + " "), t._removeClassFromMFP(n), t.fixedContentPos) { var i = {marginRight: ""}; t.isIE7 ? e("body, html").css("overflow", "") : i.overflow = "", e("html").css(i) } o.off("keyup" + h + " focusin" + h), t.ev.off(h), t.wrap.attr("class", "mfp-wrap").removeAttr("style"), t.bgOverlay.attr("class", "mfp-bg"), t.container.attr("class", "mfp-container"), !t.st.showCloseBtn || t.st.closeBtnInside && t.currTemplate[t.currItem.type] !== !0 || t.currTemplate.closeBtn && t.currTemplate.closeBtn.detach(), t._lastFocusedEl && e(t._lastFocusedEl).focus(), t.currItem = null, t.content = null, t.currTemplate = null, t.prevHeight = 0, T(d) }, updateSize: function (e) { if (t.isioses) { var n = document.documentElement.clientWidth / window.innerWidth, i = window.innerHeight * n; t.wrap.css("height", i), t.wH = i } else t.wH = e || I.height(); t.fixedContentPos || t.wrap.css("height", t.wH), T("Resize") }, updateItemHTML: function () { var n = t.items[t.index]; t.contentContainer.detach(), t.content && t.content.detach(), n.parsed || (n = t.parseEl(t.index)); var i = n.type; if (T("BeforeChange", [t.currItem ? t.currItem.type : "", i]), t.currItem = n, !t.currTemplate[i]) { var o = t.st[i] ? t.st[i].markup : !1; T("FirstMarkupParse", o), t.currTemplate[i] = o ? e(o) : !0 } r && r !== n.type && t.container.removeClass("mfp-" + r + "-holder"); var a = t["get" + i.charAt(0).toUpperCase() + i.slice(1)](n, t.currTemplate[i]); t.appendContent(a, i), n.preloaded = !0, T(m, n), r = n.type, t.container.prepend(t.contentContainer), T("AfterChange") }, appendContent: function (e, n) { t.content = e, e ? t.st.showCloseBtn && t.st.closeBtnInside && t.currTemplate[n] === !0 ? t.content.find(".mfp-close").length || t.content.append(E()) : t.content = e : t.content = "", T(u), t.container.addClass("mfp-" + n + "-holder"), t.contentContainer.append(t.content) }, parseEl: function (n) { var i, o = t.items[n]; if (o.tagName ? o = {el: e(o)} : (i = o.type, o = {data: o, src: o.src}), o.el) { for (var r = t.types, a = 0; r.length > a; a++)if (o.el.hasClass("mfp-" + r[a])) { i = r[a]; break } o.src = o.el.attr("data-mfp-src"), o.src || (o.src = o.el.attr("href")) } return o.type = i || t.st.type || "inline", o.index = n, o.parsed = !0, t.items[n] = o, T("ElementParse", o), t.items[n] }, addGroup: function (e, n) { var i = function (i) { i.mfpEl = this, t._openClick(i, e, n) }; n || (n = {}); var o = "click.magnificPopup"; n.mainEl = e, n.items ? (n.isObj = !0, e.off(o).on(o, i)) : (n.isObj = !1, n.delegate ? e.off(o).on(o, n.delegate, i) : (n.items = e, e.off(o).on(o, i))) }, _openClick: function (n, i, o) { var r = void 0 !== o.midClick ? o.midClick : e.magnificPopup.defaults.midClick; if (r || 2 !== n.which && !n.ctrlKey && !n.metaKey) { var a = void 0 !== o.disableOn ? o.disableOn : e.magnificPopup.defaults.disableOn; if (a)if (e.isFunction(a)) { if (!a.call(t))return !0 } else if (a > I.width())return !0; n.type && (n.preventDefault(), t.isOpen && n.stopPropagation()), o.el = e(n.mfpEl), o.delegate && (o.items = i.find(o.delegate)), t.open(o) } }, updateStatus: function (e, i) { if (t.preloader) { n !== e && t.container.removeClass("mfp-s-" + n), i || "loading" !== e || (i = t.st.tLoading); var o = {status: e, text: i}; T("UpdateStatus", o), e = o.status, i = o.text, t.preloader.html(i), t.preloader.find("a").on("click", function (e) { e.stopImmediatePropagation() }), t.container.addClass("mfp-s-" + e), n = e } }, _checkIfClose: function (n) { if (!e(n).hasClass(y)) { var i = t.st.closeOnContentClick, o = t.st.closeOnBgClick; if (i && o)return !0; if (!t.content || e(n).hasClass("mfp-close") || t.preloader && n === t.preloader[0])return !0; if (n === t.content[0] || e.contains(t.content[0], n)) { if (i)return !0 } else if (o && e.contains(document, n))return !0; return !1 } }, _addClassToMFP: function (e) { t.bgOverlay.addClass(e), t.wrap.addClass(e) }, _removeClassFromMFP: function (e) { this.bgOverlay.removeClass(e), t.wrap.removeClass(e) }, _hasScrollBar: function (e) { return (t.isIE7 ? o.height() : document.body.scrollHeight) > (e || I.height()) }, _setFocus: function () { (t.st.focus ? t.content.find(t.st.focus).eq(0) : t.wrap).focus() }, _onFocusIn: function (n) { return n.target === t.wrap[0] || e.contains(t.wrap[0], n.target) ? void 0 : (t._setFocus(), !1) }, _parseMarkup: function (t, n, i) { var o; i.data && (n = e.extend(i.data, n)), T(p, [t, n, i]), e.each(n, function (e, n) { if (void 0 === n || n === !1)return !0; if (o = e.split("_"), o.length > 1) { var i = t.find(h + "-" + o[0]); if (i.length > 0) { var r = o[1]; "replaceWith" === r ? i[0] !== n[0] && i.replaceWith(n) : "img" === r ? i.is("img") ? i.attr("src", n) : i.replaceWith('') : i.attr(o[1], n) } } else t.find(h + "-" + e).html(n) }) }, _getScrollbarSize: function () { if (void 0 === t.scrollbarSize) { var e = document.createElement("div"); e.id = "mfp-sbm", e.style.cssText = "width: 99px; height: 99px; overflow: scroll; position: absolute; top: -9999px;", document.body.appendChild(e), t.scrollbarSize = e.offsetWidth - e.clientWidth, document.body.removeChild(e) } return t.scrollbarSize } }, e.magnificPopup = { instance: null, proto: w.prototype, modules: [], open: function (t, n) { return _(), t = t ? e.extend(!0, {}, t) : {}, t.isObj = !0, t.index = n || 0, this.instance.open(t) }, close: function () { return e.magnificPopup.instance && e.magnificPopup.instance.close() }, registerModule: function (t, n) { n.options && (e.magnificPopup.defaults[t] = n.options), e.extend(this.proto, n.proto), this.modules.push(t) }, defaults: { disableOn: 0, key: null, midClick: !1, mainClass: "", preloader: !0, focus: "", closeOnContentClick: !1, closeOnBgClick: !0, closeBtnInside: !0, showCloseBtn: !0, enableEscapeKey: !0, modal: !1, alignTop: !1, removalDelay: 0, prependTo: null, fixedContentPos: "auto", fixedBgPos: "auto", overflowY: "auto", closeMarkup: '', tClose: "Close (Esc)", tLoading: "Loading..." } }, e.fn.magnificPopup = function (n) { _(); var i = e(this); if ("string" == typeof n)if ("open" === n) { var o, r = b ? i.data("magnificPopup") : i[0].magnificPopup, a = parseInt(arguments[1], 10) || 0; r.items ? o = r.items[a] : (o = i, r.delegate && (o = o.find(r.delegate)), o = o.eq(a)), t._openClick({mfpEl: o}, i, r) } else t.isOpen && t[n].apply(t, Array.prototype.slice.call(arguments, 1)); else n = e.extend(!0, {}, n), b ? i.data("magnificPopup", n) : i[0].magnificPopup = n, t.addGroup(i, n); return i }; var P, O, z, M = "inline", B = function () { z && (O.after(z.addClass(P)).detach(), z = null) }; e.magnificPopup.registerModule(M, { options: {hiddenClass: "hide", markup: "", tNotFound: "Content not found"}, proto: { initInline: function () { t.types.push(M), x(l + "." + M, function () { B() }) }, getInline: function (n, i) { if (B(), n.src) { var o = t.st.inline, r = e(n.src); if (r.length) { var a = r[0].parentNode; a && a.tagName && (O || (P = o.hiddenClass, O = k(P), P = "mfp-" + P), z = r.after(O).detach().removeClass(P)), t.updateStatus("ready") } else t.updateStatus("error", o.tNotFound), r = e("
"); return n.inlineElement = r, r } return t.updateStatus("ready"), t._parseMarkup(i, {}, n), i } } }); var F, H = "ajax", L = function () { F && i.removeClass(F) }, A = function () { L(), t.req && t.req.abort() }; e.magnificPopup.registerModule(H, { options: { settings: null, cursor: "mfp-ajax-cur", tError: 'The content could not be loaded.' }, proto: { initAjax: function () { t.types.push(H), F = t.st.ajax.cursor, x(l + "." + H, A), x("BeforeChange." + H, A) }, getAjax: function (n) { F && i.addClass(F), t.updateStatus("loading"); var o = e.extend({ url: n.src, success: function (i, o, r) { var a = {data: i, xhr: r}; T("ParseAjax", a), t.appendContent(e(a.data), H), n.finished = !0, L(), t._setFocus(), setTimeout(function () { t.wrap.addClass(v) }, 16), t.updateStatus("ready"), T("AjaxContentAdded") }, error: function () { L(), n.finished = n.loadError = !0, t.updateStatus("error", t.st.ajax.tError.replace("%url%", n.src)) } }, t.st.ajax.settings); return t.req = e.ajax(o), "" } } }); var j, N = function (n) { if (n.data && void 0 !== n.data.title)return n.data.title; var i = t.st.image.titleSrc; if (i) { if (e.isFunction(i))return i.call(t, n); if (n.el)return n.el.attr(i) || "" } return "" }; e.magnificPopup.registerModule("image", { options: { markup: '
', cursor: "mfp-zoom-out-cur", titleSrc: "title", verticalFit: !0, tError: 'The image could not be loaded.' }, proto: { initImage: function () { var e = t.st.image, n = ".image"; t.types.push("image"), x(f + n, function () { "image" === t.currItem.type && e.cursor && i.addClass(e.cursor) }), x(l + n, function () { e.cursor && i.removeClass(e.cursor), I.off("resize" + h) }), x("Resize" + n, t.resizeImage), t.isLowIE && x("AfterChange", t.resizeImage) }, resizeImage: function () { var e = t.currItem; if (e && e.img && t.st.image.verticalFit) { var n = 0; t.isLowIE && (n = parseInt(e.img.css("padding-top"), 10) + parseInt(e.img.css("padding-bottom"), 10)), e.img.css("max-height", t.wH - n) } }, _onImageHasSize: function (e) { e.img && (e.hasSize = !0, j && clearInterval(j), e.isCheckingImgSize = !1, T("ImageHasSize", e), e.imgHidden && (t.content && t.content.removeClass("mfp-loading"), e.imgHidden = !1)) }, findImageSize: function (e) { var n = 0, i = e.img[0], o = function (r) { j && clearInterval(j), j = setInterval(function () { return i.naturalWidth > 0 ? (t._onImageHasSize(e), void 0) : (n > 200 && clearInterval(j), n++, 3 === n ? o(10) : 40 === n ? o(50) : 100 === n && o(500), void 0) }, r) }; o(1) }, getImage: function (n, i) { var o = 0, r = function () { n && (n.img[0].complete ? (n.img.off(".mfploader"), n === t.currItem && (t._onImageHasSize(n), t.updateStatus("ready")), n.hasSize = !0, n.loaded = !0, T("ImageLoadComplete")) : (o++, 200 > o ? setTimeout(r, 100) : a())) }, a = function () { n && (n.img.off(".mfploader"), n === t.currItem && (t._onImageHasSize(n), t.updateStatus("error", s.tError.replace("%url%", n.src))), n.hasSize = !0, n.loaded = !0, n.loadError = !0) }, s = t.st.image, l = i.find(".mfp-img"); if (l.length) { var c = document.createElement("img"); c.className = "mfp-img", n.img = e(c).on("load.mfploader", r).on("error.mfploader", a), c.src = n.src, l.is("img") && (n.img = n.img.clone()), c = n.img[0], c.naturalWidth > 0 ? n.hasSize = !0 : c.width || (n.hasSize = !1) } return t._parseMarkup(i, { title: N(n), img_replaceWith: n.img }, n), t.resizeImage(), n.hasSize ? (j && clearInterval(j), n.loadError ? (i.addClass("mfp-loading"), t.updateStatus("error", s.tError.replace("%url%", n.src))) : (i.removeClass("mfp-loading"), t.updateStatus("ready")), i) : (t.updateStatus("loading"), n.loading = !0, n.hasSize || (n.imgHidden = !0, i.addClass("mfp-loading"), t.findImageSize(n)), i) } } }); var W, R = function () { return void 0 === W && (W = void 0 !== document.createElement("p").style.MozTransform), W }; e.magnificPopup.registerModule("zoom", { options: { enabled: !1, easing: "ease-in-out", duration: 300, opener: function (e) { return e.is("img") ? e : e.find("img") } }, proto: { initZoom: function () { var e, n = t.st.zoom, i = ".zoom"; if (n.enabled && t.supportsTransition) { var o, r, a = n.duration, s = function (e) { var t = e.clone().removeAttr("style").removeAttr("class").addClass("mfp-animated-image"), i = "all " + n.duration / 1e3 + "s " + n.easing, o = { position: "fixed", zIndex: 9999, left: 0, top: 0, "-webkit-backface-visibility": "hidden" }, r = "transition"; return o["-webkit-" + r] = o["-moz-" + r] = o["-o-" + r] = o[r] = i, t.css(o), t }, d = function () { t.content.css("visibility", "visible") }; x("BuildControls" + i, function () { if (t._allowZoom()) { if (clearTimeout(o), t.content.css("visibility", "hidden"), e = t._getItemToZoom(), !e)return d(), void 0; r = s(e), r.css(t._getOffset()), t.wrap.append(r), o = setTimeout(function () { r.css(t._getOffset(!0)), o = setTimeout(function () { d(), setTimeout(function () { r.remove(), e = r = null, T("ZoomAnimationEnded") }, 16) }, a) }, 16) } }), x(c + i, function () { if (t._allowZoom()) { if (clearTimeout(o), t.st.removalDelay = a, !e) { if (e = t._getItemToZoom(), !e)return; r = s(e) } r.css(t._getOffset(!0)), t.wrap.append(r), t.content.css("visibility", "hidden"), setTimeout(function () { r.css(t._getOffset()) }, 16) } }), x(l + i, function () { t._allowZoom() && (d(), r && r.remove(), e = null) }) } }, _allowZoom: function () { return "image" === t.currItem.type }, _getItemToZoom: function () { return t.currItem.hasSize ? t.currItem.img : !1 }, _getOffset: function (n) { var i; i = n ? t.currItem.img : t.st.zoom.opener(t.currItem.el || t.currItem); var o = i.offset(), r = parseInt(i.css("padding-top"), 10), a = parseInt(i.css("padding-bottom"), 10); o.top -= e(window).scrollTop() - r; var s = {width: i.width(), height: (b ? i.innerHeight() : i[0].offsetHeight) - a - r}; return R() ? s["-moz-transform"] = s.transform = "translate(" + o.left + "px," + o.top + "px)" : (s.left = o.left, s.top = o.top), s } } }); var Z = "iframe", q = "http://about:blank", D = function (e) { if (t.currTemplate[Z]) { var n = t.currTemplate[Z].find("iframe"); n.length && (e || (n[0].src = q), t.isIE8 && n.css("display", e ? "block" : "none")) } }; e.magnificPopup.registerModule(Z, { options: { markup: '
', srcAction: "iframe_src", patterns: { youtube: {index: "youtube.com", id: "v=", src: "http://www.youtube.com/embed/%id%?autoplay=1"}, vimeo: {index: "vimeo.com/", id: "/", src: "http://player.vimeo.com/video/%id%?autoplay=1"}, gmaps: {index: "http://maps.google.", src: "%id%&output=embed"} } }, proto: { initIframe: function () { t.types.push(Z), x("BeforeChange", function (e, t, n) { t !== n && (t === Z ? D() : n === Z && D(!0)) }), x(l + "." + Z, function () { D() }) }, getIframe: function (n, i) { var o = n.src, r = t.st.iframe; e.each(r.patterns, function () { return o.indexOf(this.index) > -1 ? (this.id && (o = "string" == typeof this.id ? o.substr(o.lastIndexOf(this.id) + this.id.length, o.length) : this.id.call(this, o)), o = this.src.replace("%id%", o), !1) : void 0 }); var a = {}; return r.srcAction && (a[r.srcAction] = o), t._parseMarkup(i, a, n), t.updateStatus("ready"), i } } }); var K = function (e) { var n = t.items.length; return e > n - 1 ? e - n : 0 > e ? n + e : e }, Y = function (e, t, n) { return e.replace(/%curr%/gi, t + 1).replace(/%total%/gi, n) }; e.magnificPopup.registerModule("gallery", { options: { enabled: !1, arrowMarkup: '', preload: [0, 2], navigateByImgClick: !0, arrows: !0, tPrev: "Previous (Left arrow key)", tNext: "Next (Right arrow key)", tCounter: "%curr% of %total%" }, proto: { initGallery: function () { var n = t.st.gallery, i = ".mfp-gallery", r = Boolean(e.fn.mfpFastClick); return t.direction = !0, n && n.enabled ? (a += " mfp-gallery", x(f + i, function () { n.navigateByImgClick && t.wrap.on("click" + i, ".mfp-img", function () { return t.items.length > 1 ? (t.next(), !1) : void 0 }), o.on("keydown" + i, function (e) { 37 === e.keyCode ? t.prev() : 39 === e.keyCode && t.next() }) }), x("UpdateStatus" + i, function (e, n) { n.text && (n.text = Y(n.text, t.currItem.index, t.items.length)) }), x(p + i, function (e, i, o, r) { var a = t.items.length; o.counter = a > 1 ? Y(n.tCounter, r.index, a) : "" }), x("BuildControls" + i, function () { if (t.items.length > 1 && n.arrows && !t.arrowLeft) { var i = n.arrowMarkup, o = t.arrowLeft = e(i.replace(/%title%/gi, n.tPrev).replace(/%dir%/gi, "left")).addClass(y), a = t.arrowRight = e(i.replace(/%title%/gi, n.tNext).replace(/%dir%/gi, "right")).addClass(y), s = r ? "mfpFastClick" : "click"; o[s](function () { t.prev() }), a[s](function () { t.next() }), t.isIE7 && (k("b", o[0], !1, !0), k("a", o[0], !1, !0), k("b", a[0], !1, !0), k("a", a[0], !1, !0)), t.container.append(o.add(a)) } }), x(m + i, function () { t._preloadTimeout && clearTimeout(t._preloadTimeout), t._preloadTimeout = setTimeout(function () { t.preloadNearbyImages(), t._preloadTimeout = null }, 16) }), x(l + i, function () { o.off(i), t.wrap.off("click" + i), t.arrowLeft && r && t.arrowLeft.add(t.arrowRight).destroyMfpFastClick(), t.arrowRight = t.arrowLeft = null }), void 0) : !1 }, next: function () { t.direction = !0, t.index = K(t.index + 1), t.updateItemHTML() }, prev: function () { t.direction = !1, t.index = K(t.index - 1), t.updateItemHTML() }, goTo: function (e) { t.direction = e >= t.index, t.index = e, t.updateItemHTML() }, preloadNearbyImages: function () { var e, n = t.st.gallery.preload, i = Math.min(n[0], t.items.length), o = Math.min(n[1], t.items.length); for (e = 1; (t.direction ? o : i) >= e; e++)t._preloadItem(t.index + e); for (e = 1; (t.direction ? i : o) >= e; e++)t._preloadItem(t.index - e) }, _preloadItem: function (n) { if (n = K(n), !t.items[n].preloaded) { var i = t.items[n]; i.parsed || (i = t.parseEl(n)), T("LazyLoad", i), "image" === i.type && (i.img = e('').on("load.mfploader", function () { i.hasSize = !0 }).on("error.mfploader", function () { i.hasSize = !0, i.loadError = !0, T("LazyLoadError", i) }).attr("src", i.src)), i.preloaded = !0 } } } }); var U = "retina"; e.magnificPopup.registerModule(U, { options: { replaceSrc: function (e) { return e.src.replace(/\.\w+$/, function (e) { return "@2x" + e }) }, ratio: 1 }, proto: { initRetina: function () { if (window.devicePixelRatio > 1) { var e = t.st.retina, n = e.ratio; n = isNaN(n) ? n() : n, n > 1 && (x("ImageHasSize." + U, function (e, t) { t.img.css({"max-width": t.img[0].naturalWidth / n, width: "100%"}) }), x("ElementParse." + U, function (t, i) { i.src = e.replaceSrc(i, n) })) } } } }), function () { var t = 1e3, n = "ontouchstart"in window, i = function () { I.off("touchmove" + r + " touchend" + r) }, o = "mfpFastClick", r = "." + o; e.fn.mfpFastClick = function (o) { return e(this).each(function () { var a, s = e(this); if (n) { var l, c, d, u, p, f; s.on("touchstart" + r, function (e) { u = !1, f = 1, p = e.originalEvent ? e.originalEvent.touches[0] : e.touches[0], c = p.clientX, d = p.clientY, I.on("touchmove" + r, function (e) { p = e.originalEvent ? e.originalEvent.touches : e.touches, f = p.length, p = p[0], (Math.abs(p.clientX - c) > 10 || Math.abs(p.clientY - d) > 10) && (u = !0, i()) }).on("touchend" + r, function (e) { i(), u || f > 1 || (a = !0, e.preventDefault(), clearTimeout(l), l = setTimeout(function () { a = !1 }, t), o()) }) }) } s.on("click" + r, function () { a || o() }) }) }, e.fn.destroyMfpFastClick = function () { e(this).off("touchstart" + r + " click" + r), n && I.off("touchmove" + r + " touchend" + r) } }(), _() })(window.jQuery || window.Zepto);;(function(window, document, $) {var isOperaMini = Object.prototype.toString.call(window.operamini) == '[object OperaMini]'; var isInputSupported = 'placeholder' in document.createElement('input') && !isOperaMini; var isTextareaSupported = 'placeholder' in document.createElement('textarea') && !isOperaMini; var prototype = $.fn; var valHooks = $.valHooks; var propHooks = $.propHooks; var hooks; var placeholder;if (isInputSupported && isTextareaSupported) {placeholder = prototype.placeholder = function() { return this; };placeholder.input = placeholder.textarea = true;} else {placeholder = prototype.placeholder = function() { var $this = this; $this .filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]') .not('.placeholder') .bind({ 'focus.placeholder': clearPlaceholder, 'blur.placeholder': setPlaceholder }) .data('placeholder-enabled', true) .trigger('blur.placeholder'); return $this; };placeholder.input = isInputSupported; placeholder.textarea = isTextareaSupported;hooks = { 'get': function(element) { var $element = $(element);var $passwordInput = $element.data('placeholder-password'); if ($passwordInput) { return $passwordInput[0].value; }return $element.data('placeholder-enabled') && $element.hasClass('placeholder') ? '' : element.value; }, 'set': function(element, value) { var $element = $(element);var $passwordInput = $element.data('placeholder-password'); if ($passwordInput) { return $passwordInput[0].value = value; }if (!$element.data('placeholder-enabled')) { return element.value = value; } if (value == '') { element.value = value; // Issue #56: Setting the placeholder causes problems if the element continues to have focus. if (element != safeActiveElement()) { // We can't use `triggerHandler` here because of dummy text/password inputs :( setPlaceholder.call(element); } } else if ($element.hasClass('placeholder')) { clearPlaceholder.call(element, true, value) || (element.value = value); } else { element.value = value; } // `set` can not return `undefined`; see http://jsapi.info/jquery/1.7.1/val#L2363 return $element; } };if (!isInputSupported) { valHooks.input = hooks; propHooks.value = hooks; } if (!isTextareaSupported) { valHooks.textarea = hooks; propHooks.value = hooks; }$(function() { // Look for forms $(document).delegate('form', 'submit.placeholder', function() { // Clear the placeholder values so they don't get submitted var $inputs = $('.placeholder', this).each(clearPlaceholder); setTimeout(function() { $inputs.each(setPlaceholder); }, 10); }); });// Clear placeholder values upon page reload $(window).bind('beforeunload.placeholder', function() { $('.placeholder').each(function() { this.value = ''; }); });}function args(elem) { // Return an object of element attributes var newAttrs = {}; var rinlinejQuery = /^jQuery\d+$/; $.each(elem.attributes, function(i, attr) { if (attr.specified && !rinlinejQuery.test(attr.name)) { newAttrs[attr.name] = attr.value; } }); return newAttrs; }function clearPlaceholder(event, value) { var input = this; var $input = $(input); if (input.value == $input.attr('placeholder') && $input.hasClass('placeholder')) { if ($input.data('placeholder-password')) { $input = $input.hide().next().show().attr('id', $input.removeAttr('id').data('placeholder-id')); // If `clearPlaceholder` was called from `$.valHooks.input.set` if (event === true) { return $input[0].value = value; } $input.focus(); } else { input.value = ''; $input.removeClass('placeholder'); input == safeActiveElement() && input.select(); } } }function setPlaceholder() { var $replacement; var input = this; var $input = $(input); var id = this.id; if (input.value == '') { if (input.type == 'password') { if (!$input.data('placeholder-textinput')) { try { $replacement = $input.clone().attr({ 'type': 'text' }); } catch(e) { $replacement = $('').attr($.extend(args(this), { 'type': 'text' })); } $replacement .removeAttr('name') .data({ 'placeholder-password': $input, 'placeholder-id': id }) .bind('focus.placeholder', clearPlaceholder); $input .data({ 'placeholder-textinput': $replacement, 'placeholder-id': id }) .before($replacement); } $input = $input.removeAttr('id').hide().prev().attr('id', id).show(); // Note: `$input[0] != input` now! } $input.addClass('placeholder'); $input[0].value = $input.attr('placeholder'); } else { $input.removeClass('placeholder'); } }function safeActiveElement() { // Avoid IE9 `document.activeElement` of death // https://github.com/mathiasbynens/jquery-placeholder/pull/99 try { return document.activeElement; } catch (err) {} }}(this, document, jQuery));(function() { (function(factory) { if (typeof define === 'function' && define.amd) { return define(['jquery'], factory); } else { return factory(window.jQuery); } })(function($) { "use strict"; var EditableCaret, InputCaret, Mirror, Utils, methods, oDocument, oFrame, oWindow, pluginName; pluginName = 'caret'; EditableCaret = (function() { function EditableCaret($inputor) { this.$inputor = $inputor; this.domInputor = this.$inputor[0]; } EditableCaret.prototype.setPos = function(pos) { return this.domInputor; }; EditableCaret.prototype.getIEPosition = function() { return $.noop(); }; EditableCaret.prototype.getPosition = function() { return $.noop(); }; EditableCaret.prototype.getOldIEPos = function() { var preCaretTextRange, textRange; textRange = oDocument.selection.createRange(); preCaretTextRange = oDocument.body.createTextRange(); preCaretTextRange.moveToElementText(this.domInputor); preCaretTextRange.setEndPoint("EndToEnd", textRange); return preCaretTextRange.text.length; }; EditableCaret.prototype.getPos = function() { var clonedRange, pos, range; if (range = this.range()) { clonedRange = range.cloneRange(); clonedRange.selectNodeContents(this.domInputor); clonedRange.setEnd(range.endContainer, range.endOffset); pos = clonedRange.toString().length; clonedRange.detach(); return pos; } else if (oDocument.selection) { return this.getOldIEPos(); } }; EditableCaret.prototype.getOldIEOffset = function() { var range, rect; range = oDocument.selection.createRange().duplicate(); range.moveStart("character", -1); rect = range.getBoundingClientRect(); return { height: rect.bottom - rect.top, left: rect.left, top: rect.top }; }; EditableCaret.prototype.getOffset = function(pos) { var clonedRange, offset, range, rect; if (oWindow.getSelection && (range = this.range())) { if (range.endOffset - 1 < 0) { return null; } clonedRange = range.cloneRange(); clonedRange.setStart(range.endContainer, range.endOffset - 1); clonedRange.setEnd(range.endContainer, range.endOffset); rect = clonedRange.getBoundingClientRect(); offset = { height: rect.height, left: rect.left + rect.width, top: rect.top }; clonedRange.detach(); } else if (oDocument.selection) { offset = this.getOldIEOffset(); } if (offset && !oFrame) { offset.top += $(oWindow).scrollTop(); offset.left += $(oWindow).scrollLeft(); } return offset; }; EditableCaret.prototype.range = function() { var sel; if (!oWindow.getSelection) { return; } sel = oWindow.getSelection(); if (sel.rangeCount > 0) { return sel.getRangeAt(0); } else { return null; } }; return EditableCaret; })(); InputCaret = (function() { function InputCaret($inputor) { this.$inputor = $inputor; this.domInputor = this.$inputor[0]; } InputCaret.prototype.getIEPos = function() { var endRange, inputor, len, normalizedValue, pos, range, textInputRange; inputor = this.domInputor; range = oDocument.selection.createRange(); pos = 0; if (range && range.parentElement() === inputor) { normalizedValue = inputor.value.replace(/\r\n/g, "\n"); len = normalizedValue.length; textInputRange = inputor.createTextRange(); textInputRange.moveToBookmark(range.getBookmark()); endRange = inputor.createTextRange(); endRange.collapse(false); if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) { pos = len; } else { pos = -textInputRange.moveStart("character", -len); } } return pos; }; InputCaret.prototype.getPos = function() { if (oDocument.selection) { return this.getIEPos(); } else { return this.domInputor.selectionStart; } }; InputCaret.prototype.setPos = function(pos) { var inputor, range; inputor = this.domInputor; if (oDocument.selection) { range = inputor.createTextRange(); range.move("character", pos); range.select(); } else if (inputor.setSelectionRange) { inputor.setSelectionRange(pos, pos); } return inputor; }; InputCaret.prototype.getIEOffset = function(pos) { var h, textRange, x, y; textRange = this.domInputor.createTextRange(); pos || (pos = this.getPos()); textRange.move('character', pos); x = textRange.boundingLeft; y = textRange.boundingTop; h = textRange.boundingHeight; return { left: x, top: y, height: h }; }; InputCaret.prototype.getOffset = function(pos) { var $inputor, offset, position; $inputor = this.$inputor; if (oDocument.selection) { offset = this.getIEOffset(pos); offset.top += $(oWindow).scrollTop() + $inputor.scrollTop(); offset.left += $(oWindow).scrollLeft() + $inputor.scrollLeft(); return offset; } else { offset = $inputor.offset(); position = this.getPosition(pos); return offset = { left: offset.left + position.left - $inputor.scrollLeft(), top: offset.top + position.top - $inputor.scrollTop(), height: position.height }; } }; InputCaret.prototype.getPosition = function(pos) { var $inputor, at_rect, format, html, mirror, start_range; $inputor = this.$inputor; format = function(value) { return value.replace(//g, '>').replace(/`/g, '`').replace(/"/g, '"').replace(/\r\n|\r|\n/g, "
"); }; if (pos === void 0) { pos = this.getPos(); } start_range = $inputor.val().slice(0, pos); html = "" + format(start_range) + ""; html += "|"; mirror = new Mirror($inputor); return at_rect = mirror.create(html).rect(); }; InputCaret.prototype.getIEPosition = function(pos) { var h, inputorOffset, offset, x, y; offset = this.getIEOffset(pos); inputorOffset = this.$inputor.offset(); x = offset.left - inputorOffset.left; y = offset.top - inputorOffset.top; h = offset.height; return { left: x, top: y, height: h }; }; return InputCaret; })(); Mirror = (function() { Mirror.prototype.css_attr = ["overflowY", "height", "width", "paddingTop", "paddingLeft", "paddingRight", "paddingBottom", "marginTop", "marginLeft", "marginRight", "marginBottom", "fontFamily", "borderStyle", "borderWidth", "wordWrap", "fontSize", "lineHeight", "overflowX", "text-align"]; function Mirror($inputor) { this.$inputor = $inputor; } Mirror.prototype.mirrorCss = function() { var css, _this = this; css = { position: 'absolute', left: -9999, top: 0, zIndex: -20000, 'white-space': 'pre-wrap' }; $.each(this.css_attr, function(i, p) { return css[p] = _this.$inputor.css(p); }); return css; }; Mirror.prototype.create = function(html) { this.$mirror = $('
'); this.$mirror.css(this.mirrorCss()); this.$mirror.html(html); this.$inputor.after(this.$mirror); return this; }; Mirror.prototype.rect = function() { var $flag, pos, rect; $flag = this.$mirror.find("#caret"); pos = $flag.position(); rect = { left: pos.left, top: pos.top, height: $flag.height() }; this.$mirror.remove(); return rect; }; return Mirror; })(); Utils = { contentEditable: function($inputor) { return !!($inputor[0].contentEditable && $inputor[0].contentEditable === 'true'); } }; methods = { pos: function(pos) { if (pos) { return this.setPos(pos); } else { return this.getPos(); } }, position: function(pos) { if (oDocument.selection) { return this.getIEPosition(pos); } else { return this.getPosition(pos); } }, offset: function(pos) { var iOffset, offset; offset = this.getOffset(pos); if (oFrame) { iOffset = $(oFrame).offset(); offset.top += iOffset.top; offset.left += iOffset.left; } return offset; } }; oDocument = null; oWindow = null; oFrame = null; $.fn.caret = function(method) { var caret; oDocument = this[0].ownerDocument; oWindow = oDocument.defaultView || oDocument.parentWindow; oFrame = oWindow.frameElement; caret = Utils.contentEditable(this) ? new EditableCaret(this) : new InputCaret(this); if (methods[method]) { return methods[method].apply(caret, Array.prototype.slice.call(arguments, 1)); } else { return $.error("Method " + method + " does not exist on jQuery.caret"); } }; $.fn.caret.EditableCaret = EditableCaret; $.fn.caret.InputCaret = InputCaret; $.fn.caret.Utils = Utils; return $.fn.caret.apis = methods; });}).call(this);(function() { var __slice = [].slice; (function(factory) { if (typeof define === 'function' && define.amd) { return define(['jquery'], factory); } else { return factory(window.jQuery); } })(function($) { var $CONTAINER, Api, App, Atwho, Controller, DEFAULT_CALLBACKS, KEY_CODE, Model, View; App = (function() { function App(inputor) { this.current_flag = null; this.controllers = {}; this.alias_maps = {}; this.$inputor = $(inputor); this.listen(); } App.prototype.controller = function(at) { return this.controllers[this.alias_maps[at] || at || this.current_flag]; }; App.prototype.set_context_for = function(at) { this.current_flag = at; return this; }; App.prototype.reg = function(flag, setting) { var controller, _base; controller = (_base = this.controllers)[flag] || (_base[flag] = new Controller(this, flag)); if (setting.alias) { this.alias_maps[setting.alias] = flag; } controller.init(setting); return this; }; App.prototype.listen = function() { var _this = this; return this.$inputor.on('keyup.atwho', function(e) { return _this.on_keyup(e); }).on('keydown.atwho', function(e) { return _this.on_keydown(e); }).on('scroll.atwho', function(e) { var _ref; return (_ref = _this.controller()) != null ? _ref.view.hide() : void 0; }).on('blur.atwho', function(e) { var c; if (c = _this.controller()) { return c.view.hide(c.get_opt("display_timeout")); } }); }; App.prototype.dispatch = function() { var _this = this; return $.map(this.controllers, function(c) { if (c.look_up()) { return _this.set_context_for(c.at); } }); }; App.prototype.on_keyup = function(e) { var _ref; switch (e.keyCode) { case KEY_CODE.ESC: e.preventDefault(); if ((_ref = this.controller()) != null) { _ref.view.hide(); } break; case KEY_CODE.DOWN: case KEY_CODE.UP: $.noop(); break; default: this.dispatch(); } }; App.prototype.on_keydown = function(e) { var view, _ref; view = (_ref = this.controller()) != null ? _ref.view : void 0; if (!(view && view.visible())) { return; } switch (e.keyCode) { case KEY_CODE.ESC: e.preventDefault(); view.hide(); break; case KEY_CODE.UP: e.preventDefault(); view.prev(); break; case KEY_CODE.DOWN: e.preventDefault(); view.next(); break; case KEY_CODE.TAB: case KEY_CODE.ENTER: if (!view.visible()) { return; } e.preventDefault(); view.choose(); break; default: $.noop(); } }; return App; })(); Controller = (function() { var uuid, _uuid; _uuid = 0; uuid = function() { return _uuid += 1; }; function Controller(app, at) { this.app = app; this.at = at; this.$inputor = this.app.$inputor; this.oDocument = this.$inputor[0].ownerDocument; this.oWindow = this.oDocument.defaultView || this.oDocument.parentWindow; this.id = this.$inputor[0].id || uuid(); this.setting = null; this.query = null; this.pos = 0; this.cur_rect = null; this.range = null; $CONTAINER.append(this.$el = $("
")); this.model = new Model(this); this.view = new View(this); } Controller.prototype.init = function(setting) { this.setting = $.extend({}, this.setting || $.fn.atwho["default"], setting); this.view.init(); return this.model.reload(this.setting.data); }; Controller.prototype.call_default = function() { var args, func_name; func_name = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; try { return DEFAULT_CALLBACKS[func_name].apply(this, args); } catch (error) { return $.error("" + error + " Or maybe At.js doesn't have function " + func_name); } }; Controller.prototype.trigger = function(name, data) { var alias, event_name; data.push(this); alias = this.get_opt('alias'); event_name = alias ? "" + name + "-" + alias + ".atwho" : "" + name + ".atwho"; return this.$inputor.trigger(event_name, data); }; Controller.prototype.callbacks = function(func_name) { return this.get_opt("callbacks")[func_name] || DEFAULT_CALLBACKS[func_name]; }; Controller.prototype.get_opt = function(at, default_value) { try { return this.setting[at]; } catch (e) { return null; } }; Controller.prototype.content = function() { if (this.$inputor.is('textarea, input')) { return this.$inputor.val(); } else { return this.$inputor.text(); } }; Controller.prototype.catch_query = function() { var caret_pos, content, end, query, start, subtext; content = this.content(); caret_pos = this.$inputor.caret('pos'); subtext = content.slice(0, caret_pos); query = this.callbacks("matcher").call(this, this.at, subtext, this.get_opt('start_with_space')); if (typeof query === "string" && query.length <= this.get_opt('max_len', 20)) { start = caret_pos - query.length; end = start + query.length; this.pos = start; query = { 'text': query.toLowerCase(), 'head_pos': start, 'end_pos': end }; this.trigger("matched", [this.at, query.text]); } else { this.view.hide(); } return this.query = query; }; Controller.prototype.rect = function() { var c, scale_bottom; if (!(c = this.$inputor.caret('offset', this.pos - 1))) { return; } if (this.$inputor.attr('contentEditable') === 'true') { c = (this.cur_rect || (this.cur_rect = c)) || c; } scale_bottom = document.selection ? 0 : 2; return { left: c.left, top: c.top, bottom: c.top + c.height + scale_bottom }; }; Controller.prototype.reset_rect = function() { if (this.$inputor.attr('contentEditable') === 'true') { return this.cur_rect = null; } }; Controller.prototype.mark_range = function() { if (this.$inputor.attr('contentEditable') === 'true') { this.range = this.get_range(); return this.ie_range = this.get_ie_range(); } }; Controller.prototype.clear_range = function() { return this.range = null; }; Controller.prototype.get_range = function() { return this.range || (this.oWindow.getSelection ? this.oWindow.getSelection().getRangeAt(0) : void 0); }; Controller.prototype.get_ie_range = function() { return this.ie_range || (this.oDocument.selection ? this.oDocument.selection.createRange() : void 0); }; Controller.prototype.insert_content_for = function($li) { var data, data_value, tpl; data_value = $li.data('value'); tpl = this.get_opt('insert_tpl'); if (this.$inputor.is('textarea, input') || !tpl) { return data_value; } data = $.extend({}, $li.data('item-data'), { 'atwho-data-value': data_value, 'atwho-at': this.at }); return this.callbacks("tpl_evals").call(this, tpl, data); }; Controller.prototype.insert = function(content, $li) { var $inputor, $insert_node, class_name, content_node, insert_node, pos, range, sel, source, start_str, text; $inputor = this.$inputor; if ($inputor.attr('contentEditable') === 'true') { class_name = "atwho-view-flag atwho-view-flag-" + (this.get_opt('alias') || this.at); content_node = "" + content + " "; insert_node = "" + content_node + ""; $insert_node = $(insert_node, this.oDocument).data('atwho-data-item', $li.data('item-data')); if (this.oDocument.selection) { $insert_node = $("", this.oDocument).html($insert_node); } } if ($inputor.is('textarea, input')) { content = '' + content; source = $inputor.val(); start_str = source.slice(0, Math.max(this.query.head_pos - this.at.length, 0)); text = "" + start_str + content + " " + (source.slice(this.query['end_pos'] || 0)); $inputor.val(text); $inputor.caret('pos', start_str.length + content.length + 1); } else if (range = this.get_range()) { pos = range.startOffset - (this.query.end_pos - this.query.head_pos) - this.at.length; range.setStart(range.endContainer, Math.max(pos, 0)); range.setEnd(range.endContainer, range.endOffset); range.deleteContents(); range.insertNode($insert_node[0]); range.collapse(false); sel = this.oWindow.getSelection(); sel.removeAllRanges(); sel.addRange(range); } else if (range = this.get_ie_range()) { range.moveStart('character', this.query.end_pos - this.query.head_pos - this.at.length); range.pasteHTML(content_node); range.collapse(false); range.select(); } $inputor.focus(); return $inputor.change(); }; Controller.prototype.render_view = function(data) { var search_key; search_key = this.get_opt("search_key"); data = this.callbacks("sorter").call(this, this.query.text, data.slice(0, 1001), search_key); return this.view.render(data.slice(0, this.get_opt('limit'))); }; Controller.prototype.look_up = function() { var query, _callback; if (!(query = this.catch_query())) { return; } _callback = function(data) { if (data && data.length > 0) { return this.render_view(data); } else { return this.view.hide(); } }; this.model.query(query.text, $.proxy(_callback, this)); return query; }; return Controller; })(); Model = (function() { function Model(context) { this.context = context; this.at = this.context.at; this.storage = this.context.$inputor; } Model.prototype.saved = function() { return this.fetch() > 0; }; Model.prototype.query = function(query, callback) { var data, search_key, _remote_filter; data = this.fetch(); search_key = this.context.get_opt("search_key"); data = this.context.callbacks('filter').call(this.context, query, data, search_key) || []; _remote_filter = this.context.callbacks('remote_filter'); if (data.length > 0 || (!_remote_filter && data.length === 0)) { return callback(data); } else { return _remote_filter.call(this.context, query, callback); } }; Model.prototype.fetch = function() { return this.storage.data(this.at) || []; }; Model.prototype.save = function(data) { return this.storage.data(this.at, this.context.callbacks("before_save").call(this.context, data || [])); }; Model.prototype.load = function(data) { if (!(this.saved() || !data)) { return this._load(data); } }; Model.prototype.reload = function(data) { return this._load(data); }; Model.prototype._load = function(data) { var _this = this; if (typeof data === "string") { return $.ajax(data, { dataType: "json" }).done(function(data) { return _this.save(data); }); } else { return this.save(data); } }; return Model; })(); View = (function() { function View(context) { this.context = context; this.$el = $("
    "); this.timeout_id = null; this.context.$el.append(this.$el); this.bind_event(); } View.prototype.init = function() { var id; id = this.context.get_opt("alias") || this.context.at.charCodeAt(0); return this.$el.attr({ 'id': "at-view-" + id }); }; View.prototype.bind_event = function() { var $menu, _this = this; $menu = this.$el.find('ul'); $menu.on('mouseenter.atwho-view', 'li', function(e) { $menu.find('.cur').removeClass('cur'); return $(e.currentTarget).addClass('cur'); }).on('click', function(e) { _this.choose(); return e.preventDefault(); }); return this.$el.on('mouseenter.atwho-view', 'ul', function(e) { return _this.context.mark_range(); }).on('mouseleave.atwho-view', 'ul', function(e) { return _this.context.clear_range(); }); }; View.prototype.visible = function() { return this.$el.is(":visible"); }; View.prototype.choose = function() { var $li, content; $li = this.$el.find(".cur"); content = this.context.insert_content_for($li); this.context.insert(this.context.callbacks("before_insert").call(this.context, content, $li), $li); this.context.trigger("inserted", [$li]); return this.hide(); }; View.prototype.reposition = function(rect) { var offset; if (rect.bottom + this.$el.height() - $(window).scrollTop() > $(window).height()) { rect.bottom = rect.top - this.$el.height(); } offset = { left: rect.left, top: rect.bottom }; this.$el.offset(offset); return this.context.trigger("reposition", [offset]); }; View.prototype.next = function() { var cur, next; cur = this.$el.find('.cur').removeClass('cur'); next = cur.next(); if (!next.length) { next = this.$el.find('li:first'); } return next.addClass('cur'); }; View.prototype.prev = function() { var cur, prev; cur = this.$el.find('.cur').removeClass('cur'); prev = cur.prev(); if (!prev.length) { prev = this.$el.find('li:last'); } return prev.addClass('cur'); }; View.prototype.show = function() { var rect; if (!this.visible()) { this.$el.show(); } if (rect = this.context.rect()) { return this.reposition(rect); } }; View.prototype.hide = function(time) { var callback, _this = this; if (isNaN(time && this.visible())) { this.context.reset_rect(); return this.$el.hide(); } else { callback = function() { return _this.hide(); }; clearTimeout(this.timeout_id); return this.timeout_id = setTimeout(callback, time); } }; View.prototype.render = function(list) { var $li, $ul, item, li, tpl, _i, _len; if (!($.isArray(list) && list.length > 0)) { this.hide(); return; } this.$el.find('ul').empty(); $ul = this.$el.find('ul'); tpl = this.context.get_opt('tpl'); for (_i = 0, _len = list.length; _i < _len; _i++) { item = list[_i]; item = $.extend({}, item, { 'atwho-at': this.context.at }); li = this.context.callbacks("tpl_evals").call(this.context, tpl, item); $li = $(this.context.callbacks("highlighter").call(this.context, li, this.context.query.text)); $li.data("item-data", item); $ul.append($li); } this.show(); return $ul.find("li:first").addClass("cur"); }; return View; })(); KEY_CODE = { DOWN: 40, UP: 38, ESC: 27, TAB: 9, ENTER: 13 }; DEFAULT_CALLBACKS = { before_save: function(data) { var item, _i, _len, _results; if (!$.isArray(data)) { return data; } _results = []; for (_i = 0, _len = data.length; _i < _len; _i++) { item = data[_i]; if ($.isPlainObject(item)) { _results.push(item); } else { _results.push({ name: item }); } } return _results; }, matcher: function(flag, subtext, should_start_with_space) { var match, regexp; flag = flag.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); if (should_start_with_space) { flag = '(?:^|\\s)' + flag; } regexp = new RegExp(flag + '([A-Za-z0-9_\+\-]*)$|' + flag + '([^\\x00-\\xff]*)$', 'gi'); match = regexp.exec(subtext); if (match) { return match[2] || match[1]; } else { return null; } }, filter: function(query, data, search_key) { var item, _i, _len, _results; _results = []; for (_i = 0, _len = data.length; _i < _len; _i++) { item = data[_i]; if (~item[search_key].toLowerCase().indexOf(query)) { _results.push(item); } } return _results; }, remote_filter: null, sorter: function(query, items, search_key) { var item, _i, _len, _results; if (!query) { return items; } _results = []; for (_i = 0, _len = items.length; _i < _len; _i++) { item = items[_i]; item.atwho_order = item[search_key].toLowerCase().indexOf(query); if (item.atwho_order > -1) { _results.push(item); } } return _results.sort(function(a, b) { return a.atwho_order - b.atwho_order; }); }, tpl_evals: function(tpl, map) { try { return tpl.replace(/\$\{([^\}]*)\}/g, function(tag, key, pos) { return map[key]; }); } catch (error) { return ""; } }, highlighter: function(li, query) { var regexp; if (!query) { return li; } regexp = new RegExp(">\\s*(\\w*)(" + query.replace("+", "\\+") + ")(\\w*)\\s*<", 'ig'); return li.replace(regexp, function(str, $1, $2, $3) { return '> ' + $1 + '' + $2 + '' + $3 + ' <'; }); }, before_insert: function(value, $li) { return value; } }; Api = { load: function(at, data) { var c; if (c = this.controller(at)) { return c.model.load(data); } }, getInsertedItemsWithIDs: function(at) { var c, ids, items; if (!(c = this.controller(at))) { return [null, null]; } if (at) { at = "-" + (c.get_opt('alias') || c.at); } ids = []; items = $.map(this.$inputor.find("span.atwho-view-flag" + (at || "")), function(item) { var data; data = $(item).data('atwho-data-item'); if (ids.indexOf(data.id) > -1) { return; } if (data.id) { ids.push = data.id; } return data; }); return [ids, items]; }, getInsertedItems: function(at) { return Api.getInsertedItemsWithIDs.apply(this, [at])[1]; }, getInsertedIDs: function(at) { return Api.getInsertedItemsWithIDs.apply(this, [at])[0]; }, run: function() { return this.dispatch(); } }; Atwho = { init: function(options) { var $this, app; app = ($this = $(this)).data("atwho"); if (!app) { $this.data('atwho', (app = new App(this))); } app.reg(options.at, options); return this; } }; $CONTAINER = $("
    "); $.fn.atwho = function(method) { var result, _args; _args = arguments; $('body').append($CONTAINER); result = null; this.filter('textarea, input, [contenteditable=true]').each(function() { var app; if (typeof method === 'object' || !method) { return Atwho.init.apply(this, _args); } else if (Api[method]) { if (app = $(this).data('atwho')) { return result = Api[method].apply(app, Array.prototype.slice.call(_args, 1)); } } else { return $.error("Method " + method + " does not exist on jQuery.caret"); } }); return result || this; }; return $.fn.atwho["default"] = { at: void 0, alias: void 0, data: null, tpl: "
  • ${name}
  • ", insert_tpl: "${atwho-data-value}", callbacks: DEFAULT_CALLBACKS, search_key: "name", start_with_space: true, limit: 5, max_len: 20, display_timeout: 300 }; });}).call(this);