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"> </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).trigger('contentLoad'); 262 } 263 264 } else { 265 gdn.inform(json); 266 formSaved = json['FormSaved']; 267 data = json['Data']; 268 269 // Add any js that's come in. 270 $(json.js).each(function(i, el){ 271 var v_js = document.createElement('script'); 272 v_js.type = 'text/javascript'; 273 v_js.src = gdn.url(el); 274 document.getElementsByTagName('head')[0].appendChild(v_js); 275 }); 276 277 // mosullivan - need to always reload the data b/c when uninviting ppl 278 // we need to reload the invitation table. Is there a reason not to reload 279 // the content? 280 // if (formSaved == false) 281 if (data) { // Prevent blank popups 282 $('#'+settings.popupId+' .Content').html(data).trigger('contentLoad'); 283 } 284 } 285 286 $('#'+settings.popupId+' .Loading').remove(); 287 $('#'+settings.popupId+' .Body').children().fadeIn('normal'); 288 289 $('#'+settings.popupId+' .Close').unbind().click(function() { 290 return $.popup.close(settings); 291 }); 292 293 settings.afterLoad(); 294 295 // Now, if there are any forms in the popup, hijack them if necessary. 296 if (settings.hijackForms == true) { 297 $('#'+settings.popupId+' form').ajaxForm({ 298 data: { 299 'DeliveryType': settings.deliveryType, 300 'DeliveryMethod': 'JSON' 301 }, 302 dataType: 'json', 303 beforeSubmit: function() { 304 settings.onSave(settings); // Notify the user that it is being saved. 305 }, 306 success: function(json) { 307 gdn.inform(json); 308 gdn.processTargets(json.Targets); 309 310 if (json.FormSaved == true) { 311 if (json.RedirectUrl) 312 setTimeout(function() { document.location.replace(json.RedirectUrl); }, 300); 313 314 settings.afterSuccess(settings, json); 315 $.popup.close(settings, json); 316 } else { 317 $.popup.reveal(settings, json) // Setup the form again 318 } 319 }, 320 error: function(xhr) { 321 $('.InProgress', this).removeClass('InProgress'); 322 gdn.informError(xhr); 323 } 324 }); 325 326 327 // Hijack links to navigate within the same popup. 328 $('#'+settings.popupId+' .PopLink').click(function() {
329 $.popup.loading(settings); 330 331 // Ajax the link into the current popup. 332 $.get($(this).attr('href'), {'DeliveryType': settings.deliveryType}, function(data, textStatus, xhr) { 333 if (typeof(data) == 'object') { 334 if (data.RedirectUrl) 335 setTimeout(function() { document.location.replace(data.RedirectUrl); }, 300); 336 } 337 $.popup.reveal(settings, data); 338 //$('#'+settings.popupId+' .Content').html(data); 339 }); 340 341 return false; 342 }); 343 } 344 345 // If there is a cancel button in the popup, hide it (the popup has it's own close button) 346 $('#'+settings.popupId+' a.Cancel').hide(); 347 348 // Trigger an even that plugins can attach to when popups are revealed. 349 $('body').trigger('popupReveal'); 350 351 return false; 352 } 353 354 $.popup.settings = { 355 targetUrl: false, // Use this URL instead of one provided by the matched element? 356 doPost: false, // Use POST, instead of GET, when performing an AJAX request? 357 confirm: false, // Pop up a confirm message? 358 followConfirm: false, // Follow the confirm url after OK, or request it with ajax? 359 afterConfirm: function(json, sender) { 360 // Called after the confirm url has been loaded via ajax 361 }, // Event to fire if the confirm was ajaxed 362 hijackForms: true, // Hijack popup forms so they are handled in-page instead of posting the entire page back 363 deliveryType: 'VIEW', // Adds DeliveryType=3 to url so Garden doesn't pull the entire page 364 mouseoverClass: 'Popable', // CssClass to be applied to a popup link when hovering 365 onSave: function(settings) { 366 if (settings.sender) { 367 $('#'+settings.popupId+' .Button:submit').attr('disabled', true).addClass('InProgress'); 368 } 369 }, 370 onLoad: function(settings) { 371 // Called before the "loading..." is displayed 372 }, 373 onUnload: function(settings, response) { 374 // Called after the popup is closed 375 }, 376 afterSuccess: function() { 377 // Called after an ajax request resulted in success, and before "close" is called. 378 }, 379 containerCssClass: '', 380 popupHtml: '\ 381 <div class="Overlay"> \ 382 <div id="{popup.id}" class="Popup"> \ 383 <div class="Border"> \ 384 <div class="Body"> \ 385 <div class="Content"> \ 386 </div> \ 387 <div class="Footer"> \ 388 <a href="#" class="Close"><span>×</span></a> \ 389 </div> \ 390 </div> \ 391 </div> \ 392 </div> \ 393 </div>', 394 confirmHtml: '\ 395 <div class="Overlay"> \ 396 <div id="{popup.id}" class="Popup"> \ 397 <div class="Border"> \ 398 <div class="Body"> \ 399 <div class="Content"><h1>Confirm</h1><p>Are you sure you want to do that?</p></div> \ 400 <div class="Buttons Footer"> \ 401 <input type="button" class="Button Primary Okay" value="OK" /> \ 402 <input type="button" class="Button Cancel" value="Cancel" /> \ 403 </div> \ 404 </div> \ 405 </div> \ 406 </div> \ 407 </div>', 408 afterLoad: function() {} 409 } 410 411 $.popup.inFrame = function() { 412 try { 413 if (top !== self && $(parent.document).width()) 414 return true; 415 } catch(e) { } 416 417 return false; 418 } 419 420 $.popup.getPageSize = function() { 421 var inFrame = $.popup.inFrame(); 422 var doc = $(inFrame ? parent.document : document); 423 var win = $(inFrame ? parent.window : window); 424 arrayPageSize = new Array( 425 $(doc).width(), 426 $(doc).height(), 427 $(win).width(), 428 $(win).height() 429 ); 430 return arrayPageSize; 431 }; 432 433 $.popup.getPagePosition = function() { 434 var inFrame = $.popup.inFrame(); 435 var doc = $(inFrame ? parent.document : document); 436 var win = $(inFrame ? parent.window : window); 437 var scroll = { 'top':doc.scrollTop(), 'left':doc.scrollLeft() }; 438 var t = scroll.top + ($(win).height() / 10); 439 if (inFrame) { 440 var el = $(parent.document).find('iframe[id^=vanilla]'); 441 el = el ? el : $(document); // Just in case iframe is not id'd properly 442 t -= (el.offset().top); 443 // Don't slide above or below the frame bounds. 444 var diff = $(doc).height() - $(document).height(); 445 var maxOffset = $(document).height() - diff; 446 if (t < 0) { 447 t = 0; 448 } else if (t > maxOffset) { 449 t = maxOffset; 450 } 451 } 452 return {'top':t, 'left':scroll.left}; 453 }; 454 455})(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.