1/* 2* File: jquery.simplePopup.js 3* Version: 1.0.0 4* Description: Create a simple popup to display content 5* Author: 9bit Studios 6* Copyright 2012, 9bit Studios 7* http://www.9bitstudios.com 8* Free to use and abuse under the MIT license. 9* http://www.opensource.org/licenses/mit-license.php 10*/ 11 12(function ($) { 13 14 $.fn.simplePopup = function (options) { 15 16 var defaults = $.extend({ 17 centerPopup: true, 18 open: function() {}, 19 closed: function() {} 20 }, options); 21 22 /****************************** 23 Private Variables 24 *******************************/ 25 26 var object = $(this); 27 var settings = $.extend(defaults, options); 28 29 /****************************** 30 Public Methods 31 *******************************/ 32 33 var methods = { 34 35 init: function() { 36 return this.each(function () { 37 methods.appendHTML(); 38 methods.setEventHandlers(); 39 methods.showPopup(); 40 }); 41 }, 42 43 /****************************** 44 Append HTML 45 *******************************/ 46 47 appendHTML: function() { 48 49 // if this has already been added we don't need to add it again 50 if ($('.simplePopupBackground').length === 0) { 51 var background = '<div class="simplePopupBackground"></div>'; 52 $('body').prepend(background); 53 } 54 55 if(object.find('.simplePopupClose').length === 0) { 56 var close = '<div class="simplePopupClose">X</div>'; 57 object.prepend(close); 58 } 59 }, 60 61 /****************************** 62 Set Event Handlers 63 *******************************/ 64 65 setEventHandlers: function() { 66 67 $(".simplePopupClose, .simplePopupBackground").on("click", function (event) { 68 methods.hidePopup(); 69 }); 70 71 $(window).on("resize", function(event){ 72 73 if(settings.centerPopup) { 74 methods.positionPopup(); 75 } 76 }); 77 78 }, 79 80 removeEventListners: function() { 81 $(".simplePopupClose, .simplePopupBackground").off("click"); 82 }, 83 84 showPopup: function() { 85 $(".simplePopupBackground").css({ 86 "opacity": "0.7" 87 }); 88 89 $(".simplePopupBackground").fadeIn("fast"); 90 91 object.fadeIn("slow", function(){ 92 settings.open(); 93 }); 94 95 if(settings.centerPopup) { 96 methods.positionPopup(); 97 } 98 }, 99 100 hidePopup: function() { 101 $(".simplePopupBackground").fadeOut("fast"); 102 object.fadeOut("fast", function(){ 103 methods.removeEventListners(); 104 settings.closed(); 105 }); 106 }, 107 108 positionPopup: function() { 109 var windowWidth = $(window).width(); 110 var windowHeight = $(window).height(); 111 var popupWidth = object.width(); 112 var popupHeight = object.height(); 113 114 var topPos = (windowHeight / 2) - (popupHeight / 2); 115 var leftPos = (windowWidth / 2) - (popupWidth / 2); 116 if(topPos < 30) topPos = 30; 117 118 object.css({ 119 "position": "absolute", 120 "top": topPos, 121 "left": leftPos 122 }); 123 }, 124 125 }; 126 127 if (methods[options]) { // $("#element").pluginName('methodName', 'arg1', 'arg2'); 128 return methods[options].apply(this, Array.prototype.slice.call(arguments, 1)); 129 } else if (typeof options === 'object' || !options) { // $("#element").pluginName({ option: 1, option:2 }); 130 return methods.init.apply(this); 131 } else { 132 $.error( 'Method "' + method + '" does not exist in simple popup plugin!'); 133 } 134 }; 135 136})(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.