storys 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MDUzYzg1MDc5MjJiNzE4ZGU5OTA5ODcyNWYyODYxMmMzYjc0YjA5YQ==
5
- data.tar.gz: !binary |-
6
- MWE4MTUyMmNhMGEwODQ3ZWNkNDA3NmNhYWQzZDliYmE1YjkxMTgyMQ==
2
+ SHA1:
3
+ metadata.gz: 0427bf14c6198faa4b38f5447c6eb6801da34d5b
4
+ data.tar.gz: e740055662f4cf1d7a78879158edb74e87ea93f0
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- OWVjYWZlYWM2OTM0NzFiYWJiMzEzMGNkNzY1NjljNDE1ZGUxMTFmZWE4YmY1
10
- YjNmMGY0ZDhkZjQ4MWEwZDM3OGEyN2E4ODgxNzE5NTRlMjdmNDk4MjY0Yzgw
11
- OWY2NjVhMGZhMDczYmVjOGM5ZTk3ZGY1Njg4Zjk4MjI2NDVkYWY=
12
- data.tar.gz: !binary |-
13
- YWQwOWY4MGZlMThhMTg2MzJkNTQ4ODU4NDlhNWFmM2I5MzJmYjllNDI4OWEw
14
- YTY0Yzk5YmU4OThiNmM5YTA5Nzk5OWQyZThjOTBlMzIzYWE4MjIwOGY0NTUz
15
- NzdkYmY2ZGZmZDdjYjQ1ZjFjZDljZjEzYmE0ZDM4ZTBlZGUyZWQ=
6
+ metadata.gz: 2a6882997b395f27876205b25123e4009f0868684631f39138fcd92305dbf679562924280acbfaec56698414a9aaa3dbb51334bae79ce0a4ab3b8a4edddec362
7
+ data.tar.gz: 84f55cf3dd6eab044e561c44cb58bb0b69570f0c2c2160ee750e606c029e017febc7088c2f1f7fe1c3062091882967e268aa0ae98b0d215d4d97a89087118169
data/app/index.html CHANGED
@@ -1,5 +1,5 @@
1
1
  <!doctype html>
2
- <html>
2
+ <html manifest="manifest">
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <title>Storys</title>
data/app/manifest ADDED
@@ -0,0 +1,22 @@
1
+ CACHE MANIFEST
2
+ # Timestamp 1393852279
3
+ CACHE:
4
+ css/lib/bootstrap.css
5
+ css/app.css
6
+ css/views.index.css
7
+ css/views.show.css
8
+ js/lib/jquery-2.0.3.js
9
+ js/lib/bootstrap.js
10
+ js/lib/underscore.js
11
+ js/lib/jquery.browser.js
12
+ js/jquery.twoup.js
13
+ js/framework.js
14
+ js/controllers.index.js
15
+ js/controllers.show.js
16
+ js/app.js
17
+ img/icons/page_white_stack.png
18
+ fonts/lib/glyphicons-halflings-regular.eot
19
+ fonts/lib/glyphicons-halflings-regular.svg
20
+ fonts/lib/glyphicons-halflings-regular.ttf
21
+ fonts/lib/glyphicons-halflings-regular.woff
22
+ data.json
@@ -1,18 +1,19 @@
1
1
  class Storys::Package
2
- attr_reader :root_path
3
- attr_reader :package_path
2
+ attr_reader :path
3
+ attr_reader :app_path
4
4
 
5
- def initialize(root_path)
6
- raise "root_path must be an instance of Pathname" unless root_path.is_a?(Pathname)
5
+ def initialize(path)
6
+ raise "path must be an instance of Pathname" unless path.is_a?(Pathname)
7
7
 
8
- @root_path = root_path
9
- @package_path = root_path + ".storys/"
8
+ @path = path
9
+ @app_path = path + ".storys/"
10
10
  end
11
11
 
12
12
  def pathname_to_url(path, relative_from)
13
- URI.escape(path.relative_path_from(relative_from).to_s)
13
+ URI.escape(path.relative_path_from(relative_from).cleanpath.to_s)
14
14
  end
15
15
 
16
+ #FIXME: Doesn't work!
16
17
  def url_to_pathname(url)
17
18
  path = Addressable::URI.unencode_component(url.normalized_path)
18
19
  path.gsub!(/^\//, "") #Make relative, if we allow mounting at a different root URL this will need to remove the root instead of just '/'
@@ -20,7 +21,7 @@ class Storys::Package
20
21
  end
21
22
 
22
23
  def update
23
- package_path.mkdir unless File.exists?(package_path)
24
+ app_path.mkdir unless File.exists?(app_path)
24
25
  update_app
25
26
  Storys::Update.new(self)
26
27
  end
@@ -29,20 +30,20 @@ class Storys::Package
29
30
  dev = ENV["STORYS_ENV"] == "development"
30
31
 
31
32
  app_children_paths.each do |file|
32
- storys_file = package_path + file.basename
33
+ storys_file = app_path + file.basename
33
34
  FileUtils.rm_rf(storys_file, :verbose => dev)
34
35
  end
35
36
 
36
37
  if dev
37
38
  app_children_paths.each do |file|
38
- storys_file = package_path + file.basename
39
+ storys_file = app_path + file.basename
39
40
  FileUtils.ln_sf(file, storys_file, :verbose => dev)
40
41
  end
41
42
  else
42
- FileUtils.cp_r(Storys::Package.gem_path + "app/.", package_path, :verbose => dev)
43
+ FileUtils.cp_r(Storys::Package.gem_path + "app/.", app_path, :verbose => dev)
43
44
  end
44
45
 
45
- FileUtils.chmod_R(0755, package_path, :verbose => dev)
46
+ FileUtils.chmod_R(0755, app_path, :verbose => dev)
46
47
  end
47
48
 
48
49
  def self.gem_path
@@ -63,7 +64,7 @@ class Storys::Package
63
64
 
64
65
  private
65
66
  def app_children_paths
66
- app_path = Storys::Package.gem_path + "app/"
67
- app_path.children.reject { |f| f.basename.to_s == "img"} #TODO: Deal with this directory properly
67
+ gem_app_path = Storys::Package.gem_path + "app/"
68
+ gem_app_path.children.reject { |f| f.basename.to_s == "img"} #TODO: Deal with this directory properly
68
69
  end
69
70
  end
data/lib/storys/story.rb CHANGED
@@ -17,14 +17,14 @@ class Storys::Story
17
17
  end
18
18
 
19
19
  def url
20
- package.pathname_to_url(path, package.package_path)
20
+ package.pathname_to_url(path, package.app_path)
21
21
  end
22
22
 
23
23
  def title
24
24
  title = title_from_html
25
25
  title = path.basename.to_s.chomp(path.extname.to_s) if title == ""
26
26
 
27
- directory_path = path.relative_path_from(package.root_path).dirname.to_s
27
+ directory_path = path.relative_path_from(package.path).dirname.to_s
28
28
 
29
29
  title = "#{directory_path}/#{title}" unless directory_path == "" || directory_path == "."
30
30
  title = title.gsub("/", " / ")
@@ -46,6 +46,12 @@ class Storys::Story
46
46
  }
47
47
  end
48
48
 
49
+ def update_manifest
50
+ manifest_path = package.pathname_to_url(package.app_path + "manifest", path.dirname)
51
+ new_html = html.sub(/<html.*?>/, "<html manifest=\"#{manifest_path}\">")
52
+ File.open(path, "w") { |f| f << new_html }
53
+ end
54
+
49
55
  private
50
56
 
51
57
  def title_from_html
@@ -54,7 +60,7 @@ class Storys::Story
54
60
  end
55
61
 
56
62
  def word_count_from_html
57
- html =~ /<body>(.*?)<\/body>/m
63
+ html =~ /<body.*?>(.*?)<\/body>/m
58
64
  body = CGI::unescapeHTML($1.gsub(/<\/?(p|b|i|h[1234567]).*?>/m, " "))
59
65
  (title + " " + (body ? body : "")).split(/\s+/).length
60
66
  end
data/lib/storys/update.rb CHANGED
@@ -5,7 +5,7 @@ class Storys::Update
5
5
  def initialize(package)
6
6
  @package = package
7
7
 
8
- @files = package.root_path.descendant_files.reject { |p| p.basename.to_s[0..0] == '.' }
8
+ @files = package.path.descendant_files.reject { |p| p.basename.to_s[0..0] == '.' }
9
9
  @stories = []
10
10
  #load_data
11
11
  process
@@ -14,7 +14,7 @@ class Storys::Update
14
14
  end
15
15
 
16
16
  def load_data
17
- self.stories = (Storys::Package.load_json(package.package_path + "data.json") || []).map { |b| Storys::Story.from_hash(package, b) }
17
+ self.stories = (Storys::Package.load_json(package.app_path + "data.json") || []).map { |b| Storys::Story.from_hash(package, b) }
18
18
  end
19
19
 
20
20
  def save_data
@@ -26,10 +26,9 @@ class Storys::Update
26
26
 
27
27
  stories_hashes << s.to_hash
28
28
  end
29
- Storys::Package.save_json(package.package_path + "data.json", stories_hashes)
29
+ Storys::Package.save_json(package.app_path + "data.json", stories_hashes)
30
30
  end
31
31
 
32
-
33
32
  def process
34
33
  @files.each_with_index do |f, i|
35
34
  $stdout.write "\rProcessing #{i + 1} of #{@files.length} (#{(((i + 1) / @files.length.to_f) * 100.0).round}%)"
@@ -55,6 +54,7 @@ class Storys::Update
55
54
 
56
55
  def created(f)
57
56
  story = Storys::Story.new(package, f)
57
+ story.update_manifest
58
58
  stories << story
59
59
  end
60
60
 
@@ -1,3 +1,3 @@
1
1
  module Storys
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brenton "B-Train" Fletcher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-18 00:00:00.000000000 Z
11
+ date: 2014-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.0.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: addressable
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 2.3.5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.3.5
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: naturally
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.0.3
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.0.3
55
55
  description: A collection of stories is a directory (the container) containing 1..*
@@ -65,7 +65,7 @@ executables:
65
65
  extensions: []
66
66
  extra_rdoc_files: []
67
67
  files:
68
- - .gitignore
68
+ - ".gitignore"
69
69
  - LICENSE
70
70
  - Rakefile
71
71
  - app/css/app.css
@@ -1089,8 +1089,8 @@ files:
1089
1089
  - app/js/lib/jquery-2.0.3.js
1090
1090
  - app/js/lib/jquery.ba-bbq.js
1091
1091
  - app/js/lib/jquery.browser.js
1092
- - app/js/lib/jquery.colorbox.js
1093
1092
  - app/js/lib/underscore.js
1093
+ - app/manifest
1094
1094
  - bin/storys
1095
1095
  - lib/storys.rb
1096
1096
  - lib/storys/core_ext/pathname.rb
@@ -1108,17 +1108,17 @@ require_paths:
1108
1108
  - lib
1109
1109
  required_ruby_version: !ruby/object:Gem::Requirement
1110
1110
  requirements:
1111
- - - ! '>='
1111
+ - - ">="
1112
1112
  - !ruby/object:Gem::Version
1113
1113
  version: '0'
1114
1114
  required_rubygems_version: !ruby/object:Gem::Requirement
1115
1115
  requirements:
1116
- - - ! '>='
1116
+ - - ">="
1117
1117
  - !ruby/object:Gem::Version
1118
1118
  version: 1.3.6
1119
1119
  requirements: []
1120
1120
  rubyforge_project: storys
1121
- rubygems_version: 2.1.10
1121
+ rubygems_version: 2.2.2
1122
1122
  signing_key:
1123
1123
  specification_version: 4
1124
1124
  summary: Storys indexes a collection of stories and generates a SPA that browses the
@@ -1,788 +0,0 @@
1
- // ColorBox v1.3.15 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+
2
- // Copyright (c) 2010 Jack Moore - jack@colorpowered.com
3
- // Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
4
- (function ($, window) {
5
-
6
- var
7
- // ColorBox Default Settings.
8
- // See http://colorpowered.com/colorbox for details.
9
- defaults = {
10
- transition: "elastic",
11
- speed: 300,
12
- width: false,
13
- initialWidth: "600",
14
- innerWidth: false,
15
- maxWidth: false,
16
- height: false,
17
- initialHeight: "450",
18
- innerHeight: false,
19
- maxHeight: false,
20
- scalePhotos: true,
21
- scrolling: true,
22
- inline: false,
23
- html: false,
24
- iframe: false,
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
- loop: true,
38
- slideshow: false,
39
- slideshowAuto: true,
40
- slideshowSpeed: 2500,
41
- slideshowStart: "start slideshow",
42
- slideshowStop: "stop slideshow",
43
- onOpen: false,
44
- onLoad: false,
45
- onComplete: false,
46
- onCleanup: false,
47
- onClosed: false,
48
- overlayClose: true,
49
- escKey: true,
50
- arrowKey: true
51
- },
52
-
53
- // Abstracting the HTML and event identifiers for easy rebranding
54
- colorbox = 'colorbox',
55
- prefix = 'cbox',
56
-
57
- // Events
58
- event_open = prefix + '_open',
59
- event_load = prefix + '_load',
60
- event_complete = prefix + '_complete',
61
- event_cleanup = prefix + '_cleanup',
62
- event_closed = prefix + '_closed',
63
- event_purge = prefix + '_purge',
64
- event_loaded = prefix + '_loaded',
65
-
66
- // Special Handling for IE
67
- isIE = $.browser.msie && !$.support.opacity, // feature detection alone gave a false positive on at least one phone browser and on some development versions of Chrome.
68
- isIE6 = isIE && $.browser.version < 7,
69
- event_ie6 = prefix + '_IE6',
70
-
71
- // Cached jQuery Object Variables
72
- $overlay,
73
- $box,
74
- $wrap,
75
- $content,
76
- $topBorder,
77
- $leftBorder,
78
- $rightBorder,
79
- $bottomBorder,
80
- $related,
81
- $window,
82
- $loaded,
83
- $loadingBay,
84
- $loadingOverlay,
85
- $title,
86
- $current,
87
- $slideshow,
88
- $next,
89
- $prev,
90
- $close,
91
-
92
- // Variables for cached values or use across multiple functions
93
- interfaceHeight,
94
- interfaceWidth,
95
- loadedHeight,
96
- loadedWidth,
97
- element,
98
- index,
99
- settings,
100
- open,
101
- active,
102
- closing = false,
103
-
104
- publicMethod,
105
- boxElement = prefix + 'Element';
106
-
107
- // ****************
108
- // HELPER FUNCTIONS
109
- // ****************
110
-
111
- // jQuery object generator to reduce code size
112
- function $div(id, css) {
113
- id = id ? ' id="' + prefix + id + '"' : '';
114
- css = css ? ' style="' + css + '"' : '';
115
- return $('<div' + id + css + '/>');
116
- }
117
-
118
- // Convert % values to pixels
119
- function setSize(size, dimension) {
120
- dimension = dimension === 'x' ? $window.width() : $window.height();
121
- return (typeof size === 'string') ? Math.round((/%/.test(size) ? (dimension / 100) * parseInt(size, 10) : parseInt(size, 10))) : size;
122
- }
123
-
124
- // Checks an href to see if it is a photo.
125
- // There is a force photo option (photo: true) for hrefs that cannot be matched by this regex.
126
- function isImage(url) {
127
- return settings.photo || /\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i.test(url);
128
- }
129
-
130
- // Assigns function results to their respective settings. This allows functions to be used as values.
131
- function process(settings) {
132
- for (var i in settings) {
133
- if ($.isFunction(settings[i]) && i.substring(0, 2) !== 'on') { // checks to make sure the function isn't one of the callbacks, they will be handled at the appropriate time.
134
- settings[i] = settings[i].call(element);
135
- }
136
- }
137
- settings.rel = settings.rel || element.rel || 'nofollow';
138
- settings.href = settings.href || $(element).attr('href');
139
- settings.title = settings.title || element.title;
140
- return settings;
141
- }
142
-
143
- function trigger(event, callback) {
144
- if (callback) {
145
- callback.call(element);
146
- }
147
- $.event.trigger(event);
148
- }
149
-
150
- // Slideshow functionality
151
- function slideshow() {
152
- var
153
- timeOut,
154
- className = prefix + "Slideshow_",
155
- click = "click." + prefix,
156
- start,
157
- stop,
158
- clear;
159
-
160
- if (settings.slideshow && $related[1]) {
161
- start = function () {
162
- $slideshow
163
- .text(settings.slideshowStop)
164
- .unbind(click)
165
- .bind(event_complete, function () {
166
- if (index < $related.length - 1 || settings.loop) {
167
- timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
168
- }
169
- })
170
- .bind(event_load, function () {
171
- clearTimeout(timeOut);
172
- })
173
- .one(click + ' ' + event_cleanup, stop);
174
- $box.removeClass(className + "off").addClass(className + "on");
175
- timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
176
- };
177
-
178
- stop = function () {
179
- clearTimeout(timeOut);
180
- $slideshow
181
- .text(settings.slideshowStart)
182
- .unbind([event_complete, event_load, event_cleanup, click].join(' '))
183
- .one(click, start);
184
- $box.removeClass(className + "on").addClass(className + "off");
185
- };
186
-
187
- if (settings.slideshowAuto) {
188
- start();
189
- } else {
190
- stop();
191
- }
192
- }
193
- }
194
-
195
- function launch(elem) {
196
- if (!closing) {
197
-
198
- element = elem;
199
-
200
- settings = process($.extend({}, $.data(element, colorbox)));
201
-
202
- $related = $(element);
203
-
204
- index = 0;
205
-
206
- if (settings.rel !== 'nofollow') {
207
- $related = $('.' + boxElement).filter(function () {
208
- var relRelated = $.data(this, colorbox).rel || this.rel;
209
- return (relRelated === settings.rel);
210
- });
211
- index = $related.index(element);
212
-
213
- // Check direct calls to ColorBox.
214
- if (index === -1) {
215
- $related = $related.add(element);
216
- index = $related.length - 1;
217
- }
218
- }
219
-
220
- if (!open) {
221
- open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys.
222
-
223
- $box.show();
224
-
225
- if (settings.returnFocus) {
226
- try {
227
- element.blur();
228
- $(element).one(event_closed, function () {
229
- try {
230
- this.focus();
231
- } catch (e) {
232
- // do nothing
233
- }
234
- });
235
- } catch (e) {
236
- // do nothing
237
- }
238
- }
239
-
240
- // +settings.opacity avoids a problem in IE when using non-zero-prefixed-string-values, like '.5'
241
- $overlay.css({"opacity": +settings.opacity, "cursor": settings.overlayClose ? "pointer" : "auto"}).show();
242
-
243
- // Opens inital empty ColorBox prior to content being loaded.
244
- settings.w = setSize(settings.initialWidth, 'x');
245
- settings.h = setSize(settings.initialHeight, 'y');
246
- publicMethod.position(0);
247
-
248
- if (isIE6) {
249
- $window.bind('resize.' + event_ie6 + ' scroll.' + event_ie6, function () {
250
- $overlay.css({width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft()});
251
- }).trigger('scroll.' + event_ie6);
252
- }
253
-
254
- trigger(event_open, settings.onOpen);
255
-
256
- $current.add($prev).add($next).add($slideshow).add($title).hide();
257
-
258
- $close.html(settings.close).show();
259
- }
260
-
261
- publicMethod.load(true);
262
- }
263
- }
264
-
265
- // ****************
266
- // PUBLIC FUNCTIONS
267
- // Usage format: $.fn.colorbox.close();
268
- // Usage from within an iframe: parent.$.fn.colorbox.close();
269
- // ****************
270
-
271
- publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) {
272
- var $this = this, autoOpen;
273
-
274
- if (!$this[0] && $this.selector) { // if a selector was given and it didn't match any elements, go ahead and exit.
275
- return $this;
276
- }
277
-
278
- options = options || {};
279
-
280
- if (callback) {
281
- options.onComplete = callback;
282
- }
283
-
284
- if (!$this[0] || $this.selector === undefined) { // detects $.colorbox() and $.fn.colorbox()
285
- $this = $('<a/>');
286
- options.open = true; // assume an immediate open
287
- }
288
-
289
- $this.each(function () {
290
- $.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options));
291
- $(this).addClass(boxElement);
292
- });
293
-
294
- autoOpen = options.open;
295
-
296
- if ($.isFunction(autoOpen)) {
297
- autoOpen = autoOpen.call($this);
298
- }
299
-
300
- if (autoOpen) {
301
- launch($this[0]);
302
- }
303
-
304
- return $this;
305
- };
306
-
307
- // Initialize ColorBox: store common calculations, preload the interface graphics, append the html.
308
- // This preps colorbox for a speedy open when clicked, and lightens the burdon on the browser by only
309
- // having to run once, instead of each time colorbox is opened.
310
- publicMethod.init = function () {
311
- // Create & Append jQuery Objects
312
- $window = $(window);
313
- $box = $div().attr({id: colorbox, 'class': isIE ? prefix + 'IE' : ''});
314
- $overlay = $div("Overlay", isIE6 ? 'position:absolute' : '').hide();
315
-
316
- $wrap = $div("Wrapper");
317
- $content = $div("Content").append(
318
- $loaded = $div("LoadedContent", 'width:0; height:0; overflow:hidden'),
319
- $loadingOverlay = $div("LoadingOverlay").add($div("LoadingGraphic")),
320
- $title = $div("Title"),
321
- $current = $div("Current"),
322
- $next = $div("Next"),
323
- $prev = $div("Previous"),
324
- $slideshow = $div("Slideshow").bind(event_open, slideshow),
325
- $close = $div("Close")
326
- );
327
- $wrap.append( // The 3x3 Grid that makes up ColorBox
328
- $div().append(
329
- $div("TopLeft"),
330
- $topBorder = $div("TopCenter"),
331
- $div("TopRight")
332
- ),
333
- $div(false, 'clear:left').append(
334
- $leftBorder = $div("MiddleLeft"),
335
- $content,
336
- $rightBorder = $div("MiddleRight")
337
- ),
338
- $div(false, 'clear:left').append(
339
- $div("BottomLeft"),
340
- $bottomBorder = $div("BottomCenter"),
341
- $div("BottomRight")
342
- )
343
- ).children().children().css({'float': 'left'});
344
-
345
- $loadingBay = $div(false, 'position:absolute; width:9999px; visibility:hidden; display:none');
346
-
347
- $('body').prepend($overlay, $box.append($wrap, $loadingBay));
348
-
349
- $content.children()
350
- .hover(function () {
351
- $(this).addClass('hover');
352
- }, function () {
353
- $(this).removeClass('hover');
354
- }).addClass('hover');
355
-
356
- // Cache values needed for size calculations
357
- interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height();//Subtraction needed for IE6
358
- interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width();
359
- loadedHeight = $loaded.outerHeight(true);
360
- loadedWidth = $loaded.outerWidth(true);
361
-
362
- // Setting padding to remove the need to do size conversions during the animation step.
363
- $box.css({"padding-bottom": interfaceHeight, "padding-right": interfaceWidth}).hide();
364
-
365
- // Setup button events.
366
- $next.click(publicMethod.next);
367
- $prev.click(publicMethod.prev);
368
- $close.click(publicMethod.close);
369
-
370
- // Adding the 'hover' class allowed the browser to load the hover-state
371
- // background graphics. The class can now can be removed.
372
- $content.children().removeClass('hover');
373
-
374
- $('.' + boxElement).live('click', function (e) {
375
- // checks to see if it was a non-left mouse-click and for clicks modified with ctrl, shift, or alt.
376
- if (!((e.button !== 0 && typeof e.button !== 'undefined') || e.ctrlKey || e.shiftKey || e.altKey)) {
377
- e.preventDefault();
378
- launch(this);
379
- }
380
- });
381
-
382
- $overlay.click(function () {
383
- if (settings.overlayClose) {
384
- publicMethod.close();
385
- }
386
- });
387
-
388
- // Set Navigation Key Bindings
389
- $(document).bind("keydown", function (e) {
390
- if (open && settings.escKey && e.keyCode === 27) {
391
- e.preventDefault();
392
- publicMethod.close();
393
- }
394
- if (open && settings.arrowKey && !active && $related[1]) {
395
- if (e.keyCode === 37 && (index || settings.loop)) {
396
- e.preventDefault();
397
- $prev.click();
398
- } else if (e.keyCode === 39 && (index < $related.length - 1 || settings.loop)) {
399
- e.preventDefault();
400
- $next.click();
401
- }
402
- }
403
- });
404
- };
405
-
406
- publicMethod.remove = function () {
407
- $box.add($overlay).remove();
408
- $('.' + boxElement).die('click').removeData(colorbox).removeClass(boxElement);
409
- };
410
-
411
- publicMethod.position = function (speed, loadedCallback) {
412
- var
413
- animate_speed,
414
- // keeps the top and left positions within the browser's viewport.
415
- posTop = Math.max(document.documentElement.clientHeight - settings.h - loadedHeight - interfaceHeight, 0) / 2 + $window.scrollTop(),
416
- posLeft = Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2 + $window.scrollLeft();
417
-
418
- // setting the speed to 0 to reduce the delay between same-sized content.
419
- animate_speed = ($box.width() === settings.w + loadedWidth && $box.height() === settings.h + loadedHeight) ? 0 : speed;
420
-
421
- // this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly,
422
- // but it has to be shrank down around the size of div#colorbox when it's done. If not,
423
- // it can invoke an obscure IE bug when using iframes.
424
- $wrap[0].style.width = $wrap[0].style.height = "9999px";
425
-
426
- function modalDimensions(that) {
427
- // loading overlay height has to be explicitly set for IE6.
428
- $topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = that.style.width;
429
- $loadingOverlay[0].style.height = $loadingOverlay[1].style.height = $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height;
430
- }
431
-
432
- $box.dequeue().animate({width: settings.w + loadedWidth, height: settings.h + loadedHeight, top: posTop, left: posLeft}, {
433
- duration: animate_speed,
434
- complete: function () {
435
- modalDimensions(this);
436
-
437
- active = false;
438
-
439
- // shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation.
440
- $wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px";
441
- $wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px";
442
-
443
- if (loadedCallback) {
444
- loadedCallback();
445
- }
446
- },
447
- step: function () {
448
- modalDimensions(this);
449
- }
450
- });
451
- };
452
-
453
- publicMethod.resize = function (options) {
454
- if (open) {
455
- options = options || {};
456
-
457
- if (options.width) {
458
- settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth;
459
- }
460
- if (options.innerWidth) {
461
- settings.w = setSize(options.innerWidth, 'x');
462
- }
463
- $loaded.css({width: settings.w});
464
-
465
- if (options.height) {
466
- settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight;
467
- }
468
- if (options.innerHeight) {
469
- settings.h = setSize(options.innerHeight, 'y');
470
- }
471
- if (!options.innerHeight && !options.height) {
472
- var $child = $loaded.wrapInner("<div style='overflow:auto'></div>").children(); // temporary wrapper to get an accurate estimate of just how high the total content should be.
473
- settings.h = $child.height();
474
- $child.replaceWith($child.children()); // ditch the temporary wrapper div used in height calculation
475
- }
476
- $loaded.css({height: settings.h});
477
-
478
- publicMethod.position(settings.transition === "none" ? 0 : settings.speed);
479
- }
480
- };
481
-
482
- publicMethod.prep = function (object) {
483
- if (!open) {
484
- return;
485
- }
486
-
487
- var photo,
488
- speed = settings.transition === "none" ? 0 : settings.speed;
489
-
490
- $window.unbind('resize.' + prefix);
491
- $loaded.remove();
492
- $loaded = $div('LoadedContent').html(object);
493
-
494
- function getWidth() {
495
- settings.w = settings.w || $loaded.width();
496
- settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w;
497
- return settings.w;
498
- }
499
- function getHeight() {
500
- settings.h = settings.h || $loaded.height();
501
- settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h;
502
- return settings.h;
503
- }
504
-
505
- $loaded.hide()
506
- .appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations.
507
- .css({width: getWidth(), overflow: settings.scrolling ? 'auto' : 'hidden'})
508
- .css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height.
509
- .prependTo($content);
510
-
511
- $loadingBay.hide();
512
-
513
- // 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.
514
- $('#' + prefix + 'Photo').css({cssFloat: 'none', marginLeft: 'auto', marginRight: 'auto'});
515
-
516
- // Hides SELECT elements in IE6 because they would otherwise sit on top of the overlay.
517
- if (isIE6) {
518
- $('select').not($box.find('select')).filter(function () {
519
- return this.style.visibility !== 'hidden';
520
- }).css({'visibility': 'hidden'}).one(event_cleanup, function () {
521
- this.style.visibility = 'inherit';
522
- });
523
- }
524
-
525
- function setPosition(s) {
526
- var prev, prevSrc, next, nextSrc, total = $related.length, loop = settings.loop;
527
- publicMethod.position(s, function () {
528
- function defilter() {
529
- if (isIE) {
530
- //IE adds a filter when ColorBox fades in and out that can cause problems if the loaded content contains transparent pngs.
531
- $box[0].style.removeAttribute("filter");
532
- }
533
- }
534
-
535
- if (!open) {
536
- return;
537
- }
538
-
539
- if (isIE) {
540
- //This fadeIn helps the bicubic resampling to kick-in.
541
- if (photo) {
542
- $loaded.fadeIn(100);
543
- }
544
- }
545
-
546
- $loaded.show();
547
-
548
- trigger(event_loaded);
549
-
550
- $title.show().html(settings.title);
551
-
552
- if (total > 1) { // handle grouping
553
- if (typeof settings.current === "string") {
554
- $current.html(settings.current.replace(/\{current\}/, index + 1).replace(/\{total\}/, total)).show();
555
- }
556
-
557
- $next[(loop || index < total - 1) ? "show" : "hide"]().html(settings.next);
558
- $prev[(loop || index) ? "show" : "hide"]().html(settings.previous);
559
-
560
- prev = index ? $related[index - 1] : $related[total - 1];
561
- next = index < total - 1 ? $related[index + 1] : $related[0];
562
-
563
- if (settings.slideshow) {
564
- $slideshow.show();
565
- }
566
-
567
- // Preloads images within a rel group
568
- if (settings.preloading) {
569
- nextSrc = $.data(next, colorbox).href || next.href;
570
- prevSrc = $.data(prev, colorbox).href || prev.href;
571
-
572
- nextSrc = $.isFunction(nextSrc) ? nextSrc.call(next) : nextSrc;
573
- prevSrc = $.isFunction(prevSrc) ? prevSrc.call(prev) : prevSrc;
574
-
575
- if (isImage(nextSrc)) {
576
- $('<img/>')[0].src = nextSrc;
577
- }
578
-
579
- if (isImage(prevSrc)) {
580
- $('<img/>')[0].src = prevSrc;
581
- }
582
- }
583
- }
584
-
585
- $loadingOverlay.hide();
586
-
587
- if (settings.transition === 'fade') {
588
- $box.fadeTo(speed, 1, function () {
589
- defilter();
590
- });
591
- } else {
592
- defilter();
593
- }
594
-
595
- $window.bind('resize.' + prefix, function () {
596
- publicMethod.position(0);
597
- });
598
-
599
- trigger(event_complete, settings.onComplete);
600
- });
601
- }
602
-
603
- if (settings.transition === 'fade') {
604
- $box.fadeTo(speed, 0, function () {
605
- setPosition(0);
606
- });
607
- } else {
608
- setPosition(speed);
609
- }
610
- };
611
-
612
- publicMethod.load = function (launched) {
613
- var href, img, setResize, prep = publicMethod.prep;
614
-
615
- active = true;
616
- element = $related[index];
617
-
618
- if (!launched) {
619
- settings = process($.extend({}, $.data(element, colorbox)));
620
- }
621
-
622
- trigger(event_purge);
623
-
624
- trigger(event_load, settings.onLoad);
625
-
626
- settings.h = settings.height ?
627
- setSize(settings.height, 'y') - loadedHeight - interfaceHeight :
628
- settings.innerHeight && setSize(settings.innerHeight, 'y');
629
-
630
- settings.w = settings.width ?
631
- setSize(settings.width, 'x') - loadedWidth - interfaceWidth :
632
- settings.innerWidth && setSize(settings.innerWidth, 'x');
633
-
634
- // Sets the minimum dimensions for use in image scaling
635
- settings.mw = settings.w;
636
- settings.mh = settings.h;
637
-
638
- // Re-evaluate the minimum width and height based on maxWidth and maxHeight values.
639
- // If the width or height exceed the maxWidth or maxHeight, use the maximum values instead.
640
- if (settings.maxWidth) {
641
- settings.mw = setSize(settings.maxWidth, 'x') - loadedWidth - interfaceWidth;
642
- settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw;
643
- }
644
- if (settings.maxHeight) {
645
- settings.mh = setSize(settings.maxHeight, 'y') - loadedHeight - interfaceHeight;
646
- settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh;
647
- }
648
-
649
- href = settings.href;
650
-
651
- $loadingOverlay.show();
652
-
653
- if (settings.inline) {
654
- // Inserts an empty placeholder where inline content is being pulled from.
655
- // An event is bound to put inline content back when ColorBox closes or loads new content.
656
- $div().hide().insertBefore($(href)[0]).one(event_purge, function () {
657
- $(this).replaceWith($loaded.children());
658
- });
659
- prep($(href));
660
- } else if (settings.iframe) {
661
- // IFrame element won't be added to the DOM until it is ready to be displayed,
662
- // to avoid problems with DOM-ready JS that might be trying to run in that iframe.
663
- $box.one(event_loaded, function () {
664
- var iframe = $("<iframe frameborder='0' style='width:100%; height:100%; border:0; display:block'/>")[0];
665
- iframe.name = prefix + (+new Date());
666
- iframe.src = settings.href;
667
-
668
- if (!settings.scrolling) {
669
- iframe.scrolling = "no";
670
- }
671
-
672
- if (isIE) {
673
- iframe.allowtransparency = "true";
674
- }
675
-
676
- $(iframe).appendTo($loaded).one(event_purge, function () {
677
- iframe.src = "//about:blank";
678
- });
679
- });
680
-
681
- prep(" ");
682
- } else if (settings.html) {
683
- prep(settings.html);
684
- } else if (isImage(href)) {
685
- img = new Image();
686
- img.onload = function () {
687
- var percent;
688
- img.onload = null;
689
- img.id = prefix + 'Photo';
690
- $(img).css({border: 'none', display: 'block', cssFloat: 'left'});
691
- if (settings.scalePhotos) {
692
- setResize = function () {
693
- img.height -= img.height * percent;
694
- img.width -= img.width * percent;
695
- };
696
- if (settings.mw && img.width > settings.mw) {
697
- percent = (img.width - settings.mw) / img.width;
698
- setResize();
699
- }
700
- if (settings.mh && img.height > settings.mh) {
701
- percent = (img.height - settings.mh) / img.height;
702
- setResize();
703
- }
704
- }
705
-
706
- if (settings.h) {
707
- img.style.marginTop = Math.max(settings.h - img.height, 0) / 2 + 'px';
708
- }
709
-
710
- if ($related[1] && (index < $related.length - 1 || settings.loop)) {
711
- $(img).css({cursor: 'pointer'}).click(publicMethod.next);
712
- }
713
-
714
- if (isIE) {
715
- img.style.msInterpolationMode = 'bicubic';
716
- }
717
-
718
- setTimeout(function () { // Chrome will sometimes report a 0 by 0 size if there isn't pause in execution
719
- prep(img);
720
- }, 1);
721
- };
722
-
723
- setTimeout(function () { // Opera 10.6+ will sometimes load the src before the onload function is set
724
- img.src = href;
725
- }, 1);
726
- } else if (href) {
727
- $loadingBay.load(href, function (data, status, xhr) {
728
- prep(status === 'error' ? 'Request unsuccessful: ' + xhr.statusText : $(this).children());
729
- });
730
- }
731
- };
732
-
733
- // Navigates to the next page/image in a set.
734
- publicMethod.next = function () {
735
- if (!active) {
736
- index = index < $related.length - 1 ? index + 1 : 0;
737
- publicMethod.load();
738
- }
739
- };
740
-
741
- publicMethod.prev = function () {
742
- if (!active) {
743
- index = index ? index - 1 : $related.length - 1;
744
- publicMethod.load();
745
- }
746
- };
747
-
748
- // Note: to use this within an iframe use the following format: parent.$.fn.colorbox.close();
749
- publicMethod.close = function () {
750
- if (open && !closing) {
751
- closing = true;
752
-
753
- open = false;
754
-
755
- trigger(event_cleanup, settings.onCleanup);
756
-
757
- $window.unbind('.' + prefix + ' .' + event_ie6);
758
-
759
- $overlay.fadeTo('fast', 0);
760
-
761
- $box.stop().fadeTo('fast', 0, function () {
762
-
763
- trigger(event_purge);
764
-
765
- $loaded.remove();
766
-
767
- $box.add($overlay).css({'opacity': 1, cursor: 'auto'}).hide();
768
-
769
- setTimeout(function () {
770
- closing = false;
771
- trigger(event_closed, settings.onClosed);
772
- }, 1);
773
- });
774
- }
775
- };
776
-
777
- // A method for fetching the current element ColorBox is referencing.
778
- // returns a jQuery object.
779
- publicMethod.element = function () {
780
- return $(element);
781
- };
782
-
783
- publicMethod.settings = defaults;
784
-
785
- // Initializes ColorBox when the DOM has loaded
786
- $(publicMethod.init);
787
-
788
- }(jQuery, this));