PageSourceSearch

https://www.mediaminer.org/forum/js/library/jquery.popup.js?v=2.3.1

js mediaminer.org collected 2026-10-02 12:05:57 UTC 15,953 bytes, 452 lines download raw bytes

1/*
2This is a highly modified version of the Facebox plugin for jQuery by Chris
3Wanstrath. Original Credits:
4
5Facebox (for jQuery)
6version: 1.0 (12/19/2007)
7@requires jQuery v1.2 or later
8Examples at http://famspam.com/facebox/
9Licensed under the MIT: http://www.opensource.org/licenses/mit-license.php
10Copyright 2007 Chris Wanstrath [ [email protected] ]
11*/
12
13(function($) {
14
15   // Allows generating a popup by jQuery.popup('contents')
16   $.popup = function(options, data) {
17	  // Merge default settings:
18      var settings = $.extend({}, $.popup.settings, options);
19      $.popup.init(settings)
20
21      if (data) {
22         $.isFunction(data) ? data.call(this, settings) : $.popup.reveal(settings, data);
23      } else {
24         $.popup.load(settings);
25      }
26   }
27
28   $.fn.popup = function(options) {
29
30      /*
31       * Since upgrading jQuery to 1.10.2 this does not work, as $.browser was
32       * removed. The author of this popup plugin does not explain why
33       * ie6+7 don't get popups, but at this point in time it's no matter. Just
34       * make sure the popup function works as expected.
35       */
36      var browser = navigator.userAgent.toLowerCase();
37      // IE7 or less gets no popups because they're jerks
38      if (/msie\s6/.test(browser) || /msie\s7/.test(browser)) {
39         return false;
40      }
41
42      // Merge the two settings arrays into a central data store
43      var settings = $.extend({}, $.popup.settings, options);
44
45      // Need to rewrite how popup is called, to incorporate
46      // event delegation, as live() removed from jQuery in 1.7, and Vanilla
47      // upgraded to 1.10.2 on Jan28, 2014.
48      //this.live('click', function() {
49      var selector = this.selector;
50      $(document).on('click', selector, function() {
51         settings.sender = this;
52         $.extend(settings, { popupType: $(this).attr('popupType') });
53
54         $.popup.init(settings);
55
56         $.popup.load(settings);
57
58         return false;
59      });
60
61      this.mouseover(function() {
62         settings.sender = this;
63         if ($.popup.findTarget(settings))
64            $(this).addClass(settings.mouseoverClass);
65      });
66
67      this.mouseout(function() {
68         settings.sender = this;
69         if ($.popup.findTarget(settings))
70            $(this).removeClass(settings.mouseoverClass);
71      });
72
73      return this;
74   }
75
76   $.popup.findTarget = function(settings) {
77      settings.foundTarget = settings.targetUrl;
78
79      // See if the matched element was an anchor. If it was, use the href.
80      if (!settings.foundTarget) {
81         if ($(settings.sender).attr('href') != undefined) {
82            settings.foundTarget = settings.sender.href;
83         } else {
84            // See if there were any anchors within the matched element.
85            // If there are, use the href from the first one.
86            var anchor = $(settings.sender).find('a:first');
87            if (anchor.length > 0) {
88               settings.foundTarget = anchor[0].href;
89            }
90         }
91      }
92
93      return settings.foundTarget;
94   }
95
96   // Close a jquery popup and release escape key bindings
97   $.popup.close = function(settings, response) {
98      $(document).unbind('keydown.popup');
99      $('#'+settings.popupId).trigger('popupClose');
100      $('.Overlay').remove();
101
102      return false;
103   }
104
105   $.popup.init = function(settings) {
106      // Define a unique identifier for this popup
107      var i = 1;
108      var popupId = 'Popup';
109      while ($('#'+popupId).size() > 0) {
110         popupId = 'Popup'+i;
111         i++;
112      }
113      settings.popupId = popupId;
114      var popupHtml = '';
115      if (!settings.confirm)
116         popupHtml = settings.popupHtml;
117      else
118         popupHtml = settings.confirmHtml;
119
120      popupHtml = popupHtml.replace('{popup.id}', settings.popupId);
121
122      $('body').append(popupHtml);
123      if (settings.containerCssClass != '')
124         $('#'+settings.popupId).addClass(settings.containerCssClass);
125
126      var pagesize = $.popup.getPageSize();
127      $('div.Overlay').css({height: pagesize[1]});
128
129      var pagePos = $.popup.getPagePosition();
130      $('#'+settings.popupId).css({
131         top: pagePos.top,
132         left: pagePos.left
133      });
134      $('#'+settings.popupId).show();
135
136      $('#'+settings.popupId+' .Body').css({
137         'max-height': pagesize[3] * .8,
138         'overflow-y': 'auto'
139      });
140
141      $(document).bind('keydown.popup', function(e) {
142         if (e.keyCode == 27)
143            $.popup.close(settings);
144      })
145
146      if (settings.onUnload) {
147         $('#'+settings.popupId).bind('popupClose',function(){
148            setTimeout(settings.onUnload,1);
149         });
150      }
151
152      // Replace language definitions
153      if (!settings.confirm) {
154         $('#'+settings.popupId+' .Close').click(function() {
155            return $.popup.close(settings);
156         });
157      } else {
158         // 'Confirm' popup heading
159         var confirmHeading = (settings.confirmHeading) ? settings.confirmHeading : gdn.definition('ConfirmHeading', 'Confirm');
160         $('#'+settings.popupId+' .Content h1').text(confirmHeading);
161
162         // 'Confirm' popup body text
163         var confirmText = (settings.confirmText) ? settings.confirmText : gdn.definition('ConfirmText', 'Are you sure you want to do that?');
164         $('#'+settings.popupId+' .Content p').text(confirmText);
165
166         $('#'+settings.popupId+' .Okay').val(gdn.definition('Okay', 'Okay'));
167         $('#'+settings.popupId+' .Cancel').val(gdn.definition('Cancel', 'Cancel')).click(function() {
168            $.popup.close(settings);
169         });
170      }
171   }
172
173   $.popup.loading = function(settings) {
174      settings.onLoad(settings);
175      if ($('#'+settings.popupId+' .Loading').length == 1)
176         return true;
177
178      $('#'+settings.popupId+' .Content').empty();
179      $('#'+settings.popupId+' .Body').children().hide().end().append('<div class="Loading">&#160;</div>');
180      // Trigger an even that plugins can attach to when popups are loading.
181      $('body').trigger('popupLoading');
182   }
183
184   $.popup.load = function(settings) {
185       if (!settings.confirm) {
186          $.popup.loading(settings);
187       }
188
189	   var target = $.popup.findTarget(settings);
190       if (settings.confirm) {
191          // Bind to the "Okay" button click
192          $('#'+settings.popupId+' .Okay').focus().click(function() {
193             if (settings.followConfirm) {
194                // follow the target
195                document.location = target;
196             } else {
197                // request the target via ajax
198                var ajaxData = {'DeliveryType' : settings.deliveryType, 'DeliveryMethod' : 'JSON'};
199                if (settings.doPost) {
200                   ajaxData.TransientKey = gdn.definition('TransientKey');
201                }
202                $.popup.loading(settings);
203
204                $.ajax({
205                   method: settings.doPost ? 'POST' : 'GET',
206                   url: target,
207                   data: ajaxData,
208                   dataType: 'json',
209                   error: function(xhr) {
210                      gdn.informError(xhr);
211                   },
212                   success: function(json) {
213                      $.popup.close(settings);
214                      settings.afterConfirm(json, settings.sender);
215                      gdn.inform(json);
216                      gdn.processTargets(json.Targets);
217
218                      if (json.RedirectUrl)
219                         setTimeout(function() { document.location.replace(json.RedirectUrl); }, 300);
220                   }
221                });
222             }
223          });
224       } else {
225          if (target) {
226             var ajaxData = { 'DeliveryType': settings.deliveryType };
227             if (settings.doPost) {
228                ajaxData.TransientKey = gdn.definition('TransientKey');
229             }
230
231             $.ajax({
232                method: settings.doPost ? 'POST' : 'GET',
233                url: target,
234                data: ajaxData,
235                error: function(request, textStatus, errorThrown) {
236                   $.popup.reveal(settings, request.responseText);
237                },
238                success: function(data) {
239                   $.popup.reveal(settings, data);
240                }
241             });
242//        $.get(target, {'DeliveryType': settings.deliveryType}, function(data) {
243//          $.popup.reveal(settings, data)
244//        });
245          }
246       }
247   }
248
249   $.popup.reveal = function(settings, data) {
250      // First see if we've retrieved json or something else
251      var json = false;
252      if (data instanceof Array) {
253         json = false;
254      } else if (data !== null && typeof(data) == 'object') {
255         json = data;
256      }
257
258      if (json == false) {
259         // This is something other than json, so just put it into the popup directly
260         if (data) // Prevent blank popups
261            $('#'+settings.popupId+' .Content').append(data);
262      } else {
263         gdn.inform(json);
264         formSaved = json['FormSaved'];
265         data = json['Data'];
266
267         // Add any js that's come in.
268         $(json.js).each(function(i, el){
269            var v_js  = document.createElement('script');
270            v_js.type = 'text/javascript';
271            v_js.src = gdn.url(el);
272            document.getElementsByTagName('head')[0].appendChild(v_js);
273         });
274
275         // mosullivan - need to always reload the data b/c when uninviting ppl
276         // we need to reload the invitation table. Is there a reason not to reload
277         // the content?
278         // if (formSaved == false)
279         if (data) // Prevent blank popups
280            $('#'+settings.popupId+' .Content').html(data);
281      }
282
283      $('#'+settings.popupId+' .Loading').remove();
284      $('#'+settings.popupId+' .Body').children().fadeIn('normal');
285
286      $('#'+settings.popupId+' .Close').unbind().click(function() {
287         return $.popup.close(settings);
288      });
289
290      settings.afterLoad();
291
292      // Now, if there are any forms in the popup, hijack them if necessary.
293      if (settings.hijackForms == true) {
294         $('#'+settings.popupId+' form').ajaxForm({
295            data: {
296                'DeliveryType': settings.deliveryType,
297                'DeliveryMethod': 'JSON'
298            },
299            dataType: 'json',
300            beforeSubmit: function() {
301               settings.onSave(settings); // Notify the user that it is being saved.
302            },
303            success: function(json) {
304               gdn.inform(json);
305               gdn.processTargets(json.Targets);
306
307               if (json.FormSaved == true) {
308                  if (json.RedirectUrl)
309                     setTimeout(function() { document.location.replace(json.RedirectUrl); }, 300);
310
311                  settings.afterSuccess(settings, json);
312                  $.popup.close(settings, json);
313               } else {
314                  $.popup.reveal(settings, json) // Setup the form again
315               }
316            },
317            error: function(xhr) {
318               $('.InProgress', this).removeClass('InProgress');
319               gdn.informError(xhr);
320            }
321         });
322
323
324         // Hijack links to navigate within the same popup.
325         $('#'+settings.popupId+' .PopLink').click(function() {
326            $.popup.loading(settings);
327
328            // Ajax the link into the current popup.
329            $.get($(this).attr('href'), {'DeliveryType': settings.deliveryType}, function(data, textStatus, xhr) {
330               if (typeof(data) == 'object') {
331                  if (data.RedirectUrl)
332                     setTimeout(function() { document.location.replace(data.RedirectUrl); }, 300);
333               }
334               $.popup.reveal(settings, data);
335               //$('#'+settings.popupId+' .Content').html(data);
336            });
337
338            return false;
339         });
340      }
341
342      // If there is a cancel button in the popup, hide it (the popup has it's own close button)
343      $('#'+settings.popupId+' a.Cancel').hide();
344
345      // Trigger an even that plugins can attach to when popups are revealed.
346      $('body').trigger('popupReveal');
347
348      return false;
349   }
350
351   $.popup.settings = {
352      targetUrl:        false,        // Use this URL instead of one provided by the matched element?
353      doPost:           false,        // Use POST, instead of GET, when performing an AJAX request?
354      confirm:          false,        // Pop up a confirm message?
355      followConfirm:    false,        // Follow the confirm url after OK, or request it with ajax?
356      afterConfirm:     function(json, sender) {
357         // Called after the confirm url has been loaded via ajax
358      },                              // Event to fire if the confirm was ajaxed
359      hijackForms:      true,         // Hijack popup forms so they are handled in-page instead of posting the entire page back
360      deliveryType:     'VIEW',            // Adds DeliveryType=3 to url so Garden doesn't pull the entire page
361      mouseoverClass:   'Popable',    // CssClass to be applied to a popup link when hovering
362      onSave:           function(settings) {
363         if (settings.sender) {
364            $('#'+settings.popupId+' .Button:submit').attr('disabled', true).addClass('InProgress');
365         }
366      },
367      onLoad:           function(settings) {
368         // Called before the "loading..." is displayed
369      },
370      onUnload:         function(settings, response) {
371         // Called after the popup is closed
372      },
373      afterSuccess:     function() {
374         // Called after an ajax request resulted in success, and before "close" is called.
375      },
376      containerCssClass: '',
377      popupHtml:       '\
378  <div class="Overlay"> \
379    <div id="{popup.id}" class="Popup"> \
380      <div class="Border"> \
381        <div class="Body"> \
382          <div class="Content"> \
383          </div> \
384          <div class="Footer"> \
385            <a href="#" class="Close"><span>&times;</span></a> \
386          </div> \
387        </div> \
388      </div> \
389    </div> \
390  </div>',
391      confirmHtml:       '\
392  <div class="Overlay"> \
393    <div id="{popup.id}" class="Popup"> \
394      <div class="Border"> \
395        <div class="Body"> \
396          <div class="Content"><h1>Confirm</h1><p>Are you sure you want to do that?</p></div> \
397          <div class="Buttons Footer"> \
398            <input type="button" class="Button Primary Okay" value="OK" /> \
399            <input type="button" class="Button Cancel" value="Cancel" /> \
400          </div> \
401        </div> \
402      </div> \
403    </div> \
404  </div>',
405      afterLoad: function() {}
406   }
407
408   $.popup.inFrame = function() {
409      try {
410         if (top !== self && $(parent.document).width())
411            return true;
412      } catch(e) { }
413
414      return false;
415   }
416
417   $.popup.getPageSize = function() {
418      var inFrame = $.popup.inFrame();
419      var doc = $(inFrame ? parent.document : document);
420      var win = $(inFrame ? parent.window : window);
421      arrayPageSize = new Array(
422         $(doc).width(),
423         $(doc).height(),
424         $(win).width(),
425         $(win).height()
426      );
427      return arrayPageSize;
428   };
429
430   $.popup.getPagePosition = function() {
431      var inFrame = $.popup.inFrame();
432      var doc = $(inFrame ? parent.document : document);
433      var win = $(inFrame ? parent.window : window);
434      var scroll = { 'top':doc.scrollTop(), 'left':doc.scrollLeft() };
435      var t = scroll.top + ($(win).height() / 10);
436      if (inFrame) {
437         var el = $(parent.document).find('iframe[id^=vanilla]');
438         el = el ? el : $(document); // Just in case iframe is not id'd properly
439         t -= (el.offset().top);
440         // Don't slide above or below the frame bounds.
441         var diff = $(doc).height() - $(document).height();
442         var maxOffset = $(document).height() - diff;
443         if (t < 0) {
444            t = 0;
445         } else if (t > maxOffset) {
446            t = maxOffset;
447         }
448      }
449      return {'top':t, 'left':scroll.left};
450   };
451
452})(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.