|
| 1 | + |
| 2 | +/* |
| 3 | + * Popit Plugin for jQuery JavaScript Library |
| 4 | + * |
| 5 | + * Copyright (c) 2014 Adam J De Lucia |
| 6 | + * Licensed under the MIT License. |
| 7 | + * http://opensource.org/licenses/MIT |
| 8 | + * |
| 9 | + * Author: Adam J De Lucia |
| 10 | + * Version: 1.0.0 |
| 11 | + * Date: May 24 2014 |
| 12 | + * |
| 13 | + */ |
| 14 | + |
| 15 | +$.fn.popit = function (options) { |
| 16 | + this.each(function () { |
| 17 | + var settings = $.extend({ |
| 18 | + popup: $(this), |
| 19 | + defaultWidth: 960, |
| 20 | + defaultHeight: 285, |
| 21 | + url: $(this).attr("href"), |
| 22 | + name: $(this).attr("target"), |
| 23 | + dynamicWidth: $(this).data("width"), |
| 24 | + dynamicHeight: $(this).data("height") |
| 25 | + }, options); |
| 26 | + |
| 27 | + var show = function (e) { |
| 28 | + e.preventDefault(); |
| 29 | + if (settings.dynamicWidth && settings.dynamicHeight) { |
| 30 | + var popitWindow = window.open(settings.url, settings.name, "location=0, menubar=0, status=0, toolbar=0, width=" + settings.dynamicWidth + ", height=" + settings.dynamicHeight + '"', false) |
| 31 | + } else if (settings.dynamicWidth || settings.dynamicHeight) { |
| 32 | + if (settings.dynamicWidth) { |
| 33 | + var popitWindow = window.open(settings.url, settings.name, "location=0, menubar=0, status=0, toolbar=0, width=" + settings.dynamicWidth + ", height=" + settings.defaultHeight + '"', false) |
| 34 | + } else { |
| 35 | + var popitWindow = window.open(settings.url, settings.name, "location=0, menubar=0, status=0, toolbar=0, width=" + settings.defaultWidth + ", height=" + settings.dynamicHeight + '"', false) |
| 36 | + } |
| 37 | + } else { |
| 38 | + var popitWindow = window.open(settings.url, settings.name, "location=0, menubar=0, status=0, toolbar=0, width=" + settings.defaultWidth + ", height=" + settings.defaultHeight + '"', false) |
| 39 | + } |
| 40 | + |
| 41 | + // Brings the new window to the front |
| 42 | + popitWindow.focus(); |
| 43 | + |
| 44 | + // Reloads window to process JS like location.hash for playlist index in named windows |
| 45 | + var isFirefox = navigator.userAgent.toLowerCase().indexOf("firefox") > -1; |
| 46 | + if (!isFirefox) popitWindow.location.reload(); |
| 47 | + if (isFirefox) popitWindow.history.go(0); |
| 48 | + return popitWindow; |
| 49 | + }; |
| 50 | + |
| 51 | + settings.popup.on("click.popit", show); |
| 52 | + }); |
| 53 | +}; |
0 commit comments