colorbox-on-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in colorbox-on-rails.gemspec
4
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 John Resig, http://jquery.com/
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Colorbox on Rails
2
+
3
+ An asset gem pack the ColorBox jQuery Plugin (http://www.jacklmoore.com/colorbox)
4
+
5
+ ## Installation
6
+
7
+ Currently only support Rails 3.1
8
+
9
+ Add this line to `Gemfile`:
10
+
11
+ gem 'colorbox-on-rails', :git => 'git@github.com:zetachang/colorbox-on-rails.git'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ In `application.js`, add this line after `//=require jquery`:
20
+
21
+ //=require jquery.colorbox
22
+
23
+ In `application.css`, add this line after `=require_self`:
24
+
25
+ *= require colorbox
26
+
27
+ All the setting is done, the rest is up to you. For a simple use case, you can have a image link:
28
+
29
+ ```erb
30
+ <a href="<%= idea_post.photo.url %>" class="colorbox">
31
+ <%= image_tag idea_post.photo.url(:thumb), :class => 'photo' %>
32
+ </a>
33
+ ```
34
+
35
+ And invoke the colorbox in js file:
36
+
37
+ ```js
38
+ $('a.colorbox').colorbox()
39
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "colorbox-on-rails/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "colorbox-on-rails"
7
+ s.version = Colorbox::On::Rails::VERSION
8
+ s.authors = ["David Chang"]
9
+ s.email = ["zeta11235813@gmail.com"]
10
+ s.homepage = "http://github.com/zetachang/colorbox-on-rails"
11
+ s.summary = "An assets gem for jquery.colorbox integrating with Rails 3.1"
12
+ s.description = "An asset gem pack the ColorBox jQuery Plugin (http://www.jacklmoore.com/colorbox)"
13
+
14
+ s.rubyforge_project = "colorbox-on-rails"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
@@ -0,0 +1,6 @@
1
+ module ColorBox
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module Colorbox
2
+ module On
3
+ module Rails
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require "colorbox-on-rails/version"
2
+
3
+ module Colorbox
4
+ module On
5
+ module Rails
6
+ require "colorbox-on-rails/engine"
7
+ end
8
+ end
9
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,888 @@
1
+ // ColorBox v1.3.19 - jQuery lightbox plugin
2
+ // (c) 2011 Jack Moore - jacklmoore.com
3
+ // License: http://www.opensource.org/licenses/mit-license.php
4
+ (function ($, document, window) {
5
+ var
6
+ // Default settings object.
7
+ // See http://jacklmoore.com/colorbox for details.
8
+ defaults = {
9
+ transition: "elastic",
10
+ speed: 300,
11
+ width: false,
12
+ initialWidth: "600",
13
+ innerWidth: false,
14
+ maxWidth: false,
15
+ height: false,
16
+ initialHeight: "450",
17
+ innerHeight: false,
18
+ maxHeight: false,
19
+ scalePhotos: true,
20
+ scrolling: true,
21
+ inline: false,
22
+ html: false,
23
+ iframe: false,
24
+ fastIframe: true,
25
+ photo: false,
26
+ href: false,
27
+ title: false,
28
+ rel: false,
29
+ opacity: 0.9,
30
+ preloading: true,
31
+ current: "image {current} of {total}",
32
+ previous: "previous",
33
+ next: "next",
34
+ close: "close",
35
+ open: false,
36
+ returnFocus: true,
37
+ reposition: true,
38
+ loop: true,
39
+ slideshow: false,
40
+ slideshowAuto: true,
41
+ slideshowSpeed: 2500,
42
+ slideshowStart: "start slideshow",
43
+ slideshowStop: "stop slideshow",
44
+ onOpen: false,
45
+ onLoad: false,
46
+ onComplete: false,
47
+ onCleanup: false,
48
+ onClosed: false,
49
+ overlayClose: true,
50
+ escKey: true,
51
+ arrowKey: true,
52
+ top: false,
53
+ bottom: false,
54
+ left: false,
55
+ right: false,
56
+ fixed: false,
57
+ data: undefined
58
+ },
59
+
60
+ // Abstracting the HTML and event identifiers for easy rebranding
61
+ colorbox = 'colorbox',
62
+ prefix = 'cbox',
63
+ boxElement = prefix + 'Element',
64
+
65
+ // Events
66
+ event_open = prefix + '_open',
67
+ event_load = prefix + '_load',
68
+ event_complete = prefix + '_complete',
69
+ event_cleanup = prefix + '_cleanup',
70
+ event_closed = prefix + '_closed',
71
+ event_purge = prefix + '_purge',
72
+
73
+ // Special Handling for IE
74
+ isIE = !$.support.opacity && !$.support.style, // IE7 & IE8
75
+ isIE6 = isIE && !window.XMLHttpRequest, // IE6
76
+ event_ie6 = prefix + '_IE6',
77
+
78
+ // Cached jQuery Object Variables
79
+ $overlay,
80
+ $box,
81
+ $wrap,
82
+ $content,
83
+ $topBorder,
84
+ $leftBorder,
85
+ $rightBorder,
86
+ $bottomBorder,
87
+ $related,
88
+ $window,
89
+ $loaded,
90
+ $loadingBay,
91
+ $loadingOverlay,
92
+ $title,
93
+ $current,
94
+ $slideshow,
95
+ $next,
96
+ $prev,
97
+ $close,
98
+ $groupControls,
99
+
100
+ // Variables for cached values or use across multiple functions
101
+ settings,
102
+ interfaceHeight,
103
+ interfaceWidth,
104
+ loadedHeight,
105
+ loadedWidth,
106
+ element,
107
+ index,
108
+ photo,
109
+ open,
110
+ active,
111
+ closing,
112
+ loadingTimer,
113
+ publicMethod,
114
+ div = "div",
115
+ init;
116
+
117
+ // ****************
118
+ // HELPER FUNCTIONS
119
+ // ****************
120
+
121
+ // Convience function for creating new jQuery objects
122
+ function $tag(tag, id, css) {
123
+ var element = document.createElement(tag);
124
+
125
+ if (id) {
126
+ element.id = prefix + id;
127
+ }
128
+
129
+ if (css) {
130
+ element.style.cssText = css;
131
+ }
132
+
133
+ return $(element);
134
+ }
135
+
136
+ // Determine the next and previous members in a group.
137
+ function getIndex(increment) {
138
+ var
139
+ max = $related.length,
140
+ newIndex = (index + increment) % max;
141
+
142
+ return (newIndex < 0) ? max + newIndex : newIndex;
143
+ }
144
+
145
+ // Convert '%' and 'px' values to integers
146
+ function setSize(size, dimension) {
147
+ return Math.round((/%/.test(size) ? ((dimension === 'x' ? $window.width() : $window.height()) / 100) : 1) * parseInt(size, 10));
148
+ }
149
+
150
+ // Checks an href to see if it is a photo.
151
+ // There is a force photo option (photo: true) for hrefs that cannot be matched by this regex.
152
+ function isImage(url) {
153
+ return settings.photo || /\.(gif|png|jpe?g|bmp|ico)((#|\?).*)?$/i.test(url);
154
+ }
155
+
156
+ // Assigns function results to their respective properties
157
+ function makeSettings() {
158
+ var i;
159
+ settings = $.extend({}, $.data(element, colorbox));
160
+
161
+ for (i in settings) {
162
+ if ($.isFunction(settings[i]) && i.slice(0, 2) !== 'on') { // checks to make sure the function isn't one of the callbacks, they will be handled at the appropriate time.
163
+ settings[i] = settings[i].call(element);
164
+ }
165
+ }
166
+
167
+ settings.rel = settings.rel || element.rel || 'nofollow';
168
+ settings.href = settings.href || $(element).attr('href');
169
+ settings.title = settings.title || element.title;
170
+
171
+ if (typeof settings.href === "string") {
172
+ settings.href = $.trim(settings.href);
173
+ }
174
+ }
175
+
176
+ function trigger(event, callback) {
177
+ $.event.trigger(event);
178
+ if (callback) {
179
+ callback.call(element);
180
+ }
181
+ }
182
+
183
+ // Slideshow functionality
184
+ function slideshow() {
185
+ var
186
+ timeOut,
187
+ className = prefix + "Slideshow_",
188
+ click = "click." + prefix,
189
+ start,
190
+ stop,
191
+ clear;
192
+
193
+ if (settings.slideshow && $related[1]) {
194
+ start = function () {
195
+ $slideshow
196
+ .text(settings.slideshowStop)
197
+ .unbind(click)
198
+ .bind(event_complete, function () {
199
+ if (settings.loop || $related[index + 1]) {
200
+ timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
201
+ }
202
+ })
203
+ .bind(event_load, function () {
204
+ clearTimeout(timeOut);
205
+ })
206
+ .one(click + ' ' + event_cleanup, stop);
207
+ $box.removeClass(className + "off").addClass(className + "on");
208
+ timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
209
+ };
210
+
211
+ stop = function () {
212
+ clearTimeout(timeOut);
213
+ $slideshow
214
+ .text(settings.slideshowStart)
215
+ .unbind([event_complete, event_load, event_cleanup, click].join(' '))
216
+ .one(click, function () {
217
+ publicMethod.next();
218
+ start();
219
+ });
220
+ $box.removeClass(className + "on").addClass(className + "off");
221
+ };
222
+
223
+ if (settings.slideshowAuto) {
224
+ start();
225
+ } else {
226
+ stop();
227
+ }
228
+ } else {
229
+ $box.removeClass(className + "off " + className + "on");
230
+ }
231
+ }
232
+
233
+ function launch(target) {
234
+ if (!closing) {
235
+
236
+ element = target;
237
+
238
+ makeSettings();
239
+
240
+ $related = $(element);
241
+
242
+ index = 0;
243
+
244
+ if (settings.rel !== 'nofollow') {
245
+ $related = $('.' + boxElement).filter(function () {
246
+ var relRelated = $.data(this, colorbox).rel || this.rel;
247
+ return (relRelated === settings.rel);
248
+ });
249
+ index = $related.index(element);
250
+
251
+ // Check direct calls to ColorBox.
252
+ if (index === -1) {
253
+ $related = $related.add(element);
254
+ index = $related.length - 1;
255
+ }
256
+ }
257
+
258
+ if (!open) {
259
+ open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys.
260
+
261
+ $box.show();
262
+
263
+ if (settings.returnFocus) {
264
+ $(element).blur().one(event_closed, function () {
265
+ $(this).focus();
266
+ });
267
+ }
268
+
269
+ // +settings.opacity avoids a problem in IE when using non-zero-prefixed-string-values, like '.5'
270
+ $overlay.css({"opacity": +settings.opacity, "cursor": settings.overlayClose ? "pointer" : "auto"}).show();
271
+
272
+ // Opens inital empty ColorBox prior to content being loaded.
273
+ settings.w = setSize(settings.initialWidth, 'x');
274
+ settings.h = setSize(settings.initialHeight, 'y');
275
+ publicMethod.position();
276
+
277
+ if (isIE6) {
278
+ $window.bind('resize.' + event_ie6 + ' scroll.' + event_ie6, function () {
279
+ $overlay.css({width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft()});
280
+ }).trigger('resize.' + event_ie6);
281
+ }
282
+
283
+ trigger(event_open, settings.onOpen);
284
+
285
+ $groupControls.add($title).hide();
286
+
287
+ $close.html(settings.close).show();
288
+ }
289
+
290
+ publicMethod.load(true);
291
+ }
292
+ }
293
+
294
+ // ColorBox's markup needs to be added to the DOM prior to being called
295
+ // so that the browser will go ahead and load the CSS background images.
296
+ function appendHTML() {
297
+ if (!$box && document.body) {
298
+ init = false;
299
+
300
+ $window = $(window);
301
+ $box = $tag(div).attr({id: colorbox, 'class': isIE ? prefix + (isIE6 ? 'IE6' : 'IE') : ''}).hide();
302
+ $overlay = $tag(div, "Overlay", isIE6 ? 'position:absolute' : '').hide();
303
+ $wrap = $tag(div, "Wrapper");
304
+ $content = $tag(div, "Content").append(
305
+ $loaded = $tag(div, "LoadedContent", 'width:0; height:0; overflow:hidden'),
306
+ $loadingOverlay = $tag(div, "LoadingOverlay").add($tag(div, "LoadingGraphic")),
307
+ $title = $tag(div, "Title"),
308
+ $current = $tag(div, "Current"),
309
+ $next = $tag(div, "Next"),
310
+ $prev = $tag(div, "Previous"),
311
+ $slideshow = $tag(div, "Slideshow").bind(event_open, slideshow),
312
+ $close = $tag(div, "Close")
313
+ );
314
+
315
+ $wrap.append( // The 3x3 Grid that makes up ColorBox
316
+ $tag(div).append(
317
+ $tag(div, "TopLeft"),
318
+ $topBorder = $tag(div, "TopCenter"),
319
+ $tag(div, "TopRight")
320
+ ),
321
+ $tag(div, false, 'clear:left').append(
322
+ $leftBorder = $tag(div, "MiddleLeft"),
323
+ $content,
324
+ $rightBorder = $tag(div, "MiddleRight")
325
+ ),
326
+ $tag(div, false, 'clear:left').append(
327
+ $tag(div, "BottomLeft"),
328
+ $bottomBorder = $tag(div, "BottomCenter"),
329
+ $tag(div, "BottomRight")
330
+ )
331
+ ).find('div div').css({'float': 'left'});
332
+
333
+ $loadingBay = $tag(div, false, 'position:absolute; width:9999px; visibility:hidden; display:none');
334
+
335
+ $groupControls = $next.add($prev).add($current).add($slideshow);
336
+
337
+ $(document.body).append($overlay, $box.append($wrap, $loadingBay));
338
+ }
339
+ }
340
+
341
+ // Add ColorBox's event bindings
342
+ function addBindings() {
343
+ if ($box) {
344
+ if (!init) {
345
+ init = true;
346
+
347
+ // Cache values needed for size calculations
348
+ interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height();//Subtraction needed for IE6
349
+ interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width();
350
+ loadedHeight = $loaded.outerHeight(true);
351
+ loadedWidth = $loaded.outerWidth(true);
352
+
353
+ // Setting padding to remove the need to do size conversions during the animation step.
354
+ $box.css({"padding-bottom": interfaceHeight, "padding-right": interfaceWidth});
355
+
356
+ // Anonymous functions here keep the public method from being cached, thereby allowing them to be redefined on the fly.
357
+ $next.click(function () {
358
+ publicMethod.next();
359
+ });
360
+ $prev.click(function () {
361
+ publicMethod.prev();
362
+ });
363
+ $close.click(function () {
364
+ publicMethod.close();
365
+ });
366
+ $overlay.click(function () {
367
+ if (settings.overlayClose) {
368
+ publicMethod.close();
369
+ }
370
+ });
371
+
372
+ // Key Bindings
373
+ $(document).bind('keydown.' + prefix, function (e) {
374
+ var key = e.keyCode;
375
+ if (open && settings.escKey && key === 27) {
376
+ e.preventDefault();
377
+ publicMethod.close();
378
+ }
379
+ if (open && settings.arrowKey && $related[1]) {
380
+ if (key === 37) {
381
+ e.preventDefault();
382
+ $prev.click();
383
+ } else if (key === 39) {
384
+ e.preventDefault();
385
+ $next.click();
386
+ }
387
+ }
388
+ });
389
+
390
+ $('.' + boxElement, document).live('click', function (e) {
391
+ // ignore non-left-mouse-clicks and clicks modified with ctrl / command, shift, or alt.
392
+ // See: http://jacklmoore.com/notes/click-events/
393
+ if (!(e.which > 1 || e.shiftKey || e.altKey || e.metaKey)) {
394
+ e.preventDefault();
395
+ launch(this);
396
+ }
397
+ });
398
+ }
399
+ return true;
400
+ }
401
+ return false;
402
+ }
403
+
404
+ // Don't do anything if ColorBox already exists.
405
+ if ($.colorbox) {
406
+ return;
407
+ }
408
+
409
+ // Append the HTML when the DOM loads
410
+ $(appendHTML);
411
+
412
+
413
+ // ****************
414
+ // PUBLIC FUNCTIONS
415
+ // Usage format: $.fn.colorbox.close();
416
+ // Usage from within an iframe: parent.$.fn.colorbox.close();
417
+ // ****************
418
+
419
+ publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) {
420
+ var $this = this;
421
+
422
+ options = options || {};
423
+
424
+ appendHTML();
425
+
426
+ if (addBindings()) {
427
+ if (!$this[0]) {
428
+ if ($this.selector) { // if a selector was given and it didn't match any elements, go ahead and exit.
429
+ return $this;
430
+ }
431
+ // if no selector was given (ie. $.colorbox()), create a temporary element to work with
432
+ $this = $('<a/>');
433
+ options.open = true; // assume an immediate open
434
+ }
435
+
436
+ if (callback) {
437
+ options.onComplete = callback;
438
+ }
439
+
440
+ $this.each(function () {
441
+ $.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options));
442
+ }).addClass(boxElement);
443
+
444
+ if (($.isFunction(options.open) && options.open.call($this)) || options.open) {
445
+ launch($this[0]);
446
+ }
447
+ }
448
+
449
+ return $this;
450
+ };
451
+
452
+ publicMethod.position = function (speed, loadedCallback) {
453
+ var
454
+ top = 0,
455
+ left = 0,
456
+ offset = $box.offset(),
457
+ scrollTop = $window.scrollTop(),
458
+ scrollLeft = $window.scrollLeft();
459
+
460
+ $window.unbind('resize.' + prefix);
461
+
462
+ // remove the modal so that it doesn't influence the document width/height
463
+ $box.css({top: -9e4, left: -9e4});
464
+
465
+ if (settings.fixed && !isIE6) {
466
+ offset.top -= scrollTop;
467
+ offset.left -= scrollLeft;
468
+ $box.css({position: 'fixed'});
469
+ } else {
470
+ top = scrollTop;
471
+ left = scrollLeft;
472
+ $box.css({position: 'absolute'});
473
+ }
474
+
475
+ // keeps the top and left positions within the browser's viewport.
476
+ if (settings.right !== false) {
477
+ left += Math.max($window.width() - settings.w - loadedWidth - interfaceWidth - setSize(settings.right, 'x'), 0);
478
+ } else if (settings.left !== false) {
479
+ left += setSize(settings.left, 'x');
480
+ } else {
481
+ left += Math.round(Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2);
482
+ }
483
+
484
+ if (settings.bottom !== false) {
485
+ top += Math.max($window.height() - settings.h - loadedHeight - interfaceHeight - setSize(settings.bottom, 'y'), 0);
486
+ } else if (settings.top !== false) {
487
+ top += setSize(settings.top, 'y');
488
+ } else {
489
+ top += Math.round(Math.max($window.height() - settings.h - loadedHeight - interfaceHeight, 0) / 2);
490
+ }
491
+
492
+ $box.css({top: offset.top, left: offset.left});
493
+
494
+ // setting the speed to 0 to reduce the delay between same-sized content.
495
+ speed = ($box.width() === settings.w + loadedWidth && $box.height() === settings.h + loadedHeight) ? 0 : speed || 0;
496
+
497
+ // this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly,
498
+ // but it has to be shrank down around the size of div#colorbox when it's done. If not,
499
+ // it can invoke an obscure IE bug when using iframes.
500
+ $wrap[0].style.width = $wrap[0].style.height = "9999px";
501
+
502
+ function modalDimensions(that) {
503
+ $topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = that.style.width;
504
+ $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height;
505
+ }
506
+
507
+ $box.dequeue().animate({width: settings.w + loadedWidth, height: settings.h + loadedHeight, top: top, left: left}, {
508
+ duration: speed,
509
+ complete: function () {
510
+ modalDimensions(this);
511
+
512
+ active = false;
513
+
514
+ // shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation.
515
+ $wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px";
516
+ $wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px";
517
+
518
+ if (settings.reposition) {
519
+ setTimeout(function () { // small delay before binding onresize due to an IE8 bug.
520
+ $window.bind('resize.' + prefix, publicMethod.position);
521
+ }, 1);
522
+ }
523
+
524
+ if (loadedCallback) {
525
+ loadedCallback();
526
+ }
527
+ },
528
+ step: function () {
529
+ modalDimensions(this);
530
+ }
531
+ });
532
+ };
533
+
534
+ publicMethod.resize = function (options) {
535
+ if (open) {
536
+ options = options || {};
537
+
538
+ if (options.width) {
539
+ settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth;
540
+ }
541
+ if (options.innerWidth) {
542
+ settings.w = setSize(options.innerWidth, 'x');
543
+ }
544
+ $loaded.css({width: settings.w});
545
+
546
+ if (options.height) {
547
+ settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight;
548
+ }
549
+ if (options.innerHeight) {
550
+ settings.h = setSize(options.innerHeight, 'y');
551
+ }
552
+ if (!options.innerHeight && !options.height) {
553
+ $loaded.css({height: "auto"});
554
+ settings.h = $loaded.height();
555
+ }
556
+ $loaded.css({height: settings.h});
557
+
558
+ publicMethod.position(settings.transition === "none" ? 0 : settings.speed);
559
+ }
560
+ };
561
+
562
+ publicMethod.prep = function (object) {
563
+ if (!open) {
564
+ return;
565
+ }
566
+
567
+ var callback, speed = settings.transition === "none" ? 0 : settings.speed;
568
+
569
+ $loaded.remove();
570
+ $loaded = $tag(div, 'LoadedContent').append(object);
571
+
572
+ function getWidth() {
573
+ settings.w = settings.w || $loaded.width();
574
+ settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w;
575
+ return settings.w;
576
+ }
577
+ function getHeight() {
578
+ settings.h = settings.h || $loaded.height();
579
+ settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h;
580
+ return settings.h;
581
+ }
582
+
583
+ $loaded.hide()
584
+ .appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations.
585
+ .css({width: getWidth(), overflow: settings.scrolling ? 'auto' : 'hidden'})
586
+ .css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height.
587
+ .prependTo($content);
588
+
589
+ $loadingBay.hide();
590
+
591
+ // floating the IMG removes the bottom line-height and fixed a problem where IE miscalculates the width of the parent element as 100% of the document width.
592
+ //$(photo).css({'float': 'none', marginLeft: 'auto', marginRight: 'auto'});
593
+
594
+ $(photo).css({'float': 'none'});
595
+
596
+ // Hides SELECT elements in IE6 because they would otherwise sit on top of the overlay.
597
+ if (isIE6) {
598
+ $('select').not($box.find('select')).filter(function () {
599
+ return this.style.visibility !== 'hidden';
600
+ }).css({'visibility': 'hidden'}).one(event_cleanup, function () {
601
+ this.style.visibility = 'inherit';
602
+ });
603
+ }
604
+
605
+ callback = function () {
606
+ var preload, i, total = $related.length, iframe, frameBorder = 'frameBorder', allowTransparency = 'allowTransparency', complete, src, img;
607
+
608
+ if (!open) {
609
+ return;
610
+ }
611
+
612
+ function removeFilter() {
613
+ if (isIE) {
614
+ $box[0].style.removeAttribute('filter');
615
+ }
616
+ }
617
+
618
+ complete = function () {
619
+ clearTimeout(loadingTimer);
620
+ $loadingOverlay.hide();
621
+ trigger(event_complete, settings.onComplete);
622
+ };
623
+
624
+ if (isIE) {
625
+ //This fadeIn helps the bicubic resampling to kick-in.
626
+ if (photo) {
627
+ $loaded.fadeIn(100);
628
+ }
629
+ }
630
+
631
+ $title.html(settings.title).add($loaded).show();
632
+
633
+ if (total > 1) { // handle grouping
634
+ if (typeof settings.current === "string") {
635
+ $current.html(settings.current.replace('{current}', index + 1).replace('{total}', total)).show();
636
+ }
637
+
638
+ $next[(settings.loop || index < total - 1) ? "show" : "hide"]().html(settings.next);
639
+ $prev[(settings.loop || index) ? "show" : "hide"]().html(settings.previous);
640
+
641
+ if (settings.slideshow) {
642
+ $slideshow.show();
643
+ }
644
+
645
+ // Preloads images within a rel group
646
+ if (settings.preloading) {
647
+ preload = [
648
+ getIndex(-1),
649
+ getIndex(1)
650
+ ];
651
+ while (i = $related[preload.pop()]) {
652
+ src = $.data(i, colorbox).href || i.href;
653
+ if ($.isFunction(src)) {
654
+ src = src.call(i);
655
+ }
656
+ if (isImage(src)) {
657
+ img = new Image();
658
+ img.src = src;
659
+ }
660
+ }
661
+ }
662
+ } else {
663
+ $groupControls.hide();
664
+ }
665
+
666
+ if (settings.iframe) {
667
+ iframe = $tag('iframe')[0];
668
+
669
+ if (frameBorder in iframe) {
670
+ iframe[frameBorder] = 0;
671
+ }
672
+ if (allowTransparency in iframe) {
673
+ iframe[allowTransparency] = "true";
674
+ }
675
+ // give the iframe a unique name to prevent caching
676
+ iframe.name = prefix + (+new Date());
677
+ if (settings.fastIframe) {
678
+ complete();
679
+ } else {
680
+ $(iframe).one('load', complete);
681
+ }
682
+ iframe.src = settings.href;
683
+ if (!settings.scrolling) {
684
+ iframe.scrolling = "no";
685
+ }
686
+ $(iframe).addClass(prefix + 'Iframe').appendTo($loaded).one(event_purge, function () {
687
+ iframe.src = "//about:blank";
688
+ });
689
+ } else {
690
+ complete();
691
+ }
692
+
693
+ if (settings.transition === 'fade') {
694
+ $box.fadeTo(speed, 1, removeFilter);
695
+ } else {
696
+ removeFilter();
697
+ }
698
+ };
699
+
700
+ if (settings.transition === 'fade') {
701
+ $box.fadeTo(speed, 0, function () {
702
+ publicMethod.position(0, callback);
703
+ });
704
+ } else {
705
+ publicMethod.position(speed, callback);
706
+ }
707
+ };
708
+
709
+ publicMethod.load = function (launched) {
710
+ var href, setResize, prep = publicMethod.prep;
711
+
712
+ active = true;
713
+
714
+ photo = false;
715
+
716
+ element = $related[index];
717
+
718
+ if (!launched) {
719
+ makeSettings();
720
+ }
721
+
722
+ trigger(event_purge);
723
+
724
+ trigger(event_load, settings.onLoad);
725
+
726
+ settings.h = settings.height ?
727
+ setSize(settings.height, 'y') - loadedHeight - interfaceHeight :
728
+ settings.innerHeight && setSize(settings.innerHeight, 'y');
729
+
730
+ settings.w = settings.width ?
731
+ setSize(settings.width, 'x') - loadedWidth - interfaceWidth :
732
+ settings.innerWidth && setSize(settings.innerWidth, 'x');
733
+
734
+ // Sets the minimum dimensions for use in image scaling
735
+ settings.mw = settings.w;
736
+ settings.mh = settings.h;
737
+
738
+ // Re-evaluate the minimum width and height based on maxWidth and maxHeight values.
739
+ // If the width or height exceed the maxWidth or maxHeight, use the maximum values instead.
740
+ if (settings.maxWidth) {
741
+ settings.mw = setSize(settings.maxWidth, 'x') - loadedWidth - interfaceWidth;
742
+ settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw;
743
+ }
744
+ if (settings.maxHeight) {
745
+ settings.mh = setSize(settings.maxHeight, 'y') - loadedHeight - interfaceHeight;
746
+ settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh;
747
+ }
748
+
749
+ href = settings.href;
750
+
751
+ loadingTimer = setTimeout(function () {
752
+ $loadingOverlay.show();
753
+ }, 100);
754
+
755
+ if (settings.inline) {
756
+ // Inserts an empty placeholder where inline content is being pulled from.
757
+ // An event is bound to put inline content back when ColorBox closes or loads new content.
758
+ $tag(div).hide().insertBefore($(href)[0]).one(event_purge, function () {
759
+ $(this).replaceWith($loaded.children());
760
+ });
761
+ prep($(href));
762
+ } else if (settings.iframe) {
763
+ // IFrame element won't be added to the DOM until it is ready to be displayed,
764
+ // to avoid problems with DOM-ready JS that might be trying to run in that iframe.
765
+ prep(" ");
766
+ } else if (settings.html) {
767
+ prep(settings.html);
768
+ } else if (isImage(href)) {
769
+ $(photo = new Image())
770
+ .addClass(prefix + 'Photo')
771
+ .error(function () {
772
+ settings.title = false;
773
+ prep($tag(div, 'Error').text('This image could not be loaded'));
774
+ })
775
+ .load(function () {
776
+ var percent;
777
+ photo.onload = null; //stops animated gifs from firing the onload repeatedly.
778
+
779
+ if (settings.scalePhotos) {
780
+ setResize = function () {
781
+ photo.height -= photo.height * percent;
782
+ photo.width -= photo.width * percent;
783
+ };
784
+ if (settings.mw && photo.width > settings.mw) {
785
+ percent = (photo.width - settings.mw) / photo.width;
786
+ setResize();
787
+ }
788
+ if (settings.mh && photo.height > settings.mh) {
789
+ percent = (photo.height - settings.mh) / photo.height;
790
+ setResize();
791
+ }
792
+ }
793
+
794
+ if (settings.h) {
795
+ photo.style.marginTop = Math.max(settings.h - photo.height, 0) / 2 + 'px';
796
+ }
797
+
798
+ if ($related[1] && (settings.loop || $related[index + 1])) {
799
+ photo.style.cursor = 'pointer';
800
+ photo.onclick = function () {
801
+ publicMethod.next();
802
+ };
803
+ }
804
+
805
+ if (isIE) {
806
+ photo.style.msInterpolationMode = 'bicubic';
807
+ }
808
+
809
+ setTimeout(function () { // A pause because Chrome will sometimes report a 0 by 0 size otherwise.
810
+ prep(photo);
811
+ }, 1);
812
+ });
813
+
814
+ setTimeout(function () { // A pause because Opera 10.6+ will sometimes not run the onload function otherwise.
815
+ photo.src = href;
816
+ }, 1);
817
+ } else if (href) {
818
+ $loadingBay.load(href, settings.data, function (data, status, xhr) {
819
+ prep(status === 'error' ? $tag(div, 'Error').text('Request unsuccessful: ' + xhr.statusText) : $(this).contents());
820
+ });
821
+ }
822
+ };
823
+
824
+ // Navigates to the next page/image in a set.
825
+ publicMethod.next = function () {
826
+ if (!active && $related[1] && (settings.loop || $related[index + 1])) {
827
+ index = getIndex(1);
828
+ publicMethod.load();
829
+ }
830
+ };
831
+
832
+ publicMethod.prev = function () {
833
+ if (!active && $related[1] && (settings.loop || index)) {
834
+ index = getIndex(-1);
835
+ publicMethod.load();
836
+ }
837
+ };
838
+
839
+ // Note: to use this within an iframe use the following format: parent.$.fn.colorbox.close();
840
+ publicMethod.close = function () {
841
+ if (open && !closing) {
842
+
843
+ closing = true;
844
+
845
+ open = false;
846
+
847
+ trigger(event_cleanup, settings.onCleanup);
848
+
849
+ $window.unbind('.' + prefix + ' .' + event_ie6);
850
+
851
+ $overlay.fadeTo(200, 0);
852
+
853
+ $box.stop().fadeTo(300, 0, function () {
854
+
855
+ $box.add($overlay).css({'opacity': 1, cursor: 'auto'}).hide();
856
+
857
+ trigger(event_purge);
858
+
859
+ $loaded.remove();
860
+
861
+ setTimeout(function () {
862
+ closing = false;
863
+ trigger(event_closed, settings.onClosed);
864
+ }, 1);
865
+ });
866
+ }
867
+ };
868
+
869
+ // Removes changes ColorBox made to the document, but does not remove the plugin
870
+ // from jQuery.
871
+ publicMethod.remove = function () {
872
+ $([]).add($box).add($overlay).remove();
873
+ $box = null;
874
+ $('.' + boxElement)
875
+ .removeData(colorbox)
876
+ .removeClass(boxElement)
877
+ .die();
878
+ };
879
+
880
+ // A method for fetching the current element ColorBox is referencing.
881
+ // returns a jQuery object.
882
+ publicMethod.element = function () {
883
+ return $(element);
884
+ };
885
+
886
+ publicMethod.settings = defaults;
887
+
888
+ }(jQuery, document, this));
@@ -0,0 +1,85 @@
1
+ /*
2
+ ColorBox Core Style:
3
+ The following CSS is consistent between example themes and should not be altered.
4
+ */
5
+ #colorbox, #cboxOverlay, #cboxWrapper{position:absolute; top:0; left:0; z-index:9999; overflow:hidden;}
6
+ #cboxOverlay{position:fixed; width:100%; height:100%;}
7
+ #cboxMiddleLeft, #cboxBottomLeft{clear:left;}
8
+ #cboxContent{position:relative;}
9
+ #cboxLoadedContent{overflow:auto;}
10
+ #cboxTitle{margin:0;}
11
+ #cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%; height:100%;}
12
+ #cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow{cursor:pointer;}
13
+ .cboxPhoto{float:left; margin:auto; border:0; display:block;}
14
+ .cboxIframe{width:100%; height:100%; display:block; border:0;}
15
+
16
+ /*
17
+ User Style:
18
+ Change the following styles to modify the appearance of ColorBox. They are
19
+ ordered & tabbed in a way that represents the nesting of the generated HTML.
20
+ */
21
+ #cboxOverlay{background:url(images/overlay.png) repeat 0 0;}
22
+ #colorbox{}
23
+ #cboxTopLeft{width:21px; height:21px; background:url(controls.png) no-repeat -101px 0;}
24
+ #cboxTopRight{width:21px; height:21px; background:url(controls.png) no-repeat -130px 0;}
25
+ #cboxBottomLeft{width:21px; height:21px; background:url(controls.png) no-repeat -101px -29px;}
26
+ #cboxBottomRight{width:21px; height:21px; background:url(controls.png) no-repeat -130px -29px;}
27
+ #cboxMiddleLeft{width:21px; background:url(controls.png) left top repeat-y;}
28
+ #cboxMiddleRight{width:21px; background:url(controls.png) right top repeat-y;}
29
+ #cboxTopCenter{height:21px; background:url(border.png) 0 0 repeat-x;}
30
+ #cboxBottomCenter{height:21px; background:url(border.png) 0 -29px repeat-x;}
31
+ #cboxContent{background:#fff; overflow:hidden;}
32
+ .cboxIframe{background:#fff;}
33
+ #cboxError{padding:50px; border:1px solid #ccc;}
34
+ #cboxLoadedContent{margin-bottom:28px;}
35
+ #cboxTitle{position:absolute; bottom:4px; left:0; text-align:center; width:100%; color:#949494;}
36
+ #cboxCurrent{position:absolute; bottom:4px; left:58px; color:#949494;}
37
+ #cboxSlideshow{position:absolute; bottom:4px; right:30px; color:#0092ef;}
38
+ #cboxPrevious{position:absolute; bottom:0; left:0; background:url(controls.png) no-repeat -75px 0; width:25px; height:25px; text-indent:-9999px;}
39
+ #cboxPrevious:hover{background-position:-75px -25px;}
40
+ #cboxNext{position:absolute; bottom:0; left:27px; background:url(controls.png) no-repeat -50px 0; width:25px; height:25px; text-indent:-9999px;}
41
+ #cboxNext:hover{background-position:-50px -25px;}
42
+ #cboxLoadingOverlay{background:url(loading_background.png) no-repeat center center;}
43
+ #cboxLoadingGraphic{background:url(loading.gif) no-repeat center center;}
44
+ #cboxClose{position:absolute; bottom:0; right:0; background:url(controls.png) no-repeat -25px 0; width:25px; height:25px; text-indent:-9999px;}
45
+ #cboxClose:hover{background-position:-25px -25px;}
46
+
47
+ /*
48
+ The following fixes a problem where IE7 and IE8 replace a PNG's alpha transparency with a black fill
49
+ when an alpha filter (opacity change) is set on the element or ancestor element. This style is not applied to or needed in IE9.
50
+ See: http://jacklmoore.com/notes/ie-transparency-problems/
51
+ */
52
+ .cboxIE #cboxTopLeft,
53
+ .cboxIE #cboxTopCenter,
54
+ .cboxIE #cboxTopRight,
55
+ .cboxIE #cboxBottomLeft,
56
+ .cboxIE #cboxBottomCenter,
57
+ .cboxIE #cboxBottomRight,
58
+ .cboxIE #cboxMiddleLeft,
59
+ .cboxIE #cboxMiddleRight {
60
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#00FFFFFF,endColorstr=#00FFFFFF);
61
+ }
62
+
63
+ /*
64
+ The following provides PNG transparency support for IE6
65
+ Feel free to remove this and the /ie6/ directory if you have dropped IE6 support.
66
+ */
67
+ .cboxIE6 #cboxTopLeft{background:url(ie6/borderTopLeft.png);}
68
+ .cboxIE6 #cboxTopCenter{background:url(ie6/borderTopCenter.png);}
69
+ .cboxIE6 #cboxTopRight{background:url(ie6/borderTopRight.png);}
70
+ .cboxIE6 #cboxBottomLeft{background:url(ie6/borderBottomLeft.png);}
71
+ .cboxIE6 #cboxBottomCenter{background:url(ie6/borderBottomCenter.png);}
72
+ .cboxIE6 #cboxBottomRight{background:url(ie6/borderBottomRight.png);}
73
+ .cboxIE6 #cboxMiddleLeft{background:url(ie6/borderMiddleLeft.png);}
74
+ .cboxIE6 #cboxMiddleRight{background:url(ie6/borderMiddleRight.png);}
75
+
76
+ .cboxIE6 #cboxTopLeft,
77
+ .cboxIE6 #cboxTopCenter,
78
+ .cboxIE6 #cboxTopRight,
79
+ .cboxIE6 #cboxBottomLeft,
80
+ .cboxIE6 #cboxBottomCenter,
81
+ .cboxIE6 #cboxBottomRight,
82
+ .cboxIE6 #cboxMiddleLeft,
83
+ .cboxIE6 #cboxMiddleRight {
84
+ _behavior: expression(this.src = this.src ? this.src : this.currentStyle.backgroundImage.split('"')[1], this.style.background = "none", this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + this.src + ", sizingMethod='scale')");
85
+ }
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colorbox-on-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Chang
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-27 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: An asset gem pack the ColorBox jQuery Plugin (http://www.jacklmoore.com/colorbox)
15
+ email:
16
+ - zeta11235813@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - MIT-LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - colorbox-on-rails.gemspec
27
+ - lib/colorbox-on-rails.rb
28
+ - lib/colorbox-on-rails/engine.rb
29
+ - lib/colorbox-on-rails/version.rb
30
+ - vendor/assets/images/.DS_Store
31
+ - vendor/assets/images/border.png
32
+ - vendor/assets/images/controls.png
33
+ - vendor/assets/images/ie6/borderBottomCenter.png
34
+ - vendor/assets/images/ie6/borderBottomLeft.png
35
+ - vendor/assets/images/ie6/borderBottomRight.png
36
+ - vendor/assets/images/ie6/borderMiddleLeft.png
37
+ - vendor/assets/images/ie6/borderMiddleRight.png
38
+ - vendor/assets/images/ie6/borderTopCenter.png
39
+ - vendor/assets/images/ie6/borderTopLeft.png
40
+ - vendor/assets/images/ie6/borderTopRight.png
41
+ - vendor/assets/images/loading.gif
42
+ - vendor/assets/images/loading_background.png
43
+ - vendor/assets/images/overlay.png
44
+ - vendor/assets/javascripts/.DS_Store
45
+ - vendor/assets/javascripts/jquery.colorbox.js
46
+ - vendor/assets/stylesheets/colorbox.css.scss.css
47
+ homepage: http://github.com/zetachang/colorbox-on-rails
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project: colorbox-on-rails
67
+ rubygems_version: 1.8.10
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: An assets gem for jquery.colorbox integrating with Rails 3.1
71
+ test_files: []