PageSourceSearch

https://www.zamnesia.com/themes/responsive/libs/popover/popover.js?_=560f8f09da050aa5b6497d2740097f16

js zamnesia.com collected 2026-09-24 18:32:10 UTC 11,874 bytes, 329 lines download raw bytes

1/* ========================================================================
2 * fu_popover v1.1.2
3 *
4 * ========================================================================
5 * Copyright 2016 gsreddy.in
6 *
7 * ======================================================================== */
8
9(function($){
10
11  var pluginName = 'fu_popover';
12  var popoverId = 7;
13
14 // These are the plugin defaults values
15  var defaults = {
16    arrowShow:true,
17    autoHide:false,
18    autoHideDelay:2500,
19    content:'',
20    delay:{"show": 0, "hide": 0},
21    dismissable:false,
22    placement:'bottom',
23    themeName:'default',
24    title:'',
25    trigger:'click',
26    width:'150px'
27  };
28
29  var fu_popover = function(element,options){
30
31    this.element = $(element);
32    this.popoverId = pluginName+"_"+(popoverId++);
33    this.options = $.extend({}, defaults, options);
34    this.options.autoHideDelay = this.options.autoHideDelay === undefined ? 0 : this.options.autoHideDelay;
35    this.options.delay.show = this.options.delay.show === undefined ? 0 : this.options.delay.show;
36    this.options.delay.hide = this.options.delay.hide === undefined ? 0 : this.options.delay.hide;
37    this.setStyles();
38    this.init();
39    this.initTriggers();
40
41    return this;
42  };
43
44  fu_popover.prototype.setStyles = function(){
45
46    if(this.options.themeName === "default"){
47      if($("#fu_popover_styles_default").length){
48
49      }
50      else{
51        var str='.fu_popover_'+this.options.themeName+' {position: absolute;background: #fff;border: 1px solid rgba(0, 0, 0, 0.2);border-radius: 6px;z-index: 1060;-webkit-background-clip: padding-box;background-clip: padding-box;border: 1px solid #cccccc;border: 1px solid rgba(0, 0, 0, 0.2);border-radius: 6px;-webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);}';
52
53        str+='.fu_popover_header_'+this.options.themeName+'{margin: 0;padding: 8px 14px;font-size: 14px;text-align: center;background-color: #f7f7f7;border-bottom: 1px solid #ebebeb;border-radius: 5px 5px 0 0;}.fu_popover_content_'+this.options.themeName+'{padding: 9px 14px;}';
54        str+='.fu_popover_'+this.options.themeName+':after, .fu_popover_'+this.options.themeName+':before {border: solid transparent;content: " ";height: 0;width: 0;position: absolute;pointer-events: none;}.fu_popover_'+this.options.themeName+':after {border-color: rgba(255, 255, 255, 0);border-width: 10px;}.fu_popover_'+this.options.themeName+':before {border-color: rgba(0, 0, 0, 0);border-width: 11px;}';
55
56            str+='.arrow_top_'+this.options.themeName+':after{left: 50%;bottom: 100%;border-bottom-color: #fff;margin-left: -10px;}.arrow_top_'+this.options.themeName+':before{left: 50%;bottom: 100%;border-bottom-color: rgba(0, 0, 0, 0.2);margin-left: -11px;}';
57            str+='.arrow_bottom_'+this.options.themeName+':after{left: 50%;top: 100%;border-top-color: #fff;margin-left: -10px;}.arrow_bottom_'+this.options.themeName+':before{left: 50%;top: 100%;border-top-color: rgba(0, 0, 0, 0.2);margin-left: -11px;}';
58            str+='.arrow_left_'+this.options.themeName+':after{right: 100%;top: 50%;border-right-color: #fff;margin-top: -10px;}.arrow_left_'+this.options.themeName+':before{right: 100%;top: 50%;border-right-color: rgba(0, 0, 0, 0.2);margin-top: -11px;}';
59            str+='.arrow_right_'+this.options.themeName+':after{left: 100%;top: 50%;border-left-color: #fff;margin-top: -10px;}.arrow_right_'+this.options.themeName+':before{left: 100%;top: 50%;border-left-color: rgba(0, 0, 0, 0.2);margin-top: -11px;}';
60
61        // set styles for popover
62        $( "<style type='text/css' id='fu_popover_styles_default'>"+str+"</style>" ).appendTo( "head" );
63
64        // set styles for progressbar
65        str = '.fu_progress{overflow: hidden;height: 20px;margin-bottom: 10px;background-color: #f5f5f5;border-radius: 4px;-webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);}';
66        str+='.fu_progress_bar{float: left;width: 0%;height: 100%;font-size: 12px;line-height: 20px;color: #ffffff;text-align: center;background-color: #337ab7;-webkit-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15);box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15);-webkit-transition: width 0.6s ease;-o-transition: width 0.6s ease;transition: width 0.6s ease;}';
67
68        $( "<style type='text/css'>
68"+str+"</style>" ).appendTo( "head" );
69      }
70    }
71
72  };
73
74  fu_popover.prototype.init = function()
75  {
76    var title='';
77    var content='';
78
79    if(this.options.title.length > 0)
80    title='<div class="fu_popover_header_'+this.options.themeName+'">'+this.options.title+'</div>';
81
82    var htmlStr = '<div class="fu_popover_'+this.options.themeName+' '+this.getArrowClass()+'" id="'+this.popoverId+'" style="display:none;">'+title+'<div class="fu_popover_content_'+this.options.themeName+'">'+this.options.content+'</div></div>';
83
84    this.options.dismissable === true ? this.initDismissableEvent():'';
85
86    this.htmlStr = htmlStr;
87
88  };
89
90  fu_popover.prototype.getArrowClass = function(){
91
92    return this.options.placement === 'top' ? 'arrow_bottom_'+this.options.themeName :
93           this.options.placement === 'bottom' ? 'arrow_top_'+this.options.themeName :
94           this.options.placement === 'left' ? 'arrow_right_'+this.options.themeName :
95           this.options.placement === 'right' ? 'arrow_left_'+this.options.themeName : '';
96  }
97//**************  Events
98  fu_popover.prototype.initDismissableEvent = function(){
99
100    var id = this.popoverId;
101    var delay = this.options.delay.hide;
102    var elem = this.element;
103
104    $(document).mouseup(function (e)
105    {
106        var container = $(elem);
107        var container1 = $('#'+id);
108
109        if (!container.is(e.target) // if the target of the click isn't the container...
110            && container.has(e.target).length === 0 // ... nor a descendant of the container
111           && !container1.is(e.target)
112           && container1.has(e.target).length === 0) // ... nor a descendant of the container
113        {
114            $('#'+id).hide(delay);
115        }
116    });
117
118  };
119
120  fu_popover.prototype.initTriggers = function(){
121    var triggers = (this.options.trigger).split(" ");
122    triggers = jQuery.unique(triggers);
123
124    for(var i=0;i<triggers.length;i++)
125    {
126      triggers[i] === 'click' ? this.initClickTrigger() :
127      triggers[i] === 'hover' ? this.initHoverTrigger() :
128      triggers[i] === 'focus' ? this.initFocusTrigger() : '';
129    }
130  };
131
132  fu_popover.prototype.initClickTrigger = function(){
133    var elem = this.element;
134    $('body').on("click", '#'+this.element[0].id+'', function() {
135      $(elem).fu_popover("show");
136    });
137  };
138  fu_popover.prototype.initHoverTrigger = function(){
139    var elem = this.element;
140    $('body').on("mouseenter", '#'+this.element[0].id+'', function() {
141      $(elem).fu_popover("show");
142    });
143  };
144  fu_popover.prototype.initFocusTrigger = function(){
145    var elem = this.element;
146    $('body').on("focus", '#'+this.element[0].id+'', function() {
147      $(elem).fu_popover("show");
148    });
149  };
150
151  //**************  Events
152
153  // Show /hide /destroy
154    fu_popover.prototype.display = function(option){
155
156      var id = this.popoverId;
157
158      if(option === 'show'){
159        var showDelay = this.options.delay.show;
160        var arrowShow = this.options.arrowShow;
161
162        if(!$("#"+id).length)
163        $("body").append(this.htmlStr);
164
165        setTimeout(function(){
166
167          if(!arrowShow){
168            $("#"+id).attr('class','');
169            $("#"+id).addClass("fu_popover_"+this.options.themeName);
170          }
171
172          $("#"+id).show();
173        },showDelay);
174
175        this.setPopupPosition();
176
177        if(this.options.autoHide === true){
178          var hideDelay = this.options.autoHideDelay;
179          hideDelay = hideDelay == 0 ? 2500 : hideDelay;
180
181          setTimeout(function(){
182              $("#"+id).hide();
183          },hideDelay);
184
185        }
186
187      }
188      else if(option === 'hide'){
189        $("#"+id).hide(this.options.delay.hide);
190      }
191      else if(option === 'destroy'){
192        $("#"+id).remove();
193        $(this.element).removeData("fu_popover");
194        this.destroyTriggers();
195      }
196
197    }
198
199// Calculate offsets - for old browsers
200    fu_popover.prototype.getOffsetSum = function(elem) {
201      var top=0, left=0
202      while(elem) {
203        top = top + parseInt(elem.offsetTop)
204        left = left + parseInt(elem.offsetLeft)
205        elem = elem.offsetParent
206      }
207
208      return {top: top, left: left}
209    }
210
211// Calculate offsets
212    fu_popover.prototype.getOffsetRect = function(elem) {
213        var box = elem.getBoundingClientRect()
214
215        var body = document.body
216        var docElem = document.documentElement
217
218        var scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop
219        var scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft
220
221        var clientTop = docElem.clientTop || body.clientTop || 0
222        var clientLeft = docElem.clientLeft || body.clientLeft || 0
223
224        var top  = box.top +  scrollTop - clientTop
225        var left = box.left + scrollLeft - clientLeft
226
227        return { top: Math.round(top), left: Math.round(left) }
228    }
229
230    fu_popover.prototype.getOffset = function( elem ){
231        if (elem.getBoundingClientRect) {
232            return this.getOffsetRect(elem)
233        } else {
234            return this.getOffsetSum(elem)
235        }
236    }
237
238  fu_popover.prototype.setPopupPosition = function(){
239
240    $("#"+this.popoverId).css({width:this.options.width});
241
242    var position = this.getOffset(this.element[0]);
243
244    var popoverPosition = $("#"+this.popoverId).position();
245
246    var parentWidth = $(this.element).outerWidth();
247    var parentHeight = $(this.element).outerHeight();
248    var parentLeft = position.left;
249    var parentTop = position.top;
250
251    var popoverWidth = $("#"+this.popoverId).outerWidth();
252    var popoverHeight = $("#"+this.popoverId).outerHeight();
253
254    var left,top;
255
256    if(this.options.placement === 'bottom' || this.options.placement === 'top'){
257
258      var parentCenter = (parentWidth/2);
259      var popoverCenter = (popoverWidth/2);
260
261      if(this.options.placement === 'bottom'){
262          top = parentTop + parentHeight;// 12.5 - arrow height
263      }
264      else{
265          top = parentTop - popoverHeight - 10;//why 10 ?? box consists shadow
266      }
267
268      var  pCenterLeft = parentLeft + parentCenter;
269
270      left = pCenterLeft - popoverCenter;
271
272    }
273    else if(this.options.placement === 'left' || this.options.placement === 'right'){
274
275      var parentCenter = (parentHeight/2);
276      var popoverCenter = (popoverHeight/2);
277
278      if(this.options.placement === 'left'){
279          left = parentLeft - popoverWidth - 10;
280      }
281      else{
282          left = parentLeft + parentWidth + 14;//box shadow
283      }
284
285      var  pCenterTop = parentTop + parentCenter;
286
287      top = pCenterTop - popoverCenter;
288
289    }
290    if (left < 0) {
291      left = 0;
292    }
293    $("#"+this.popoverId).css({"left":left+"px","top":top+"px"});
294
295  }
296
297  fu_popover.prototype.destroyTriggers = function(){
298    var triggers = (this.options.trigger).split(" ");
299    triggers = jQuery.unique(triggers);
300
301    for(var i=0;i<triggers.length;i++)
302    {
303      $('body').off("click", '#'+this.element[0].id+'', function(){});
304      $('body').off("mouseenter", '#'+this.element[0].id+'', function(){});
305      $('body').off("focus", '#'+this.element[0].id+'', function(){});
306    }
307  };
308
309  $.fn.fu_popover = function(options){
310
311    if (typeof options == 'string'){
312        var obj = $(this).data(pluginName);
313        if(jQuery.isEmptyObject(obj))
314        return this;
315        obj.display(options);
316    }
317    else{
318      if(!$.data(this, pluginName)){
319
320        var pop = new fu_popover(this,options);
321        $("#"+pop.element[0].id).data(pluginName,pop);
322        $.data(this, pluginName, pop);
323
324        return this;
325      }
326    }
327  }
328
329}(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.