less-rails-liftkit 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. data/.gitignore +7 -0
  2. data/.travis.yml +5 -0
  3. data/Gemfile +5 -0
  4. data/README.md +0 -0
  5. data/Rakefile +14 -0
  6. data/less-rails-liftkit.gemspec +19 -0
  7. data/lib/less/rails/liftkit/engine.rb +13 -0
  8. data/lib/less/rails/liftkit/version.rb +7 -0
  9. data/lib/less/rails/liftkit.rb +2 -0
  10. data/lib/less-rails-liftkit.rb +9 -0
  11. data/vendor/assets/javascripts/lift/liftkit/plugins/jquery.blockify.js +86 -0
  12. data/vendor/assets/javascripts/lift/liftkit/plugins/jquery.cycle.js +1503 -0
  13. data/vendor/assets/javascripts/lift/liftkit/plugins/jquery.dropdown.js +71 -0
  14. data/vendor/assets/javascripts/lift/liftkit/plugins/jquery.hashchange.js +390 -0
  15. data/vendor/assets/javascripts/lift/liftkit/plugins/jquery.modal.js +133 -0
  16. data/vendor/assets/javascripts/lift/liftkit/plugins/jquery.placeholder.js +106 -0
  17. data/vendor/assets/javascripts/lift/liftkit/plugins/jquery.stickybox.js +116 -0
  18. data/vendor/assets/javascripts/lift/liftkit/plugins/jquery.tabs.js +119 -0
  19. data/vendor/assets/javascripts/lift/liftkit/script.js +59 -0
  20. data/vendor/assets/javascripts/lift/liftkit/underscore.js +34 -0
  21. data/vendor/assets/javascripts/lift/liftkit.js +3 -0
  22. data/vendor/assets/stylesheets/lift/liftkit.css.less +1 -0
  23. data/vendor/frameworks/lift/liftkit/alerts.less +104 -0
  24. data/vendor/frameworks/lift/liftkit/buttons.less +160 -0
  25. data/vendor/frameworks/lift/liftkit/core.less +345 -0
  26. data/vendor/frameworks/lift/liftkit/fluid.less +93 -0
  27. data/vendor/frameworks/lift/liftkit/forms.less +401 -0
  28. data/vendor/frameworks/lift/liftkit/liftkit.less +64 -0
  29. data/vendor/frameworks/lift/liftkit/modal.less +34 -0
  30. data/vendor/frameworks/lift/liftkit/navigation.less +159 -0
  31. data/vendor/frameworks/lift/liftkit/responsive-fixed.less +238 -0
  32. data/vendor/frameworks/lift/liftkit/responsive-fluid.less +89 -0
  33. data/vendor/frameworks/lift/liftkit/scaffolding.less +116 -0
  34. data/vendor/frameworks/lift/liftkit/tables.less +54 -0
  35. data/vendor/frameworks/lift/liftkit/type.less +272 -0
  36. data/vendor/frameworks/lift/liftkit.less +1 -0
  37. metadata +114 -0
@@ -0,0 +1,71 @@
1
+ /*!
2
+ * jQuery Dropdown Plugin
3
+ * Copyright (c) 2010 Eli Dupuis
4
+ * Version: 0.3 (Sept 1, 2010)
5
+ * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL (http://creativecommons.org/licenses/GPL/2.0/) licenses.
6
+ * Requires: jQuery v1.4.2 or later
7
+ * Based heavily on snippet from (Steve Taylor) http://sltaylor.co.uk/blog/jquery-hover-drop-down-menu-settimeout/
8
+ */
9
+
10
+ (function($) {
11
+
12
+ var ver = '0.3';
13
+
14
+ $.fn.dropdown = function(options) {
15
+
16
+ // build main options before element iteration
17
+ var opts = $.extend({}, $.fn.dropdown.defaults, options),
18
+ navTimers = [];
19
+
20
+ return this.each(function() {
21
+ $this = $(this);
22
+ // build element specific options
23
+ var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
24
+
25
+ if (opts.mozRemoveTitleAttr) {
26
+ // start firefox glitch fix:
27
+ // remove title attributes because they interfere with the hover() in Firefox:
28
+ // http://dev.jquery.com/ticket/5290
29
+ if ($.browser.mozilla) {
30
+ $this.removeAttr('title');
31
+ $this.find('*[title]').each(function(){
32
+ $(this).removeAttr('title');
33
+ });
34
+ }
35
+ // end firefox glitch fix.
36
+ };
37
+
38
+ $this.hover(
39
+ function (e) {
40
+ var id = $.data(this), $this = $(this);
41
+ navTimers[id] = setTimeout( function() {
42
+ $this.find(o.child).fadeIn(o.speedIn);
43
+ navTimers[id] = "";
44
+ }, o.delay );
45
+ }, function (e) {
46
+ var id = $.data(this);
47
+ if (navTimers[id] != "") {
48
+ clearTimeout(navTimers[id]);
49
+ } else {
50
+ $(this).find(o.child).fadeOut(o.speedOut);
51
+ }
52
+ });
53
+
54
+ });
55
+ };
56
+
57
+ //
58
+ // plugin defaults
59
+ //
60
+ $.fn.dropdown.defaults = {
61
+ delay: 100,
62
+ speedIn: 200,
63
+ speedOut: 150,
64
+ child: 'ul',
65
+ mozRemoveTitleAttr: true
66
+ };
67
+
68
+ // public function/method
69
+ $.fn.dropdown.ver = function() { return "jquery.dropdown version " + ver; };
70
+
71
+ })(jQuery);
@@ -0,0 +1,390 @@
1
+ /*!
2
+ * jQuery hashchange event - v1.3 - 7/21/2010
3
+ * http://benalman.com/projects/jquery-hashchange-plugin/
4
+ *
5
+ * Copyright (c) 2010 "Cowboy" Ben Alman
6
+ * Dual licensed under the MIT and GPL licenses.
7
+ * http://benalman.com/about/license/
8
+ */
9
+
10
+ // Script: jQuery hashchange event
11
+ //
12
+ // *Version: 1.3, Last updated: 7/21/2010*
13
+ //
14
+ // Project Home - http://benalman.com/projects/jquery-hashchange-plugin/
15
+ // GitHub - http://github.com/cowboy/jquery-hashchange/
16
+ // Source - http://github.com/cowboy/jquery-hashchange/raw/master/jquery.ba-hashchange.js
17
+ // (Minified) - http://github.com/cowboy/jquery-hashchange/raw/master/jquery.ba-hashchange.min.js (0.8kb gzipped)
18
+ //
19
+ // About: License
20
+ //
21
+ // Copyright (c) 2010 "Cowboy" Ben Alman,
22
+ // Dual licensed under the MIT and GPL licenses.
23
+ // http://benalman.com/about/license/
24
+ //
25
+ // About: Examples
26
+ //
27
+ // These working examples, complete with fully commented code, illustrate a few
28
+ // ways in which this plugin can be used.
29
+ //
30
+ // hashchange event - http://benalman.com/code/projects/jquery-hashchange/examples/hashchange/
31
+ // document.domain - http://benalman.com/code/projects/jquery-hashchange/examples/document_domain/
32
+ //
33
+ // About: Support and Testing
34
+ //
35
+ // Information about what version or versions of jQuery this plugin has been
36
+ // tested with, what browsers it has been tested in, and where the unit tests
37
+ // reside (so you can test it yourself).
38
+ //
39
+ // jQuery Versions - 1.2.6, 1.3.2, 1.4.1, 1.4.2
40
+ // Browsers Tested - Internet Explorer 6-8, Firefox 2-4, Chrome 5-6, Safari 3.2-5,
41
+ // Opera 9.6-10.60, iPhone 3.1, Android 1.6-2.2, BlackBerry 4.6-5.
42
+ // Unit Tests - http://benalman.com/code/projects/jquery-hashchange/unit/
43
+ //
44
+ // About: Known issues
45
+ //
46
+ // While this jQuery hashchange event implementation is quite stable and
47
+ // robust, there are a few unfortunate browser bugs surrounding expected
48
+ // hashchange event-based behaviors, independent of any JavaScript
49
+ // window.onhashchange abstraction. See the following examples for more
50
+ // information:
51
+ //
52
+ // Chrome: Back Button - http://benalman.com/code/projects/jquery-hashchange/examples/bug-chrome-back-button/
53
+ // Firefox: Remote XMLHttpRequest - http://benalman.com/code/projects/jquery-hashchange/examples/bug-firefox-remote-xhr/
54
+ // WebKit: Back Button in an Iframe - http://benalman.com/code/projects/jquery-hashchange/examples/bug-webkit-hash-iframe/
55
+ // Safari: Back Button from a different domain - http://benalman.com/code/projects/jquery-hashchange/examples/bug-safari-back-from-diff-domain/
56
+ //
57
+ // Also note that should a browser natively support the window.onhashchange
58
+ // event, but not report that it does, the fallback polling loop will be used.
59
+ //
60
+ // About: Release History
61
+ //
62
+ // 1.3 - (7/21/2010) Reorganized IE6/7 Iframe code to make it more
63
+ // "removable" for mobile-only development. Added IE6/7 document.title
64
+ // support. Attempted to make Iframe as hidden as possible by using
65
+ // techniques from http://www.paciellogroup.com/blog/?p=604. Added
66
+ // support for the "shortcut" format $(window).hashchange( fn ) and
67
+ // $(window).hashchange() like jQuery provides for built-in events.
68
+ // Renamed jQuery.hashchangeDelay to <jQuery.fn.hashchange.delay> and
69
+ // lowered its default value to 50. Added <jQuery.fn.hashchange.domain>
70
+ // and <jQuery.fn.hashchange.src> properties plus document-domain.html
71
+ // file to address access denied issues when setting document.domain in
72
+ // IE6/7.
73
+ // 1.2 - (2/11/2010) Fixed a bug where coming back to a page using this plugin
74
+ // from a page on another domain would cause an error in Safari 4. Also,
75
+ // IE6/7 Iframe is now inserted after the body (this actually works),
76
+ // which prevents the page from scrolling when the event is first bound.
77
+ // Event can also now be bound before DOM ready, but it won't be usable
78
+ // before then in IE6/7.
79
+ // 1.1 - (1/21/2010) Incorporated document.documentMode test to fix IE8 bug
80
+ // where browser version is incorrectly reported as 8.0, despite
81
+ // inclusion of the X-UA-Compatible IE=EmulateIE7 meta tag.
82
+ // 1.0 - (1/9/2010) Initial Release. Broke out the jQuery BBQ event.special
83
+ // window.onhashchange functionality into a separate plugin for users
84
+ // who want just the basic event & back button support, without all the
85
+ // extra awesomeness that BBQ provides. This plugin will be included as
86
+ // part of jQuery BBQ, but also be available separately.
87
+
88
+ (function($,window,undefined){
89
+ '$:nomunge'; // Used by YUI compressor.
90
+
91
+ // Reused string.
92
+ var str_hashchange = 'hashchange',
93
+
94
+ // Method / object references.
95
+ doc = document,
96
+ fake_onhashchange,
97
+ special = $.event.special,
98
+
99
+ // Does the browser support window.onhashchange? Note that IE8 running in
100
+ // IE7 compatibility mode reports true for 'onhashchange' in window, even
101
+ // though the event isn't supported, so also test document.documentMode.
102
+ doc_mode = doc.documentMode,
103
+ supports_onhashchange = 'on' + str_hashchange in window && ( doc_mode === undefined || doc_mode > 7 );
104
+
105
+ // Get location.hash (or what you'd expect location.hash to be) sans any
106
+ // leading #. Thanks for making this necessary, Firefox!
107
+ function get_fragment( url ) {
108
+ url = url || location.href;
109
+ return '#' + url.replace( /^[^#]*#?(.*)$/, '$1' );
110
+ };
111
+
112
+ // Method: jQuery.fn.hashchange
113
+ //
114
+ // Bind a handler to the window.onhashchange event or trigger all bound
115
+ // window.onhashchange event handlers. This behavior is consistent with
116
+ // jQuery's built-in event handlers.
117
+ //
118
+ // Usage:
119
+ //
120
+ // > jQuery(window).hashchange( [ handler ] );
121
+ //
122
+ // Arguments:
123
+ //
124
+ // handler - (Function) Optional handler to be bound to the hashchange
125
+ // event. This is a "shortcut" for the more verbose form:
126
+ // jQuery(window).bind( 'hashchange', handler ). If handler is omitted,
127
+ // all bound window.onhashchange event handlers will be triggered. This
128
+ // is a shortcut for the more verbose
129
+ // jQuery(window).trigger( 'hashchange' ). These forms are described in
130
+ // the <hashchange event> section.
131
+ //
132
+ // Returns:
133
+ //
134
+ // (jQuery) The initial jQuery collection of elements.
135
+
136
+ // Allow the "shortcut" format $(elem).hashchange( fn ) for binding and
137
+ // $(elem).hashchange() for triggering, like jQuery does for built-in events.
138
+ $.fn[ str_hashchange ] = function( fn ) {
139
+ return fn ? this.bind( str_hashchange, fn ) : this.trigger( str_hashchange );
140
+ };
141
+
142
+ // Property: jQuery.fn.hashchange.delay
143
+ //
144
+ // The numeric interval (in milliseconds) at which the <hashchange event>
145
+ // polling loop executes. Defaults to 50.
146
+
147
+ // Property: jQuery.fn.hashchange.domain
148
+ //
149
+ // If you're setting document.domain in your JavaScript, and you want hash
150
+ // history to work in IE6/7, not only must this property be set, but you must
151
+ // also set document.domain BEFORE jQuery is loaded into the page. This
152
+ // property is only applicable if you are supporting IE6/7 (or IE8 operating
153
+ // in "IE7 compatibility" mode).
154
+ //
155
+ // In addition, the <jQuery.fn.hashchange.src> property must be set to the
156
+ // path of the included "document-domain.html" file, which can be renamed or
157
+ // modified if necessary (note that the document.domain specified must be the
158
+ // same in both your main JavaScript as well as in this file).
159
+ //
160
+ // Usage:
161
+ //
162
+ // jQuery.fn.hashchange.domain = document.domain;
163
+
164
+ // Property: jQuery.fn.hashchange.src
165
+ //
166
+ // If, for some reason, you need to specify an Iframe src file (for example,
167
+ // when setting document.domain as in <jQuery.fn.hashchange.domain>), you can
168
+ // do so using this property. Note that when using this property, history
169
+ // won't be recorded in IE6/7 until the Iframe src file loads. This property
170
+ // is only applicable if you are supporting IE6/7 (or IE8 operating in "IE7
171
+ // compatibility" mode).
172
+ //
173
+ // Usage:
174
+ //
175
+ // jQuery.fn.hashchange.src = 'path/to/file.html';
176
+
177
+ $.fn[ str_hashchange ].delay = 50;
178
+ /*
179
+ $.fn[ str_hashchange ].domain = null;
180
+ $.fn[ str_hashchange ].src = null;
181
+ */
182
+
183
+ // Event: hashchange event
184
+ //
185
+ // Fired when location.hash changes. In browsers that support it, the native
186
+ // HTML5 window.onhashchange event is used, otherwise a polling loop is
187
+ // initialized, running every <jQuery.fn.hashchange.delay> milliseconds to
188
+ // see if the hash has changed. In IE6/7 (and IE8 operating in "IE7
189
+ // compatibility" mode), a hidden Iframe is created to allow the back button
190
+ // and hash-based history to work.
191
+ //
192
+ // Usage as described in <jQuery.fn.hashchange>:
193
+ //
194
+ // > // Bind an event handler.
195
+ // > jQuery(window).hashchange( function(e) {
196
+ // > var hash = location.hash;
197
+ // > ...
198
+ // > });
199
+ // >
200
+ // > // Manually trigger the event handler.
201
+ // > jQuery(window).hashchange();
202
+ //
203
+ // A more verbose usage that allows for event namespacing:
204
+ //
205
+ // > // Bind an event handler.
206
+ // > jQuery(window).bind( 'hashchange', function(e) {
207
+ // > var hash = location.hash;
208
+ // > ...
209
+ // > });
210
+ // >
211
+ // > // Manually trigger the event handler.
212
+ // > jQuery(window).trigger( 'hashchange' );
213
+ //
214
+ // Additional Notes:
215
+ //
216
+ // * The polling loop and Iframe are not created until at least one handler
217
+ // is actually bound to the 'hashchange' event.
218
+ // * If you need the bound handler(s) to execute immediately, in cases where
219
+ // a location.hash exists on page load, via bookmark or page refresh for
220
+ // example, use jQuery(window).hashchange() or the more verbose
221
+ // jQuery(window).trigger( 'hashchange' ).
222
+ // * The event can be bound before DOM ready, but since it won't be usable
223
+ // before then in IE6/7 (due to the necessary Iframe), recommended usage is
224
+ // to bind it inside a DOM ready handler.
225
+
226
+ // Override existing $.event.special.hashchange methods (allowing this plugin
227
+ // to be defined after jQuery BBQ in BBQ's source code).
228
+ special[ str_hashchange ] = $.extend( special[ str_hashchange ], {
229
+
230
+ // Called only when the first 'hashchange' event is bound to window.
231
+ setup: function() {
232
+ // If window.onhashchange is supported natively, there's nothing to do..
233
+ if ( supports_onhashchange ) { return false; }
234
+
235
+ // Otherwise, we need to create our own. And we don't want to call this
236
+ // until the user binds to the event, just in case they never do, since it
237
+ // will create a polling loop and possibly even a hidden Iframe.
238
+ $( fake_onhashchange.start );
239
+ },
240
+
241
+ // Called only when the last 'hashchange' event is unbound from window.
242
+ teardown: function() {
243
+ // If window.onhashchange is supported natively, there's nothing to do..
244
+ if ( supports_onhashchange ) { return false; }
245
+
246
+ // Otherwise, we need to stop ours (if possible).
247
+ $( fake_onhashchange.stop );
248
+ }
249
+
250
+ });
251
+
252
+ // fake_onhashchange does all the work of triggering the window.onhashchange
253
+ // event for browsers that don't natively support it, including creating a
254
+ // polling loop to watch for hash changes and in IE 6/7 creating a hidden
255
+ // Iframe to enable back and forward.
256
+ fake_onhashchange = (function(){
257
+ var self = {},
258
+ timeout_id,
259
+
260
+ // Remember the initial hash so it doesn't get triggered immediately.
261
+ last_hash = get_fragment(),
262
+
263
+ fn_retval = function(val){ return val; },
264
+ history_set = fn_retval,
265
+ history_get = fn_retval;
266
+
267
+ // Start the polling loop.
268
+ self.start = function() {
269
+ timeout_id || poll();
270
+ };
271
+
272
+ // Stop the polling loop.
273
+ self.stop = function() {
274
+ timeout_id && clearTimeout( timeout_id );
275
+ timeout_id = undefined;
276
+ };
277
+
278
+ // This polling loop checks every $.fn.hashchange.delay milliseconds to see
279
+ // if location.hash has changed, and triggers the 'hashchange' event on
280
+ // window when necessary.
281
+ function poll() {
282
+ var hash = get_fragment(),
283
+ history_hash = history_get( last_hash );
284
+
285
+ if ( hash !== last_hash ) {
286
+ history_set( last_hash = hash, history_hash );
287
+
288
+ $(window).trigger( str_hashchange );
289
+
290
+ } else if ( history_hash !== last_hash ) {
291
+ location.href = location.href.replace( /#.*/, '' ) + history_hash;
292
+ }
293
+
294
+ timeout_id = setTimeout( poll, $.fn[ str_hashchange ].delay );
295
+ };
296
+
297
+ // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
298
+ // vvvvvvvvvvvvvvvvvvv REMOVE IF NOT SUPPORTING IE6/7/8 vvvvvvvvvvvvvvvvvvv
299
+ // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
300
+ $.browser.msie && !supports_onhashchange && (function(){
301
+ // Not only do IE6/7 need the "magical" Iframe treatment, but so does IE8
302
+ // when running in "IE7 compatibility" mode.
303
+
304
+ var iframe,
305
+ iframe_src;
306
+
307
+ // When the event is bound and polling starts in IE 6/7, create a hidden
308
+ // Iframe for history handling.
309
+ self.start = function(){
310
+ if ( !iframe ) {
311
+ iframe_src = $.fn[ str_hashchange ].src;
312
+ iframe_src = iframe_src && iframe_src + get_fragment();
313
+
314
+ // Create hidden Iframe. Attempt to make Iframe as hidden as possible
315
+ // by using techniques from http://www.paciellogroup.com/blog/?p=604.
316
+ iframe = $('<iframe tabindex="-1" title="empty"/>').hide()
317
+
318
+ // When Iframe has completely loaded, initialize the history and
319
+ // start polling.
320
+ .one( 'load', function(){
321
+ iframe_src || history_set( get_fragment() );
322
+ poll();
323
+ })
324
+
325
+ // Load Iframe src if specified, otherwise nothing.
326
+ .attr( 'src', iframe_src || 'javascript:0' )
327
+
328
+ // Append Iframe after the end of the body to prevent unnecessary
329
+ // initial page scrolling (yes, this works).
330
+ .insertAfter( 'body' )[0].contentWindow;
331
+
332
+ // Whenever `document.title` changes, update the Iframe's title to
333
+ // prettify the back/next history menu entries. Since IE sometimes
334
+ // errors with "Unspecified error" the very first time this is set
335
+ // (yes, very useful) wrap this with a try/catch block.
336
+ doc.onpropertychange = function(){
337
+ try {
338
+ if ( event.propertyName === 'title' ) {
339
+ iframe.document.title = doc.title;
340
+ }
341
+ } catch(e) {}
342
+ };
343
+
344
+ }
345
+ };
346
+
347
+ // Override the "stop" method since an IE6/7 Iframe was created. Even
348
+ // if there are no longer any bound event handlers, the polling loop
349
+ // is still necessary for back/next to work at all!
350
+ self.stop = fn_retval;
351
+
352
+ // Get history by looking at the hidden Iframe's location.hash.
353
+ history_get = function() {
354
+ return get_fragment( iframe.location.href );
355
+ };
356
+
357
+ // Set a new history item by opening and then closing the Iframe
358
+ // document, *then* setting its location.hash. If document.domain has
359
+ // been set, update that as well.
360
+ history_set = function( hash, history_hash ) {
361
+ var iframe_doc = iframe.document,
362
+ domain = $.fn[ str_hashchange ].domain;
363
+
364
+ if ( hash !== history_hash ) {
365
+ // Update Iframe with any initial `document.title` that might be set.
366
+ iframe_doc.title = doc.title;
367
+
368
+ // Opening the Iframe's document after it has been closed is what
369
+ // actually adds a history entry.
370
+ iframe_doc.open();
371
+
372
+ // Set document.domain for the Iframe document as well, if necessary.
373
+ domain && iframe_doc.write( '<script>document.domain="' + domain + '"</script>' );
374
+
375
+ iframe_doc.close();
376
+
377
+ // Update the Iframe's hash, for great justice.
378
+ iframe.location.hash = hash;
379
+ }
380
+ };
381
+
382
+ })();
383
+ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
384
+ // ^^^^^^^^^^^^^^^^^^^ REMOVE IF NOT SUPPORTING IE6/7/8 ^^^^^^^^^^^^^^^^^^^
385
+ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
386
+
387
+ return self;
388
+ })();
389
+
390
+ })(jQuery,this);
@@ -0,0 +1,133 @@
1
+ /*
2
+ A simple jQuery modal (http://github.com/kylefox/jquery-modal)
3
+ Version 0.2.4
4
+ */
5
+ (function() {
6
+
7
+ var current_modal = null;
8
+
9
+ $.fn.modal = function(options) {
10
+
11
+ var $elm = $(this);
12
+
13
+ // If this is a link, bind to its click event.
14
+ if($elm.attr('href')) {
15
+ $elm.click(open_modal_from_link);
16
+ return;
17
+ }
18
+
19
+ options = $.extend({}, $.fn.modal.defaults, options);
20
+
21
+ function block() {
22
+ current_modal.blocker = $('<div class="jquery-modal blocker"></div>').css({
23
+ top: 0, right: 0, bottom: 0, left: 0,
24
+ width: "100%", height: "100%",
25
+ position: "fixed",
26
+ zIndex: options.zIndex,
27
+ background: options.overlay,
28
+ opacity: options.opacity
29
+ });
30
+ if(options.escapeClose) {
31
+ $(document).bind('keydown.modal', function(event) {
32
+ if(event.which == 27) {$.fn.modal.close();}
33
+ });
34
+ }
35
+ if(options.clickClose) {
36
+ current_modal.blocker.click($.fn.modal.close);
37
+ }
38
+ $('body').append(current_modal.blocker);
39
+ $elm.trigger($.fn.modal.BLOCK, [current_modal]);
40
+ }
41
+
42
+ function show() {
43
+ center_modal(current_modal);
44
+ if(options.showClose) {
45
+ current_modal.closeButton = $('<a href="#close-modal" rel="modal:close" class="close-modal">' + options.closeText + '</a>');
46
+ current_modal.elm.append(current_modal.closeButton);
47
+ }
48
+ $elm.addClass(options.modalClass + ' current').show();
49
+ $elm.trigger($.fn.modal.OPEN, [current_modal]);
50
+ }
51
+
52
+ current_modal = {elm: $elm, options: options};
53
+ $elm.trigger($.fn.modal.BEFORE_BLOCK, [current_modal]);
54
+ block();
55
+ $elm.trigger($.fn.modal.BEFORE_OPEN, [current_modal]);
56
+ show();
57
+ };
58
+
59
+ $.fn.modal.defaults = {
60
+ overlay: "#000",
61
+ opacity: 0.75,
62
+ zIndex: 1,
63
+ escapeClose: true,
64
+ clickClose: true,
65
+ closeText: 'Close',
66
+ modalClass: "modal",
67
+ showClose: true
68
+ };
69
+
70
+ // Event constants:
71
+ $.fn.modal.BEFORE_BLOCK = 'modal:before-block';
72
+ $.fn.modal.BLOCK = 'modal:block';
73
+ $.fn.modal.BEFORE_OPEN = 'modal:before-open';
74
+ $.fn.modal.OPEN = 'modal:open';
75
+ $.fn.modal.BEFORE_CLOSE = 'modal:before-close';
76
+ $.fn.modal.CLOSE = 'modal:close';
77
+
78
+ $.fn.modal.close = function(event) {
79
+ if(event) {
80
+ event.preventDefault();
81
+ }
82
+ if(!current_modal) {
83
+ return;
84
+ }
85
+
86
+ current_modal.elm.trigger($.fn.modal.BEFORE_CLOSE, [current_modal]);
87
+ if(current_modal.closeButton) {
88
+ current_modal.closeButton.remove();
89
+ }
90
+ current_modal.blocker.remove();
91
+ current_modal.elm.removeClass('current').hide();
92
+ current_modal.elm.trigger($.fn.modal.CLOSE, [current_modal]);
93
+ current_modal = null;
94
+
95
+ $(document).unbind('keydown.modal');
96
+ };
97
+
98
+ $.fn.modal.resize = function() {
99
+ center_modal(current_modal);
100
+ };
101
+
102
+ function open_modal_from_link(event) {
103
+ event.preventDefault();
104
+ var target = $(this).attr('href');
105
+ if(/^#/.test(target)) { // DOM id
106
+ $(target).modal();
107
+ } else { // AJAX
108
+ $.get(target, {}, function(html) {
109
+ $('<div/>')
110
+ .html(html)
111
+ .appendTo('body')
112
+ .bind('modal:close', function(event, modal) { modal.elm.remove(); })
113
+ .modal();
114
+ });
115
+ }
116
+ }
117
+
118
+ function center_modal(modal) {
119
+ modal.elm.css({
120
+ position: 'fixed',
121
+ top: "50%",
122
+ left: "50%",
123
+ marginTop: - (modal.elm.outerHeight() / 2),
124
+ marginLeft: - (modal.elm.outerWidth() / 2),
125
+ zIndex: modal.options.zIndex + 1
126
+ });
127
+ };
128
+
129
+ // Automatically bind links with rel="modal:close" to, well, close the modal.
130
+ $('a[rel="modal:open"]').live('click', open_modal_from_link);
131
+ $('a[rel="modal:close"]').live('click', $.fn.modal.close);
132
+
133
+ })();