PageSourceSearch

https://freestyler.ws/js/vendor/jquery.codabubble.js?v24122

js freestyler.ws collected 2026-09-24 09:11:40 UTC 5,983 bytes, 162 lines download raw bytes

1/*!
2 * jQuery Codabubble Plugin
3 * http://github.com/elidupuis
4 *
5 * Copyright 2010, Eli Dupuis
6 * Version: 0.4
7 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL (http://creativecommons.org/licenses/GPL/2.0/) licenses.
8 * Requires: jQuery v1.4.2 or later
9 * Based heavily on Remy Sharp's snippet at http://jqueryfordesigners.com/coda-popup-bubbles/
10
11TODO:
12  - destroy function
13  - add smart-direction feature? if direction is set to RIGHT and there's no room for element, make it appear on the left.
14 */
15
16
17
18(function($) {
19
20  var ver = '0.4',
21  methods = {
22    init: function( options ) {
23      // iterate and reformat each matched element
24    	return this.each(function() {
25    		var $this = $(this),
26    		    opts = $.extend({}, $.fn.codabubble.defaults, options),
27            data = $this.data('codabubble');
28
29        // If the plugin hasn't been initialized yet
30        if ( ! data ) {
31
32          var hideDelayTimer = null,
33              showDelayTimer = null,
34              beingShown = false, // tracker
35              shown = false,
36              trigger = $(opts.triggerClass, this),
37              popup = $(opts.popupClass, this).css('opacity', 0),
38              offset,
39              defaultCss = {},
40              directionProperty;
41          
42          //  determine offset format:    
43          if ( typeof opts.offset === 'function' ) {
44            offset = opts.offset.call(this, popup, $this) + 'px';
45          }else{
46            offset = opts.offset + 'px';
47          };           
48
49          // determine desired direction:
50          switch ( opts.direction ) {
51            case 'left' :
52              directionProperty = 'left';
53              break;
54            case 'right' :
55              directionProperty = 'right';
56              break;
57            case 'down' :
58              directionProperty = 'bottom';
59              break;
60            default : 
61              directionProperty = 'top';
62              break;
63          };
64          
65          //  setup default css based on desired direction:
66          defaultCss[directionProperty] = offset;
67          defaultCss['display'] = 'block';
68
69          // attach mouseover/mouseout listeners and functionality:
70          $([trigger.get(0), popup.get(0)]).bind({
71            'mouseover.codabubble': function () {
72              // stops the hide event if we move from the trigger to the popup element
73              if (hideDelayTimer) {
74                clearTimeout(hideDelayTimer);
75              };
76
77              // don't trigger the animation again if we're being shown, or already visible
78              if (beingShown || shown || showDelayTimer) {
79                return;
80              } else {
81                  showDelayTimer = setTimeout(function () {
82                      beingShown = true;
83                      showDelayTimer = null;
84                      // setup animation properties
85                      var animCSS = {opacity: 1};
86                      animCSS[directionProperty] = '-=' + opts.distance + 'px';
87
88                      // reset position of popup box and animate:
89                      popup.css(defaultCss).animate(animCSS, opts.time, 'swing', function () {
90                          // once the animation is complete, set the tracker variables
91                          beingShown = false;
92                          shown = true;
93                      });
94                  }, opts.hideDelay);
95              }
96            },
97            'mouseout.codabubble': function () {
98              // reset the timer if we get fired again - avoids double animations
99              if (hideDelayTimer) {
100                clearTimeout(hideDelayTimer);
101              };
102                if (showDelayTimer) {
103                    clearTimeout(showDelayTimer);
104                    showDelayTimer= null;
105                }
106                ;
107              // store the timer so that it can be cleared in the mouseover if required
108              hideDelayTimer = setTimeout(function () {
109                hideDelayTimer = null;
110
111                var animCSS = { opacity: 0 };
112                animCSS[directionProperty] = '-=' + opts.distance + 'px';
113               
114                popup.animate(animCSS, opts.time, 'swing', function () {
115                  shown = false; // once the animate is complete, set the tracker variables
116                  popup.hide();  // hide the popup entirely after the effect (opacity alone doesn't do the job)
117                });
118              }, opts.hideDelay);
119            }
120          }).trigger('mouseout.codabubble');
121          
122
123          //  attach data:
124          $(this).data('codabubble', {
125            target : $this,
126            opts: opts
127          });
128
129        };
130      });
131    },
132    destroy: function() {
133      // to be implemented....
134      if(window.console) window.console.log('destroy called.');
135    }
136  };
137
138  $.fn.codabubble = function( method ) {
139    if ( methods[method] ) {
140      return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
141    } else if ( typeof method === 'object' || ! method ) {
142      return methods.init.apply( this, arguments );
143    } else {
144      $.error( 'Method ' +  method + ' does not exist on jQuery.codabubble' );
145    };
146  };
147
148  //	defaults
149  $.fn.codabubble.defaults = {
150  	distance: 10,             //  distance traveled by bubble during animation.
151  	offset: 0,                //  offset distance. either an integer of a function that returns an integer
152    time: 250,                //  milliseconds. duration of the animation.
153    hideDelay: 500,           //  milliseconds. time before bubble fades out (after mouseout)
154    showDelay: 500,
155    direction: 'up',          //  either 'left', 'right', down' or 'up'
156    triggerClass: '.trigger', //  class of the trigger (in your markup)
157    popupClass: '.popup'      //  class of the bubble (in your markup)
158  };
159
160  $.fn.codabubble.ver = function() { return "jquery.codabubble ver. " + ver; };
161
162})(jQuery);

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.