|
| 1 | +# JQuery My Fancy Light Box |
| 2 | + |
| 3 | +> Original Repos: |
| 4 | +> - JQuery My Fancy Light Box: https://github.com/a19836/jquerymyfancylightbox/ |
| 5 | +> - Bloxtor: https://github.com/a19836/bloxtor/ |
| 6 | +
|
| 7 | +## Overview |
| 8 | + |
| 9 | +**JQuery My Fancy Light Box** is a lightweight JavaScript library to display popups. |
| 10 | + |
| 11 | +Check out a live example by opening [index.html](index.html). |
| 12 | + |
| 13 | +Requirements: |
| 14 | +- jquery library |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## Screenshots |
| 19 | + |
| 20 | +- [example 1](./img/example_1.png) |
| 21 | +- [example 2](./img/example_2.png) |
| 22 | +- [example 3](./img/example_3.png) |
| 23 | +- [example 4](./img/example_4.png) |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```html |
| 30 | +<html> |
| 31 | +<head> |
| 32 | + <!-- Add jquery lib --> |
| 33 | + <script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> |
| 34 | + |
| 35 | + <!-- Add Fancy LighBox lib --> |
| 36 | + <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" media="screen, projection" /> |
| 37 | + <script language="javascript" type="text/javascript" src="js/jquery.myfancybox.js"></script> |
| 38 | + |
| 39 | + <style> |
| 40 | + a {margin-bottom:10px; display:block;} |
| 41 | + .myfancypopup.yellow { background:yellow; } |
| 42 | + </style> |
| 43 | + <script> |
| 44 | + var MyFancyPopup2 = null; |
| 45 | + |
| 46 | + function showPopup1() { |
| 47 | + MyFancyPopup.init({ |
| 48 | + elementToShow: $('#popup1') |
| 49 | + }); |
| 50 | + MyFancyPopup.showPopup({ |
| 51 | + not_draggable: true |
| 52 | + }); |
| 53 | + } |
| 54 | + function showPopup2() { |
| 55 | + MyFancyPopup.init({ |
| 56 | + elementToShow: $('#popup2') |
| 57 | + }); |
| 58 | + MyFancyPopup.showPopup(); |
| 59 | + } |
| 60 | + function showPopup3() { |
| 61 | + if (!MyFancyPopup2) { |
| 62 | + MyFancyPopup2 = new MyFancyPopupClass(); |
| 63 | + MyFancyPopup2.init({ |
| 64 | + elementToShow: $('#popup3'), |
| 65 | + parentElement: $('section').first(), |
| 66 | + type: "iframe", |
| 67 | + url: "iframe.html", |
| 68 | + refreshIframeOnOpen: true, |
| 69 | + popupClass: "yellow", |
| 70 | + onIframeOnLoad: function() { |
| 71 | + MyFancyPopup.hideLoading(); |
| 72 | + } |
| 73 | + }); |
| 74 | + } |
| 75 | + |
| 76 | + MyFancyPopup2.showPopup(); |
| 77 | + } |
| 78 | + </script> |
| 79 | +</head> |
| 80 | +<body> |
| 81 | + <div id="popup1" class="myfancypopup"> |
| 82 | + <div class="title">NOT Draggable Popup</div> |
| 83 | + <p class="content">CONTENT HERE</p> |
| 84 | + </div> |
| 85 | + |
| 86 | + <div id="popup2" class="myfancypopup"> |
| 87 | + <h1>Draggable Popup with inline iframe</h1> |
| 88 | + <iframe src="iframe.html"></iframe> |
| 89 | + </div> |
| 90 | + |
| 91 | + <section class="some_node"> |
| 92 | + <div id="popup3" class="myfancypopup"> |
| 93 | + <h1>Popup with auto iframe</h1> |
| 94 | + </div> |
| 95 | + </section> |
| 96 | + |
| 97 | + <a href="#" onClick="showPopup1();">CLICK HERE TO SEE POPUP 1</a> |
| 98 | + <a href="#" onClick="showPopup2();">CLICK HERE TO SEE POPUP 2</a> |
| 99 | + <a href="#" onClick="showPopup3();">CLICK HERE TO SEE POPUP 3</a> |
| 100 | +</body> |
| 101 | +</html> |
| 102 | +``` |
| 103 | + |
| 104 | +## Other calls |
| 105 | + |
| 106 | +Create new MyFancyPopup object: |
| 107 | +``` |
| 108 | +var MyFancyPopup2 = new MyFancyPopupClass(); |
| 109 | +``` |
| 110 | + |
| 111 | +Initialize MyFancyPopup based in a html element: |
| 112 | +``` |
| 113 | +MyFancyPopup.init({ |
| 114 | + elementToShow: $('#some_selector'), //html node that should be converted in a popup |
| 115 | + parentElement: document, //node where the overlay and loading will be appended |
| 116 | + onOpen: function() { ... }, //callback on popup open |
| 117 | + onClose: function() { ... }, //callback on popup close |
| 118 | + beforeClose: function() { ... }, //callback on before popup close |
| 119 | + popupClass: "some_class", //this call will be used in the elementToShow, loading and overlay nodes. |
| 120 | +}); |
| 121 | +``` |
| 122 | + |
| 123 | +Initialize MyFancyPopup based in a html element with a dynamic iframe: |
| 124 | +``` |
| 125 | +MyFancyPopup.init({ |
| 126 | + elementToShow: $('#some_selector'), //html node that should be converted in a popup |
| 127 | + parentElement: $('section').first(), //node where the overlay and loading will be appended |
| 128 | + type: "iframe", |
| 129 | + url: "iframe.html", //url for the iframe |
| 130 | + refreshIframeOnOpen: true, //if true, every time the popup open, it will refresh the iframe url |
| 131 | + onIframeUnLoad: function() { ... }, //callback on iframe unload |
| 132 | + onIframeBeforeUnLoad: function() { ... }, //callback on before iframe unload |
| 133 | + onIframeOnLoad: function() { ... }, //callback on iframe load |
| 134 | + onOpen: function() { ... }, //callback on popup open |
| 135 | + onClose: function() { ... }, //callback on popup close |
| 136 | + beforeClose: function() { ... }, //callback on before popup close |
| 137 | + popupClass: "some_class", //this call will be used in the elementToShow, loading and overlay nodes. |
| 138 | +}); |
| 139 | +``` |
| 140 | + |
| 141 | +Get initial settings when calling the init method: |
| 142 | +``` |
| 143 | +MyFancyPopup.settings; |
| 144 | +``` |
| 145 | + |
| 146 | +Show/open popup: |
| 147 | +``` |
| 148 | +var opts = { |
| 149 | + not_draggable: true //optional: if true, popup is not draggable. |
| 150 | +} |
| 151 | +MyFancyPopup.showPopup(opts); //opts are optional |
| 152 | +``` |
| 153 | + |
| 154 | +Reshow popup by hidding and showing it again: |
| 155 | +``` |
| 156 | +var opts = { |
| 157 | + not_draggable: true //optional: if true, popup is not draggable. |
| 158 | +} |
| 159 | +MyFancyPopup.reshowPopup(opts); //opts are optional |
| 160 | +``` |
| 161 | + |
| 162 | + |
| 163 | +Hide popup: |
| 164 | +``` |
| 165 | +MyFancyPopup.hidePopup(); |
| 166 | +``` |
| 167 | + |
| 168 | +Update popup position and overlay: |
| 169 | +``` |
| 170 | +MyFancyPopup.updatePopup(); |
| 171 | +``` |
| 172 | + |
| 173 | +Destroy popup and corresponding handlers: |
| 174 | +``` |
| 175 | +MyFancyPopup.destroyPopup(); |
| 176 | +``` |
| 177 | + |
| 178 | +Checks if popup is opened: |
| 179 | +``` |
| 180 | +var shown = MyFancyPopup.isPopupOpened(); |
| 181 | +``` |
| 182 | + |
| 183 | +Center popup: |
| 184 | +``` |
| 185 | +MyFancyPopup.centerPopupHtmlElm(elm, parent); //elm and parent are optional |
| 186 | +``` |
| 187 | + |
| 188 | +Get popup element corresponding to elementToShow: |
| 189 | +``` |
| 190 | +var popup = self.getPopup(); |
| 191 | +``` |
| 192 | + |
| 193 | +Reset the Z-index of the pop-up window by moving it to the front: |
| 194 | +``` |
| 195 | +MyFancyPopup.reinitZIndex(); |
| 196 | +``` |
| 197 | + |
| 198 | +Set an option: |
| 199 | +``` |
| 200 | +MyFancyPopup.setOption(option_name, option_value) |
| 201 | +``` |
| 202 | + |
| 203 | +Get an option: |
| 204 | +``` |
| 205 | +var option = MyFancyPopup.getOption = function(option_name) |
| 206 | +``` |
| 207 | + |
| 208 | +Get an element offset (top and left positions): |
| 209 | +``` |
| 210 | +var offset = MyFancyPopup.getOffset(elm); |
| 211 | +``` |
| 212 | + |
| 213 | +Get overlay element: |
| 214 | +``` |
| 215 | +var overlay = MyFancyPopup.getOverlay(); |
| 216 | +``` |
| 217 | + |
| 218 | +Show overlay: |
| 219 | +``` |
| 220 | +MyFancyPopup.showOverlay(); |
| 221 | +``` |
| 222 | + |
| 223 | +hide overlay: |
| 224 | +``` |
| 225 | +MyFancyPopup.hideOverlay(); |
| 226 | +``` |
| 227 | + |
| 228 | +Resize overlay and fits it to the screen or parent element depending of its css: |
| 229 | +``` |
| 230 | +MyFancyPopup.resizeOverlay(); |
| 231 | +``` |
| 232 | + |
| 233 | +Get loading icon node: |
| 234 | +``` |
| 235 | +var loading = MyFancyPopup.getLoading(); |
| 236 | +``` |
| 237 | + |
| 238 | +Show loading icon: |
| 239 | +``` |
| 240 | +MyFancyPopup.showLoading(); |
| 241 | +``` |
| 242 | + |
| 243 | +Hide loading icon: |
| 244 | +``` |
| 245 | +MyFancyPopup.hideLoading(); |
| 246 | +``` |
| 247 | + |
| 248 | +Get popup close button: |
| 249 | +``` |
| 250 | +var btn = MyFancyPopup.getPopupCloseButton(); |
| 251 | +``` |
| 252 | + |
| 253 | +Creates a close button if not exists and set the correspondent handler to close popup: |
| 254 | +``` |
| 255 | +MyFancyPopup.prepareElementCloseButton(); |
| 256 | +``` |
| 257 | + |
| 258 | +Creates iframe node if not exists and set the correspondent handlers and classes: |
| 259 | +``` |
| 260 | +MyFancyPopup.prepareElementIfIframe(); |
| 261 | +``` |
| 262 | + |
0 commit comments