marionette-dialogregion-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6c4d878f05db87092bf8f91484c72ace47d71df4
4
+ data.tar.gz: 3182e8df30bc44d160d15d8f1cc719fb8b3221df
5
+ SHA512:
6
+ metadata.gz: 6e0d3a4542ef2d4348d4f40be256d41d720afbda4f1de357928bf042cbab6d64a7e01eca8b4dce82ef7d12067a7d97ece0a33b363c69a871796cb54cfd6f3df2
7
+ data.tar.gz: 7825d6fbc2f478fc14c1720fbde992039c0cebf6bd99b30fcbab888802de6fab653642631d8e4d9d1d4b2b2e8d4aa3eee2839887f42b553137b469480cce06a8
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in marionette-dialogregion-rails.gemspec
4
+ gemspec
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,68 @@
1
+ marionette-dialogregion-rails
2
+ =============================
3
+
4
+ Custom Marionette region setup for dialogs/lightboxes, vendored for Rails projects using the asset pipeline.
5
+
6
+ Largely based on Brian Mann's [Building Dialogs with Custom Regions](http://www.backbonerails.com/screencasts/building-dialogs-with-custom-regions) screencast, with a few extra options to make the dialogs un-closeable and to work around issues opening consecutive dialogs with Colorbox.
7
+
8
+ Dependencies
9
+ ------------
10
+
11
+ Depends on Backbone, Marionette, and jQuery, since there are so many different solutions available to vendoring these assets, we don't provide one for you. The lightbox solution used, [colorbox](http://www.jacklmoore.com/colorbox/), _is_ included as we depend on some unreleased bug fixes. This may change in the future.
12
+
13
+ Setup
14
+ -----
15
+
16
+ Add the gem to your `Gemfile`:
17
+
18
+ ```ruby
19
+ gem marionette-dialogregion-rails
20
+ ```
21
+
22
+ And run `bundle install`.
23
+
24
+ Require the JavaScripts in your `application.js.coffee`:
25
+
26
+ ```coffeescript
27
+ #= require marionette-dialogregion-rails
28
+ ```
29
+
30
+ Then, in your Marionette app, you can declare a region to be a dialog by extending `Marionette.Region.Dialog` and providing a selector for the element you wish to use for your dialogs:
31
+
32
+ ```coffeescript
33
+ App.addRegions
34
+ dialogRegion: Marionette.Region.Dialog.extend el: "#dialog"
35
+ ```
36
+
37
+ Now, when you show a view in that region, it will be displayed in a Colorbox lightbox:
38
+
39
+ ```coffeescript
40
+ App.dialogRegion.show view
41
+ ```
42
+
43
+ Options
44
+ -------
45
+
46
+ Currently, there is only one option available, `closable`. It defaults to `true`, but if you make it `false`, the dialog will not be closable by clicking on the background overlay or pressing the Escape key:
47
+
48
+ ```coffeescript
49
+ view = new MyView fake: true
50
+ App.dialogRegion.show view
51
+ ```
52
+
53
+ Copyright and Licence
54
+ ---------------------
55
+
56
+ Copyright 2014 Avalanche Technology Group Pty Ltd
57
+
58
+ Licensed under the Apache License, Version 2.0 (the "License");
59
+ you may not use this file except in compliance with the License.
60
+ You may obtain a copy of the License at
61
+
62
+ http://www.apache.org/licenses/LICENSE-2.0
63
+
64
+ Unless required by applicable law or agreed to in writing, software
65
+ distributed under the License is distributed on an "AS IS" BASIS,
66
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
67
+ See the License for the specific language governing permissions and
68
+ limitations under the License.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ require 'rails'
2
+
3
+ module Marionette
4
+ module DialogRegion
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Marionette
2
+ module DialogRegion
3
+ module Rails
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'marionette-dialogregion-rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "marionette-dialogregion-rails"
8
+ spec.version = Marionette::DialogRegion::Rails::VERSION
9
+ spec.authors = ["Louis Simoneau"]
10
+ spec.email = ["simoneau.louis@gmail.com"]
11
+ spec.description = %q{Colorbox dialog region for Marionette}
12
+ spec.summary = %q{Custom Marionette region setup for dialogs/lightboxes, vendored for Rails projects using the asset pipeline.}
13
+ spec.homepage = "https://github.com/avalancheau/marionette-dialogregion-rails"
14
+ spec.license = "Apache"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "railties", ">= 3.1"
22
+ spec.add_dependency "coffee-rails", "~> 4.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ end
@@ -0,0 +1,29 @@
1
+ do (Backbone, Marionette, $) ->
2
+
3
+ class Marionette.Region.Dialog extends Marionette.Region
4
+
5
+ onShow: (view) ->
6
+ options = _.defaults(
7
+ view.options,
8
+ closable: true
9
+ )
10
+
11
+ $.colorbox
12
+ href: @$el
13
+ inline: true
14
+ closeButton: false
15
+ transition: 'none'
16
+ fadeOut: 100
17
+ overlayClose: options.closable
18
+ escKey: options.closable
19
+ onCleanup: =>
20
+ @oldView = @currentView
21
+ onClosed: =>
22
+ if @oldView == @currentView
23
+ @oldView.close()
24
+
25
+ @listenTo view, 'close', ->
26
+ $.colorbox.remove()
27
+
28
+ @listenTo view, 'region:show', ->
29
+ $.colorbox.resize()
@@ -0,0 +1,1090 @@
1
+ /*!
2
+ Colorbox v1.5.9 - 2014-04-25
3
+ jQuery lightbox and modal window plugin
4
+ (c) 2014 Jack Moore - http://www.jacklmoore.com/colorbox
5
+ license: http://www.opensource.org/licenses/mit-license.php
6
+ */
7
+ (function ($, document, window) {
8
+ var
9
+ // Default settings object.
10
+ // See http://jacklmoore.com/colorbox for details.
11
+ defaults = {
12
+ // data sources
13
+ html: false,
14
+ photo: false,
15
+ iframe: false,
16
+ inline: false,
17
+
18
+ // behavior and appearance
19
+ transition: "elastic",
20
+ speed: 300,
21
+ fadeOut: 300,
22
+ width: false,
23
+ initialWidth: "600",
24
+ innerWidth: false,
25
+ maxWidth: false,
26
+ height: false,
27
+ initialHeight: "450",
28
+ innerHeight: false,
29
+ maxHeight: false,
30
+ scalePhotos: true,
31
+ scrolling: true,
32
+ opacity: 0.9,
33
+ preloading: true,
34
+ className: false,
35
+ overlayClose: true,
36
+ escKey: true,
37
+ arrowKey: true,
38
+ top: false,
39
+ bottom: false,
40
+ left: false,
41
+ right: false,
42
+ fixed: false,
43
+ data: undefined,
44
+ closeButton: true,
45
+ fastIframe: true,
46
+ open: false,
47
+ reposition: true,
48
+ loop: true,
49
+ slideshow: false,
50
+ slideshowAuto: true,
51
+ slideshowSpeed: 2500,
52
+ slideshowStart: "start slideshow",
53
+ slideshowStop: "stop slideshow",
54
+ photoRegex: /\.(gif|png|jp(e|g|eg)|bmp|ico|webp|jxr|svg)((#|\?).*)?$/i,
55
+
56
+ // alternate image paths for high-res displays
57
+ retinaImage: false,
58
+ retinaUrl: false,
59
+ retinaSuffix: '@2x.$1',
60
+
61
+ // internationalization
62
+ current: "image {current} of {total}",
63
+ previous: "previous",
64
+ next: "next",
65
+ close: "close",
66
+ xhrError: "This content failed to load.",
67
+ imgError: "This image failed to load.",
68
+
69
+ // accessbility
70
+ returnFocus: true,
71
+ trapFocus: true,
72
+
73
+ // callbacks
74
+ onOpen: false,
75
+ onLoad: false,
76
+ onComplete: false,
77
+ onCleanup: false,
78
+ onClosed: false,
79
+
80
+ rel: function() {
81
+ return this.rel;
82
+ },
83
+ href: function() {
84
+ // using this.href would give the absolute url, when the href may have been inteded as a selector (e.g. '#container')
85
+ return $(this).attr('href');
86
+ },
87
+ title: function() {
88
+ return this.title;
89
+ }
90
+ },
91
+
92
+
93
+ // Abstracting the HTML and event identifiers for easy rebranding
94
+ colorbox = 'colorbox',
95
+ prefix = 'cbox',
96
+ boxElement = prefix + 'Element',
97
+
98
+ // Events
99
+ event_open = prefix + '_open',
100
+ event_load = prefix + '_load',
101
+ event_complete = prefix + '_complete',
102
+ event_cleanup = prefix + '_cleanup',
103
+ event_closed = prefix + '_closed',
104
+ event_purge = prefix + '_purge',
105
+
106
+ // Cached jQuery Object Variables
107
+ $overlay,
108
+ $box,
109
+ $wrap,
110
+ $content,
111
+ $topBorder,
112
+ $leftBorder,
113
+ $rightBorder,
114
+ $bottomBorder,
115
+ $related,
116
+ $window,
117
+ $loaded,
118
+ $loadingBay,
119
+ $loadingOverlay,
120
+ $title,
121
+ $current,
122
+ $slideshow,
123
+ $next,
124
+ $prev,
125
+ $close,
126
+ $groupControls,
127
+ $events = $('<a/>'), // $({}) would be prefered, but there is an issue with jQuery 1.4.2
128
+
129
+ // Variables for cached values or use across multiple functions
130
+ settings,
131
+ interfaceHeight,
132
+ interfaceWidth,
133
+ loadedHeight,
134
+ loadedWidth,
135
+ index,
136
+ photo,
137
+ open,
138
+ active,
139
+ closing,
140
+ loadingTimer,
141
+ publicMethod,
142
+ div = "div",
143
+ requests = 0,
144
+ previousCSS = {},
145
+ init;
146
+
147
+ // ****************
148
+ // HELPER FUNCTIONS
149
+ // ****************
150
+
151
+ // Convenience function for creating new jQuery objects
152
+ function $tag(tag, id, css) {
153
+ var element = document.createElement(tag);
154
+
155
+ if (id) {
156
+ element.id = prefix + id;
157
+ }
158
+
159
+ if (css) {
160
+ element.style.cssText = css;
161
+ }
162
+
163
+ return $(element);
164
+ }
165
+
166
+ // Get the window height using innerHeight when available to avoid an issue with iOS
167
+ // http://bugs.jquery.com/ticket/6724
168
+ function winheight() {
169
+ return window.innerHeight ? window.innerHeight : $(window).height();
170
+ }
171
+
172
+ function Settings(element, options) {
173
+ if (options !== Object(options)) {
174
+ options = {};
175
+ }
176
+
177
+ this.cache = {};
178
+ this.el = element;
179
+
180
+ this.value = function(key) {
181
+ var dataAttr;
182
+
183
+ if (this.cache[key] === undefined) {
184
+ dataAttr = $(this.el).attr('data-cbox-'+key);
185
+
186
+ if (dataAttr !== undefined) {
187
+ this.cache[key] = dataAttr;
188
+ } else if (options[key] !== undefined) {
189
+ this.cache[key] = options[key];
190
+ } else if (defaults[key] !== undefined) {
191
+ this.cache[key] = defaults[key];
192
+ }
193
+ }
194
+
195
+ return this.cache[key];
196
+ };
197
+
198
+ this.get = function(key) {
199
+ var value = this.value(key);
200
+ return $.isFunction(value) ? value.call(this.el, this) : value;
201
+ };
202
+ }
203
+
204
+ // Determine the next and previous members in a group.
205
+ function getIndex(increment) {
206
+ var
207
+ max = $related.length,
208
+ newIndex = (index + increment) % max;
209
+
210
+ return (newIndex < 0) ? max + newIndex : newIndex;
211
+ }
212
+
213
+ // Convert '%' and 'px' values to integers
214
+ function setSize(size, dimension) {
215
+ return Math.round((/%/.test(size) ? ((dimension === 'x' ? $window.width() : winheight()) / 100) : 1) * parseInt(size, 10));
216
+ }
217
+
218
+ // Checks an href to see if it is a photo.
219
+ // There is a force photo option (photo: true) for hrefs that cannot be matched by the regex.
220
+ function isImage(settings, url) {
221
+ return settings.get('photo') || settings.get('photoRegex').test(url);
222
+ }
223
+
224
+ function retinaUrl(settings, url) {
225
+ return settings.get('retinaUrl') && window.devicePixelRatio > 1 ? url.replace(settings.get('photoRegex'), settings.get('retinaSuffix')) : url;
226
+ }
227
+
228
+ function trapFocus(e) {
229
+ if ('contains' in $box[0] && !$box[0].contains(e.target) && e.target !== $overlay[0]) {
230
+ e.stopPropagation();
231
+ $box.focus();
232
+ }
233
+ }
234
+
235
+ function setClass(str) {
236
+ if (setClass.str !== str) {
237
+ $box.add($overlay).removeClass(setClass.str).addClass(str);
238
+ setClass.str = str;
239
+ }
240
+ }
241
+
242
+ function getRelated(rel) {
243
+ index = 0;
244
+
245
+ if (rel && rel !== false && rel !== 'nofollow') {
246
+ $related = $('.' + boxElement).filter(function () {
247
+ var options = $.data(this, colorbox);
248
+ var settings = new Settings(this, options);
249
+ return (settings.get('rel') === rel);
250
+ });
251
+ index = $related.index(settings.el);
252
+
253
+ // Check direct calls to Colorbox.
254
+ if (index === -1) {
255
+ $related = $related.add(settings.el);
256
+ index = $related.length - 1;
257
+ }
258
+ } else {
259
+ $related = $(settings.el);
260
+ }
261
+ }
262
+
263
+ function trigger(event) {
264
+ // for external use
265
+ $(document).trigger(event);
266
+ // for internal use
267
+ $events.triggerHandler(event);
268
+ }
269
+
270
+ var slideshow = (function(){
271
+ var active,
272
+ className = prefix + "Slideshow_",
273
+ click = "click." + prefix,
274
+ timeOut;
275
+
276
+ function clear () {
277
+ clearTimeout(timeOut);
278
+ }
279
+
280
+ function set() {
281
+ if (settings.get('loop') || $related[index + 1]) {
282
+ clear();
283
+ timeOut = setTimeout(publicMethod.next, settings.get('slideshowSpeed'));
284
+ }
285
+ }
286
+
287
+ function start() {
288
+ $slideshow
289
+ .html(settings.get('slideshowStop'))
290
+ .unbind(click)
291
+ .one(click, stop);
292
+
293
+ $events
294
+ .bind(event_complete, set)
295
+ .bind(event_load, clear);
296
+
297
+ $box.removeClass(className + "off").addClass(className + "on");
298
+ }
299
+
300
+ function stop() {
301
+ clear();
302
+
303
+ $events
304
+ .unbind(event_complete, set)
305
+ .unbind(event_load, clear);
306
+
307
+ $slideshow
308
+ .html(settings.get('slideshowStart'))
309
+ .unbind(click)
310
+ .one(click, function () {
311
+ publicMethod.next();
312
+ start();
313
+ });
314
+
315
+ $box.removeClass(className + "on").addClass(className + "off");
316
+ }
317
+
318
+ function reset() {
319
+ active = false;
320
+ $slideshow.hide();
321
+ clear();
322
+ $events
323
+ .unbind(event_complete, set)
324
+ .unbind(event_load, clear);
325
+ $box.removeClass(className + "off " + className + "on");
326
+ }
327
+
328
+ return function(){
329
+ if (active) {
330
+ if (!settings.get('slideshow')) {
331
+ $events.unbind(event_cleanup, reset);
332
+ reset();
333
+ }
334
+ } else {
335
+ if (settings.get('slideshow') && $related[1]) {
336
+ active = true;
337
+ $events.one(event_cleanup, reset);
338
+ if (settings.get('slideshowAuto')) {
339
+ start();
340
+ } else {
341
+ stop();
342
+ }
343
+ $slideshow.show();
344
+ }
345
+ }
346
+ };
347
+
348
+ }());
349
+
350
+
351
+ function launch(element) {
352
+ var options;
353
+
354
+ if (!closing) {
355
+
356
+ options = $(element).data('colorbox');
357
+
358
+ settings = new Settings(element, options);
359
+
360
+ getRelated(settings.get('rel'));
361
+
362
+ if (!open) {
363
+ open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys.
364
+
365
+ setClass(settings.get('className'));
366
+
367
+ // Show colorbox so the sizes can be calculated in older versions of jQuery
368
+ $box.css({visibility:'hidden', display:'block', opacity:''});
369
+
370
+ $loaded = $tag(div, 'LoadedContent', 'width:0; height:0; overflow:hidden; visibility:hidden');
371
+ $content.css({width:'', height:''}).append($loaded);
372
+
373
+ // Cache values needed for size calculations
374
+ interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height();
375
+ interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width();
376
+ loadedHeight = $loaded.outerHeight(true);
377
+ loadedWidth = $loaded.outerWidth(true);
378
+
379
+ // Opens inital empty Colorbox prior to content being loaded.
380
+ var initialWidth = setSize(settings.get('initialWidth'), 'x');
381
+ var initialHeight = setSize(settings.get('initialHeight'), 'y');
382
+ var maxWidth = settings.get('maxWidth');
383
+ var maxHeight = settings.get('maxHeight');
384
+
385
+ settings.w = (maxWidth !== false ? Math.min(initialWidth, setSize(maxWidth, 'x')) : initialWidth) - loadedWidth - interfaceWidth;
386
+ settings.h = (maxHeight !== false ? Math.min(initialHeight, setSize(maxHeight, 'y')) : initialHeight) - loadedHeight - interfaceHeight;
387
+
388
+ $loaded.css({width:'', height:settings.h});
389
+ publicMethod.position();
390
+
391
+ trigger(event_open);
392
+ settings.get('onOpen');
393
+
394
+ $groupControls.add($title).hide();
395
+
396
+ $box.focus();
397
+
398
+ if (settings.get('trapFocus')) {
399
+ // Confine focus to the modal
400
+ // Uses event capturing that is not supported in IE8-
401
+ if (document.addEventListener) {
402
+
403
+ document.addEventListener('focus', trapFocus, true);
404
+
405
+ $events.one(event_closed, function () {
406
+ document.removeEventListener('focus', trapFocus, true);
407
+ });
408
+ }
409
+ }
410
+
411
+ // Return focus on closing
412
+ if (settings.get('returnFocus')) {
413
+ $events.one(event_closed, function () {
414
+ $(settings.el).focus();
415
+ });
416
+ }
417
+ }
418
+
419
+ $overlay.css({
420
+ opacity: parseFloat(settings.get('opacity')) || '',
421
+ cursor: settings.get('overlayClose') ? 'pointer' : '',
422
+ visibility: 'visible'
423
+ }).show();
424
+
425
+ if (settings.get('closeButton')) {
426
+ $close.html(settings.get('close')).appendTo($content);
427
+ } else {
428
+ $close.appendTo('<div/>'); // replace with .detach() when dropping jQuery < 1.4
429
+ }
430
+
431
+ load();
432
+ }
433
+ }
434
+
435
+ // Colorbox's markup needs to be added to the DOM prior to being called
436
+ // so that the browser will go ahead and load the CSS background images.
437
+ function appendHTML() {
438
+ if (!$box && document.body) {
439
+ init = false;
440
+ $window = $(window);
441
+ $box = $tag(div).attr({
442
+ id: colorbox,
443
+ 'class': $.support.opacity === false ? prefix + 'IE' : '', // class for optional IE8 & lower targeted CSS.
444
+ role: 'dialog',
445
+ tabindex: '-1'
446
+ }).hide();
447
+ $overlay = $tag(div, "Overlay").hide();
448
+ $loadingOverlay = $([$tag(div, "LoadingOverlay")[0],$tag(div, "LoadingGraphic")[0]]);
449
+ $wrap = $tag(div, "Wrapper");
450
+ $content = $tag(div, "Content").append(
451
+ $title = $tag(div, "Title"),
452
+ $current = $tag(div, "Current"),
453
+ $prev = $('<button type="button"/>').attr({id:prefix+'Previous'}),
454
+ $next = $('<button type="button"/>').attr({id:prefix+'Next'}),
455
+ $slideshow = $tag('button', "Slideshow"),
456
+ $loadingOverlay
457
+ );
458
+
459
+ $close = $('<button type="button"/>').attr({id:prefix+'Close'});
460
+
461
+ $wrap.append( // The 3x3 Grid that makes up Colorbox
462
+ $tag(div).append(
463
+ $tag(div, "TopLeft"),
464
+ $topBorder = $tag(div, "TopCenter"),
465
+ $tag(div, "TopRight")
466
+ ),
467
+ $tag(div, false, 'clear:left').append(
468
+ $leftBorder = $tag(div, "MiddleLeft"),
469
+ $content,
470
+ $rightBorder = $tag(div, "MiddleRight")
471
+ ),
472
+ $tag(div, false, 'clear:left').append(
473
+ $tag(div, "BottomLeft"),
474
+ $bottomBorder = $tag(div, "BottomCenter"),
475
+ $tag(div, "BottomRight")
476
+ )
477
+ ).find('div div').css({'float': 'left'});
478
+
479
+ $loadingBay = $tag(div, false, 'position:absolute; width:9999px; visibility:hidden; display:none; max-width:none;');
480
+
481
+ $groupControls = $next.add($prev).add($current).add($slideshow);
482
+
483
+ $(document.body).append($overlay, $box.append($wrap, $loadingBay));
484
+ }
485
+ }
486
+
487
+ // Add Colorbox's event bindings
488
+ function addBindings() {
489
+ function clickHandler(e) {
490
+ // ignore non-left-mouse-clicks and clicks modified with ctrl / command, shift, or alt.
491
+ // See: http://jacklmoore.com/notes/click-events/
492
+ if (!(e.which > 1 || e.shiftKey || e.altKey || e.metaKey || e.ctrlKey)) {
493
+ e.preventDefault();
494
+ launch(this);
495
+ }
496
+ }
497
+
498
+ if ($box) {
499
+ if (!init) {
500
+ init = true;
501
+
502
+ // Anonymous functions here keep the public method from being cached, thereby allowing them to be redefined on the fly.
503
+ $next.click(function () {
504
+ publicMethod.next();
505
+ });
506
+ $prev.click(function () {
507
+ publicMethod.prev();
508
+ });
509
+ $close.click(function () {
510
+ publicMethod.close();
511
+ });
512
+ $overlay.click(function () {
513
+ if (settings.get('overlayClose')) {
514
+ publicMethod.close();
515
+ }
516
+ });
517
+
518
+ // Key Bindings
519
+ $(document).bind('keydown.' + prefix, function (e) {
520
+ var key = e.keyCode;
521
+ if (open && settings.get('escKey') && key === 27) {
522
+ e.preventDefault();
523
+ publicMethod.close();
524
+ }
525
+ if (open && settings.get('arrowKey') && $related[1] && !e.altKey) {
526
+ if (key === 37) {
527
+ e.preventDefault();
528
+ $prev.click();
529
+ } else if (key === 39) {
530
+ e.preventDefault();
531
+ $next.click();
532
+ }
533
+ }
534
+ });
535
+
536
+ if ($.isFunction($.fn.on)) {
537
+ // For jQuery 1.7+
538
+ $(document).on('click.'+prefix, '.'+boxElement, clickHandler);
539
+ } else {
540
+ // For jQuery 1.3.x -> 1.6.x
541
+ // This code is never reached in jQuery 1.9, so do not contact me about 'live' being removed.
542
+ // This is not here for jQuery 1.9, it's here for legacy users.
543
+ $('.'+boxElement).live('click.'+prefix, clickHandler);
544
+ }
545
+ }
546
+ return true;
547
+ }
548
+ return false;
549
+ }
550
+
551
+ // Don't do anything if Colorbox already exists.
552
+ if ($.colorbox) {
553
+ return;
554
+ }
555
+
556
+ // Append the HTML when the DOM loads
557
+ $(appendHTML);
558
+
559
+
560
+ // ****************
561
+ // PUBLIC FUNCTIONS
562
+ // Usage format: $.colorbox.close();
563
+ // Usage from within an iframe: parent.jQuery.colorbox.close();
564
+ // ****************
565
+
566
+ publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) {
567
+ var settings;
568
+ var $obj = this;
569
+
570
+ options = options || {};
571
+
572
+ if ($.isFunction($obj)) { // assume a call to $.colorbox
573
+ $obj = $('<a/>');
574
+ options.open = true;
575
+ } else if (!$obj[0]) { // colorbox being applied to empty collection
576
+ return $obj;
577
+ }
578
+
579
+
580
+ if (!$obj[0]) { // colorbox being applied to empty collection
581
+ return $obj;
582
+ }
583
+
584
+ appendHTML();
585
+
586
+ if (addBindings()) {
587
+
588
+ if (callback) {
589
+ options.onComplete = callback;
590
+ }
591
+
592
+ $obj.each(function () {
593
+ var old = $.data(this, colorbox) || {};
594
+ $.data(this, colorbox, $.extend(old, options));
595
+ }).addClass(boxElement);
596
+
597
+ settings = new Settings($obj[0], options);
598
+
599
+ if (settings.get('open')) {
600
+ launch($obj[0]);
601
+ }
602
+ }
603
+
604
+ return $obj;
605
+ };
606
+
607
+ publicMethod.position = function (speed, loadedCallback) {
608
+ var
609
+ css,
610
+ top = 0,
611
+ left = 0,
612
+ offset = $box.offset(),
613
+ scrollTop,
614
+ scrollLeft;
615
+
616
+ $window.unbind('resize.' + prefix);
617
+
618
+ // remove the modal so that it doesn't influence the document width/height
619
+ $box.css({top: -9e4, left: -9e4});
620
+
621
+ scrollTop = $window.scrollTop();
622
+ scrollLeft = $window.scrollLeft();
623
+
624
+ if (settings.get('fixed')) {
625
+ offset.top -= scrollTop;
626
+ offset.left -= scrollLeft;
627
+ $box.css({position: 'fixed'});
628
+ } else {
629
+ top = scrollTop;
630
+ left = scrollLeft;
631
+ $box.css({position: 'absolute'});
632
+ }
633
+
634
+ // keeps the top and left positions within the browser's viewport.
635
+ if (settings.get('right') !== false) {
636
+ left += Math.max($window.width() - settings.w - loadedWidth - interfaceWidth - setSize(settings.get('right'), 'x'), 0);
637
+ } else if (settings.get('left') !== false) {
638
+ left += setSize(settings.get('left'), 'x');
639
+ } else {
640
+ left += Math.round(Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2);
641
+ }
642
+
643
+ if (settings.get('bottom') !== false) {
644
+ top += Math.max(winheight() - settings.h - loadedHeight - interfaceHeight - setSize(settings.get('bottom'), 'y'), 0);
645
+ } else if (settings.get('top') !== false) {
646
+ top += setSize(settings.get('top'), 'y');
647
+ } else {
648
+ top += Math.round(Math.max(winheight() - settings.h - loadedHeight - interfaceHeight, 0) / 2);
649
+ }
650
+
651
+ $box.css({top: offset.top, left: offset.left, visibility:'visible'});
652
+
653
+ // this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly,
654
+ // but it has to be shrank down around the size of div#colorbox when it's done. If not,
655
+ // it can invoke an obscure IE bug when using iframes.
656
+ $wrap[0].style.width = $wrap[0].style.height = "9999px";
657
+
658
+ function modalDimensions() {
659
+ $topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = (parseInt($box[0].style.width,10) - interfaceWidth)+'px';
660
+ $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = (parseInt($box[0].style.height,10) - interfaceHeight)+'px';
661
+ }
662
+
663
+ css = {width: settings.w + loadedWidth + interfaceWidth, height: settings.h + loadedHeight + interfaceHeight, top: top, left: left};
664
+
665
+ // setting the speed to 0 if the content hasn't changed size or position
666
+ if (speed) {
667
+ var tempSpeed = 0;
668
+ $.each(css, function(i){
669
+ if (css[i] !== previousCSS[i]) {
670
+ tempSpeed = speed;
671
+ return;
672
+ }
673
+ });
674
+ speed = tempSpeed;
675
+ }
676
+
677
+ previousCSS = css;
678
+
679
+ if (!speed) {
680
+ $box.css(css);
681
+ }
682
+
683
+ $box.dequeue().animate(css, {
684
+ duration: speed || 0,
685
+ complete: function () {
686
+ modalDimensions();
687
+
688
+ active = false;
689
+
690
+ // shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation.
691
+ $wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px";
692
+ $wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px";
693
+
694
+ if (settings.get('reposition')) {
695
+ setTimeout(function () { // small delay before binding onresize due to an IE8 bug.
696
+ $window.bind('resize.' + prefix, publicMethod.position);
697
+ }, 1);
698
+ }
699
+
700
+ if (loadedCallback) {
701
+ loadedCallback();
702
+ }
703
+ },
704
+ step: modalDimensions
705
+ });
706
+ };
707
+
708
+ publicMethod.resize = function (options) {
709
+ var scrolltop;
710
+
711
+ if (open) {
712
+ options = options || {};
713
+
714
+ if (options.width) {
715
+ settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth;
716
+ }
717
+
718
+ if (options.innerWidth) {
719
+ settings.w = setSize(options.innerWidth, 'x');
720
+ }
721
+
722
+ $loaded.css({width: settings.w});
723
+
724
+ if (options.height) {
725
+ settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight;
726
+ }
727
+
728
+ if (options.innerHeight) {
729
+ settings.h = setSize(options.innerHeight, 'y');
730
+ }
731
+
732
+ if (!options.innerHeight && !options.height) {
733
+ scrolltop = $loaded.scrollTop();
734
+ $loaded.css({height: "auto"});
735
+ settings.h = $loaded.height();
736
+ }
737
+
738
+ $loaded.css({height: settings.h});
739
+
740
+ if(scrolltop) {
741
+ $loaded.scrollTop(scrolltop);
742
+ }
743
+
744
+ publicMethod.position(settings.get('transition') === "none" ? 0 : settings.get('speed'));
745
+ }
746
+ };
747
+
748
+ publicMethod.prep = function (object) {
749
+ if (!open) {
750
+ return;
751
+ }
752
+
753
+ var callback, speed = settings.get('transition') === "none" ? 0 : settings.get('speed');
754
+
755
+ $loaded.remove();
756
+
757
+ $loaded = $tag(div, 'LoadedContent').append(object);
758
+
759
+ function getWidth() {
760
+ settings.w = settings.w || $loaded.width();
761
+ settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w;
762
+ return settings.w;
763
+ }
764
+ function getHeight() {
765
+ settings.h = settings.h || $loaded.height();
766
+ settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h;
767
+ return settings.h;
768
+ }
769
+
770
+ $loaded.hide()
771
+ .appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations.
772
+ .css({width: getWidth(), overflow: settings.get('scrolling') ? 'auto' : 'hidden'})
773
+ .css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height.
774
+ .prependTo($content);
775
+
776
+ $loadingBay.hide();
777
+
778
+ // 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.
779
+
780
+ $(photo).css({'float': 'none'});
781
+
782
+ setClass(settings.get('className'));
783
+
784
+ callback = function () {
785
+ var total = $related.length,
786
+ iframe,
787
+ complete;
788
+
789
+ if (!open) {
790
+ return;
791
+ }
792
+
793
+ function removeFilter() { // Needed for IE8 in versions of jQuery prior to 1.7.2
794
+ if ($.support.opacity === false) {
795
+ $box[0].style.removeAttribute('filter');
796
+ }
797
+ }
798
+
799
+ complete = function () {
800
+ clearTimeout(loadingTimer);
801
+ $loadingOverlay.hide();
802
+ trigger(event_complete);
803
+ settings.get('onComplete');
804
+ };
805
+
806
+
807
+ $title.html(settings.get('title')).show();
808
+ $loaded.show();
809
+
810
+ if (total > 1) { // handle grouping
811
+ if (typeof settings.get('current') === "string") {
812
+ $current.html(settings.get('current').replace('{current}', index + 1).replace('{total}', total)).show();
813
+ }
814
+
815
+ $next[(settings.get('loop') || index < total - 1) ? "show" : "hide"]().html(settings.get('next'));
816
+ $prev[(settings.get('loop') || index) ? "show" : "hide"]().html(settings.get('previous'));
817
+
818
+ slideshow();
819
+
820
+ // Preloads images within a rel group
821
+ if (settings.get('preloading')) {
822
+ $.each([getIndex(-1), getIndex(1)], function(){
823
+ var img,
824
+ i = $related[this],
825
+ settings = new Settings(i, $.data(i, colorbox)),
826
+ src = settings.get('href');
827
+
828
+ if (src && isImage(settings, src)) {
829
+ src = retinaUrl(settings, src);
830
+ img = document.createElement('img');
831
+ img.src = src;
832
+ }
833
+ });
834
+ }
835
+ } else {
836
+ $groupControls.hide();
837
+ }
838
+
839
+ if (settings.get('iframe')) {
840
+ iframe = document.createElement('iframe');
841
+
842
+ if ('frameBorder' in iframe) {
843
+ iframe.frameBorder = 0;
844
+ }
845
+
846
+ if ('allowTransparency' in iframe) {
847
+ iframe.allowTransparency = "true";
848
+ }
849
+
850
+ if (!settings.get('scrolling')) {
851
+ iframe.scrolling = "no";
852
+ }
853
+
854
+ $(iframe)
855
+ .attr({
856
+ src: settings.get('href'),
857
+ name: (new Date()).getTime(), // give the iframe a unique name to prevent caching
858
+ 'class': prefix + 'Iframe',
859
+ allowFullScreen : true // allow HTML5 video to go fullscreen
860
+ })
861
+ .one('load', complete)
862
+ .appendTo($loaded);
863
+
864
+ $events.one(event_purge, function () {
865
+ iframe.src = "//about:blank";
866
+ });
867
+
868
+ if (settings.get('fastIframe')) {
869
+ $(iframe).trigger('load');
870
+ }
871
+ } else {
872
+ complete();
873
+ }
874
+
875
+ if (settings.get('transition') === 'fade') {
876
+ $box.fadeTo(speed, 1, removeFilter);
877
+ } else {
878
+ removeFilter();
879
+ }
880
+ };
881
+
882
+ if (settings.get('transition') === 'fade') {
883
+ $box.fadeTo(speed, 0, function () {
884
+ publicMethod.position(0, callback);
885
+ });
886
+ } else {
887
+ publicMethod.position(speed, callback);
888
+ }
889
+ };
890
+
891
+ function load () {
892
+ var href, setResize, prep = publicMethod.prep, $inline, request = ++requests;
893
+
894
+ active = true;
895
+
896
+ photo = false;
897
+
898
+ trigger(event_purge);
899
+ trigger(event_load);
900
+ settings.get('onLoad');
901
+
902
+ settings.h = settings.get('height') ?
903
+ setSize(settings.get('height'), 'y') - loadedHeight - interfaceHeight :
904
+ settings.get('innerHeight') && setSize(settings.get('innerHeight'), 'y');
905
+
906
+ settings.w = settings.get('width') ?
907
+ setSize(settings.get('width'), 'x') - loadedWidth - interfaceWidth :
908
+ settings.get('innerWidth') && setSize(settings.get('innerWidth'), 'x');
909
+
910
+ // Sets the minimum dimensions for use in image scaling
911
+ settings.mw = settings.w;
912
+ settings.mh = settings.h;
913
+
914
+ // Re-evaluate the minimum width and height based on maxWidth and maxHeight values.
915
+ // If the width or height exceed the maxWidth or maxHeight, use the maximum values instead.
916
+ if (settings.get('maxWidth')) {
917
+ settings.mw = setSize(settings.get('maxWidth'), 'x') - loadedWidth - interfaceWidth;
918
+ settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw;
919
+ }
920
+ if (settings.get('maxHeight')) {
921
+ settings.mh = setSize(settings.get('maxHeight'), 'y') - loadedHeight - interfaceHeight;
922
+ settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh;
923
+ }
924
+
925
+ href = settings.get('href');
926
+
927
+ loadingTimer = setTimeout(function () {
928
+ $loadingOverlay.show();
929
+ }, 100);
930
+
931
+ if (settings.get('inline')) {
932
+ var $target = $(href);
933
+ // Inserts an empty placeholder where inline content is being pulled from.
934
+ // An event is bound to put inline content back when Colorbox closes or loads new content.
935
+ $inline = $('<div>').hide().insertBefore($target);
936
+
937
+ $events.one(event_purge, function () {
938
+ $inline.replaceWith($target);
939
+ });
940
+
941
+ prep($target);
942
+ } else if (settings.get('iframe')) {
943
+ // IFrame element won't be added to the DOM until it is ready to be displayed,
944
+ // to avoid problems with DOM-ready JS that might be trying to run in that iframe.
945
+ prep(" ");
946
+ } else if (settings.get('html')) {
947
+ prep(settings.get('html'));
948
+ } else if (isImage(settings, href)) {
949
+
950
+ href = retinaUrl(settings, href);
951
+
952
+ photo = new Image();
953
+
954
+ $(photo)
955
+ .addClass(prefix + 'Photo')
956
+ .bind('error',function () {
957
+ prep($tag(div, 'Error').html(settings.get('imgError')));
958
+ })
959
+ .one('load', function () {
960
+ if (request !== requests) {
961
+ return;
962
+ }
963
+
964
+ // A small pause because some browsers will occassionaly report a
965
+ // img.width and img.height of zero immediately after the img.onload fires
966
+ setTimeout(function(){
967
+ var percent;
968
+
969
+ $.each(['alt', 'longdesc', 'aria-describedby'], function(i,val){
970
+ var attr = $(settings.el).attr(val) || $(settings.el).attr('data-'+val);
971
+ if (attr) {
972
+ photo.setAttribute(val, attr);
973
+ }
974
+ });
975
+
976
+ if (settings.get('retinaImage') && window.devicePixelRatio > 1) {
977
+ photo.height = photo.height / window.devicePixelRatio;
978
+ photo.width = photo.width / window.devicePixelRatio;
979
+ }
980
+
981
+ if (settings.get('scalePhotos')) {
982
+ setResize = function () {
983
+ photo.height -= photo.height * percent;
984
+ photo.width -= photo.width * percent;
985
+ };
986
+ if (settings.mw && photo.width > settings.mw) {
987
+ percent = (photo.width - settings.mw) / photo.width;
988
+ setResize();
989
+ }
990
+ if (settings.mh && photo.height > settings.mh) {
991
+ percent = (photo.height - settings.mh) / photo.height;
992
+ setResize();
993
+ }
994
+ }
995
+
996
+ if (settings.h) {
997
+ photo.style.marginTop = Math.max(settings.mh - photo.height, 0) / 2 + 'px';
998
+ }
999
+
1000
+ if ($related[1] && (settings.get('loop') || $related[index + 1])) {
1001
+ photo.style.cursor = 'pointer';
1002
+ photo.onclick = function () {
1003
+ publicMethod.next();
1004
+ };
1005
+ }
1006
+
1007
+ photo.style.width = photo.width + 'px';
1008
+ photo.style.height = photo.height + 'px';
1009
+ prep(photo);
1010
+ }, 1);
1011
+ });
1012
+
1013
+ photo.src = href;
1014
+
1015
+ } else if (href) {
1016
+ $loadingBay.load(href, settings.get('data'), function (data, status) {
1017
+ if (request === requests) {
1018
+ prep(status === 'error' ? $tag(div, 'Error').html(settings.get('xhrError')) : $(this).contents());
1019
+ }
1020
+ });
1021
+ }
1022
+ }
1023
+
1024
+ // Navigates to the next page/image in a set.
1025
+ publicMethod.next = function () {
1026
+ if (!active && $related[1] && (settings.get('loop') || $related[index + 1])) {
1027
+ index = getIndex(1);
1028
+ launch($related[index]);
1029
+ }
1030
+ };
1031
+
1032
+ publicMethod.prev = function () {
1033
+ if (!active && $related[1] && (settings.get('loop') || index)) {
1034
+ index = getIndex(-1);
1035
+ launch($related[index]);
1036
+ }
1037
+ };
1038
+
1039
+ // Note: to use this within an iframe use the following format: parent.jQuery.colorbox.close();
1040
+ publicMethod.close = function () {
1041
+ if (open && !closing) {
1042
+
1043
+ closing = true;
1044
+ open = false;
1045
+ trigger(event_cleanup);
1046
+ settings.get('onCleanup');
1047
+ $window.unbind('.' + prefix);
1048
+ $overlay.fadeTo(settings.get('fadeOut') || 0, 0);
1049
+
1050
+ $box.stop().fadeTo(settings.get('fadeOut') || 0, 0, function () {
1051
+ $box.hide();
1052
+ $overlay.hide();
1053
+ trigger(event_purge);
1054
+ $loaded.remove();
1055
+
1056
+ setTimeout(function () {
1057
+ closing = false;
1058
+ trigger(event_closed);
1059
+ settings.get('onClosed');
1060
+ }, 1);
1061
+ });
1062
+ }
1063
+ };
1064
+
1065
+ // Removes changes Colorbox made to the document, but does not remove the plugin.
1066
+ publicMethod.remove = function () {
1067
+ if (!$box) { return; }
1068
+
1069
+ $box.stop();
1070
+ $.colorbox.close();
1071
+ $box.stop(false, true).remove();
1072
+ $overlay.remove();
1073
+ closing = false;
1074
+ $box = null;
1075
+ $('.' + boxElement)
1076
+ .removeData(colorbox)
1077
+ .removeClass(boxElement);
1078
+
1079
+ $(document).unbind('click.'+prefix).unbind('keydown.'+prefix);
1080
+ };
1081
+
1082
+ // A method for fetching the current element Colorbox is referencing.
1083
+ // returns a jQuery object.
1084
+ publicMethod.element = function () {
1085
+ return $(settings.el);
1086
+ };
1087
+
1088
+ publicMethod.settings = defaults;
1089
+
1090
+ }(jQuery, document, window));