PageSourceSearch

http://pilatuscentre.co.za/Resources/Shared/scripts/dnn.jquery.tooltip.js?cdv=56

js pilatuscentre.co.za collected 2026-10-08 23:21:27 UTC 12,945 bytes, 331 lines download raw bytes

1; if (typeof dnn === "undefined" || dnn === null) { dnn = {}; }; //var dnn = dnn || {};
2
3// the semi-colon before function invocation is a safety net against concatenated 
4// scripts and/or other plugins which may not be closed properly.
5(function ($, window, document, undefined) {
6    "use strict";
7
8    // undefined is used here as the undefined global variable in ECMAScript 3 is
9    // mutable (ie. it can be changed by someone else). undefined isn't really being
10    // passed in so we can ensure the value of it is truly undefined. In ES5, undefined
11    // can no longer be modified.
12
13    // window and document are passed through as local variables rather than globals
14    // as this (slightly) quickens the resolution process and can be more efficiently
15    // minified (especially when both are regularly referenced in your plugin).
16
17    var pluginName = 'dnntooltip';
18
19    // The actual plugin constructor
20    var Tooltip = this.Tooltip = function (element, options) {
21        this.element = element;
22        this.options = options;
23
24        this.init();
25    };
26
27    Tooltip.prototype = {
28
29        constructor: Tooltip,
30
31        init: function () {
32            // Place initialization logic here
33            // You already have access to the DOM element and the options via the instance, 
34            // e.g., this.element and this.options
35            this.options = $.extend({}, Tooltip.defaults(), this.options);
36
37            this.$this = $(this);
38            this.$element = $(this.element);
39
40            // remove the original title (tooltip) and alt attribute to prevent default tooltip in IE
41            this.$element.removeAttr('title').removeAttr('alt');
42
43            var onMouseEnterHandler = $.proxy(this._onMouseEnter, this);
44            var onMouseLeaveHandler = $.proxy(this._onMouseLeave, this, this.options.closeOnMouseLeave);
45            var onMouseClickHandler = $.proxy(this._onMouseClick, this);
46            this._onCloseButtonClickHandler = $.proxy(this._onCloseButtonClick, this);
47            this.$element.on('mouseenter', onMouseEnterHandler).on('mouseleave', onMouseLeaveHandler).on('click', onMouseClickHandler);
48            var onDocumentClickHandler = $.proxy(this._onDocumentClick, this);
49            $(document).on('click', onDocumentClickHandler);
50
51            this.disabled(this.options.disabled);
52        },
53
54        disabled: function(isDisabled) {
55            if (!(typeof isDisabled === "undefined")) {
56                this._disabled = isDisabled;
57            }
58            return this._disabled;
59        },
60
61        _onMouseEnter: function (eventObject) {
62            if (this.disabled()) {
63                return;
64            }
65            //eventObject.stopPropagation();
66            if (this._showTimeoutId) {
67                clearTimeout(this._showTimeoutId);
68            }
69            this._hoverState = "mouse-enter";
70            var self = this;
71            var show = function () { if (self._hoverState === "mouse-enter") { self._show(); } };
72            this._showTimeoutId = setTimeout(show, this.options.showIn);
73        },
74
75        _onMouseLeave: function (closeOnMouseLeave, eventObject) {
76            eventObject.stopPropagation();
77            if (this._showTimeoutId) {
78                clearTimeout(this._showTimeoutId);
79                this._showTimeoutId = undefined;
80            }
81            if (closeOnMouseLeave) {
82                this._hoverState = "mouse-leave";
83                var self = this;
84                var hide = function () { if (self._hoverState === "mouse-leave") { self._hide(); } };
85                this._showTimeoutId = setTimeout(hide, this.options.hideIn);
86            }
87        },
88
89        _onCloseButtonClick: function (eventObject) {
90            eventObject.preventDefault();
91            eventObject.stopPropagation();
92            if (this._showTimeoutId) {
93                clearTimeout(this._showTimeoutId);
94                this._showTimeoutId = undefined;
95            }
96            this._hide();
97        },
98
99        _hide: function () {
100            var index = $.inArray(this, Tooltip.displayedTooltips);
101            if (index >= 0) {
102                Tooltip.displayedTooltips.splice(index, 1);
103                if (this._$tooltip) {
104                    this._$tooltip.fadeOut(this.options.fadeOutDuration);
105                }
106            }
107        },
108
109        _onMouseClick: function (eventObject) {
110            if (this.disabled() || this.options.disableMouseClick) {
111                return;
112            }
113            eventObject.stopPropagation();
114            if (Tooltip.isDisplayed(this)) {
115                this._hide();
116            }
117            else {
118                this._show();
119            }
120        },
121
122        _isjQuery: function (obj) {
123            return obj && obj.jquery;
124        },
125
126        _getViewPort: function () {
127            var $window = $(window);
128            var viewPort = {
129                top: $window.scrollTop(),
130                left: $window.scrollLeft(),
131                width: $window.width(),
132                height: $window.height(),
133                right: function () { return this.left + this.width; },
134                bottom: function () { return this.top + this.height; }
135            };
136            return viewPort;
137        },
138
139        _createTooltip: function () {
140            var $tooltip;
141            $tooltip = $(this.options.template || '<div>').addClass(this.options.cssClass).hide();
142            if (this.options.id) {
143                $tooltip.attr('id', this.options.id);
144            }
145
146            var tooltipMarkup = this.options.getTooltipMarkup.call(this, this.element);
147            if (tooltipMarkup.nodeType || this._isjQuery(tooltipMarkup)) {
148                $tooltip.append(tooltipMarkup);
149
150                if (this.options.closeButtonSelector) {
151                    $(tooltipMarkup).find(this.options.closeButtonSelector).on('click', this._onCloseButtonClickHandler);
152                }
153            }
154            else {
155                $tooltip.html(tooltipMarkup);
156            }
157
158            $tooltip.on('mouseleave', $.proxy(this._onMouseLeave, this, true));
159            $tooltip.on('click', function (e) { e.stopPropagation(); });
160
161            return $tooltip;
162        },
163
164        _inContainer: function ($container, element) {
165            return $container && $container.length !== 0 && ($.contains($container[0], element) || $container[0] === element);
166        },
167
168        _onDocumentClick: function (eventObject) {
169            // clicked outside of the tooltip
170            // when click on the element, the onMouseClick handler is executed
171            var clickedElement = eventObject.target;
172            if (this._$tooltip && !this._inContainer(this._$tooltip, clickedElement)) {
173                this._hide();
174            }
175        },
176
177        _show: function () {
178            var index = 0;
179            var isDisplayed = false;
180            while (Tooltip.displayedTooltips.length > index) {
181                if (Tooltip.displayedTooltips[index] === this) {
182                    isDisplayed = true;
183                    index++;
184                }
185                else if (this.options.singleDisplay) {
186                    // close all others
187                    Tooltip.displayedTooltips[index]._hide();
188                }
189                else {
190                    index++;
191                }
192            }
193
194            if (isDisplayed) {
195                // already opened;
196                return;
197            }
198
199            Tooltip.displayedTooltips.push(this);
200
201            if (!this._$tooltip) {
202                this._$tooltip = this._createTooltip();
203            }
204            this._setTooltipOffset();
205        },
206
207        _setTooltipOffset: function () {
208
209            this._$tooltip.detach().removeCssProperties("height", "width", "left", "top").css({ display: "block" });
210            if (this.options.container) {
211                this._$tooltip.appendTo(this.options.container);
212            }
213            else {
214                this._$tooltip.insertAfter(this.$element);
215            }
216
217            var placement = (typeof this.options.placement == 'function' ?
218                this.options.placement.call(this, this._$tooltip[0], this.element) : this.options.placement);
219
220            var elementPosition = this._getPosition();
221
222            var tooltipWidth = this._$tooltip.outerWidth();
223            var tooltipHeight = this._$tooltip.outerHeight();
224            var tooltipPosition;
225
226            switch (placement) {
227                case 'top':
228                    tooltipPosition = { top: elementPosition.top - tooltipHeight, left: elementPosition.left + 10/*+ (elementPosition.width - tooltipWidth) / 2 */ };
229                    break;
230                case 'bottom':
231                    tooltipPosition = { top: elementPosition.top + elementPosition.height, left: elementPosition.left + 10 /*+ (elementPosition.width - tooltipWidth) / 2 */ };
232                    break;
233                case 'left':
234                    tooltipPosition = { top: elementPosition.top + (elementPosition.height - tooltipHeight) / 2, left: elementPosition.left - tooltipWidth };
235                    break;
236                case 'right':
237                    tooltipPosition = { top: elementPosition.top + (elementPosition.height - tooltipHeight) / 2, left: elementPosition.left + elementPosition.width };
238                    break;
239                default:
240                    // use the "top" placement as default
241                    tooltipPosition = { top: elementPosition.top + this.options.top, left: elementPosition.left + this.options.left };
242            }
243
244            var viewPort = this._getViewPort();
245
246            var offScreenLength = (tooltipPosition.left + tooltipWidth) - viewPort.right();
247            if (offScreenLength > 0) {
248                tooltipPosition.left = Math.max(viewPort.left, tooltipPosition.left - offScreenLength);
249            }
250
251            offScreenLength = (tooltipPosition.top + tooltipHeight) - viewPort.bottom();
252            if (offScreenLength > 0) {
253                tooltipPosition.top = Math.max(viewPort.top, tooltipPosition.top - offScreenLength);
254            }
255
256            this._$tooltip.offset(tooltipPosition).fadeIn(this.options.fadeInDuration); // show();
257            if (this.options.animateOnOpen) {
258                var originalSize = { height: this._$tooltip.height(), width: this._$tooltip.width() };
259                this._$tooltip.css({ height: 0, width: 0 }).animate(originalSize, this.options.fadeInDuration);
260            }
261        },
262
263        _removeTooltip: function () {
264            if (this._$tooltip) {
265                var complete = function () {
266                    $(this).remove();
267                };
268                this._$tooltip.stop().fadeOut(this.options.fadeOutDuration, complete);
269                this._$tooltip = null;
270            }
271        },
272
273        _getPosition: function () {
274            return $.extend({}, (typeof this.element.getBoundingClientRect === 'function') ? this.element.getBoundingClientRect() : {
275                width: this.element.offsetWidth,
276                height: this.element.offsetHeight
277            }, this.$element.offset());
278        }
279
280    };
281
282    Tooltip._defaults = {
283        fade: false,
284        cssClass: "",
285        top: 15,
286        left: 15,
287        fadeInDuration: 400,
288        fadeOutDuration: 400,
289        closeOnMouseLeave: true,
290        animateOnOpen: false,
291        container: null,
292        showIn: 400,
293        hideIn: 100,
294        template: "<div></div>",
295        disableMouseClick: true
296    };
297
298    Tooltip.defaults = function (settings) {
299        if (typeof settings !== "undefined") {
300            $.extend(Tooltip._defaults, settings);
301        }
302        return Tooltip._defaults;
303    };
304
305    Tooltip.displayedTooltips = []; // array of tooltips being currently opened
306
307    Tooltip.isDisplayed = function (tooltip) {
308        return $.inArray(tooltip, Tooltip.displayedTooltips) >= 0;
309    };
310
311    $.fn[pluginName] = function (option) {
312
313        // get the arguments
314        var args = $.makeArray(arguments);
315        var params = args.slice(1);
316
317        return this.each(function () {
318            var $this = $(this);
319            var instance = $this.data(pluginName);
320            if (!instance) {
321                var options = $.extend({}, typeof option === "object" && option);
322                $this.data(pluginName, (instance = new Tooltip(this, options)));
323            }
324            if (typeof option === "string") {
325                instance[option].apply(instance, params);
326            }
327        });
328    };
329
330}).apply(dnn, [jQuery, window, document]);
331

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.