asset_host_core 2.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.markdown +138 -0
  3. data/Rakefile +11 -0
  4. data/app/assets/images/asset_host_core/alert-overlay.png +0 -0
  5. data/app/assets/images/asset_host_core/arrow-left.gif +0 -0
  6. data/app/assets/images/asset_host_core/arrow-right.gif +0 -0
  7. data/app/assets/images/asset_host_core/fallback-img-rect.png +0 -0
  8. data/app/assets/images/asset_host_core/videoplayer-play.png +0 -0
  9. data/app/assets/images/asset_host_core/x.png +0 -0
  10. data/app/assets/javascripts/asset_host_core/admin/assets.js.coffee +221 -0
  11. data/app/assets/javascripts/asset_host_core/application.js +20 -0
  12. data/app/assets/javascripts/asset_host_core/assetadmin.js.coffee +56 -0
  13. data/app/assets/javascripts/asset_host_core/assethost.js.coffee.erb +17 -0
  14. data/app/assets/javascripts/asset_host_core/browserui.js.coffee +139 -0
  15. data/app/assets/javascripts/asset_host_core/chooserui.js.coffee +381 -0
  16. data/app/assets/javascripts/asset_host_core/client.js.coffee +29 -0
  17. data/app/assets/javascripts/asset_host_core/clients/BrightcoveVideo.js.coffee +64 -0
  18. data/app/assets/javascripts/asset_host_core/clients/templates/brightcove_embed.jst.eco +18 -0
  19. data/app/assets/javascripts/asset_host_core/clients/templates/vimeo_embed.jst.eco +1 -0
  20. data/app/assets/javascripts/asset_host_core/clients/templates/youtube_embed.jst.eco +1 -0
  21. data/app/assets/javascripts/asset_host_core/clients/vimeo_video.js.coffee +21 -0
  22. data/app/assets/javascripts/asset_host_core/clients/youtube_video.js.coffee +21 -0
  23. data/app/assets/javascripts/asset_host_core/cmsplugin.js.coffee +235 -0
  24. data/app/assets/javascripts/asset_host_core/models.js.coffee +586 -0
  25. data/app/assets/javascripts/asset_host_core/railsCMS.js.coffee +141 -0
  26. data/app/assets/javascripts/asset_host_core/slideshow.js.coffee +428 -0
  27. data/app/assets/javascripts/asset_host_core/templates/after_upload_button.jst.eco +3 -0
  28. data/app/assets/javascripts/asset_host_core/templates/asset_drop_asset.jst.eco +4 -0
  29. data/app/assets/javascripts/asset_host_core/templates/asset_modal.jst.eco +13 -0
  30. data/app/assets/javascripts/asset_host_core/templates/asset_preview.jst.eco +35 -0
  31. data/app/assets/javascripts/asset_host_core/templates/asset_search.jst.eco +2 -0
  32. data/app/assets/javascripts/asset_host_core/templates/browser_asset.jst.eco +1 -0
  33. data/app/assets/javascripts/asset_host_core/templates/browser_asset_tip.jst.eco +3 -0
  34. data/app/assets/javascripts/asset_host_core/templates/edit_modal.jst.eco +40 -0
  35. data/app/assets/javascripts/asset_host_core/templates/import_help.jst.eco +59 -0
  36. data/app/assets/javascripts/asset_host_core/templates/pagination_link.jst.eco +1 -0
  37. data/app/assets/javascripts/asset_host_core/templates/pagination_links.jst.eco +13 -0
  38. data/app/assets/javascripts/asset_host_core/templates/queued_file.jst.eco +11 -0
  39. data/app/assets/javascripts/asset_host_core/templates/save_and_close_view.jst.eco +4 -0
  40. data/app/assets/javascripts/asset_host_core/templates/upload_all_button.jst.eco +4 -0
  41. data/app/assets/javascripts/asset_host_core/templates/url_input.jst.eco +8 -0
  42. data/app/assets/stylesheets/asset_host_core/application.css.scss +384 -0
  43. data/app/assets/stylesheets/asset_host_core/jquery-ui.css +105 -0
  44. data/app/assets/stylesheets/asset_host_core/public.css.scss +204 -0
  45. data/app/assets/stylesheets/asset_host_core/slidetest.css.scss +93 -0
  46. data/app/controllers/asset_host_core/admin/api_users_controller.rb +72 -0
  47. data/app/controllers/asset_host_core/admin/assets_controller.rb +140 -0
  48. data/app/controllers/asset_host_core/admin/base_controller.rb +36 -0
  49. data/app/controllers/asset_host_core/admin/home_controller.rb +13 -0
  50. data/app/controllers/asset_host_core/admin/outputs_controller.rb +55 -0
  51. data/app/controllers/asset_host_core/api/assets_controller.rb +110 -0
  52. data/app/controllers/asset_host_core/api/base_controller.rb +43 -0
  53. data/app/controllers/asset_host_core/api/outputs_controller.rb +33 -0
  54. data/app/controllers/asset_host_core/application_controller.rb +43 -0
  55. data/app/controllers/asset_host_core/public_controller.rb +104 -0
  56. data/app/models/asset_host_core/api_user.rb +44 -0
  57. data/app/models/asset_host_core/api_user_permission.rb +6 -0
  58. data/app/models/asset_host_core/asset.rb +265 -0
  59. data/app/models/asset_host_core/asset_output.rb +69 -0
  60. data/app/models/asset_host_core/brightcove_video.rb +20 -0
  61. data/app/models/asset_host_core/output.rb +52 -0
  62. data/app/models/asset_host_core/permission.rb +19 -0
  63. data/app/models/asset_host_core/video.rb +8 -0
  64. data/app/models/asset_host_core/vimeo_video.rb +17 -0
  65. data/app/models/asset_host_core/youtube_video.rb +17 -0
  66. data/app/views/asset_host_core/admin/api_users/_form_fields.html.erb +5 -0
  67. data/app/views/asset_host_core/admin/api_users/edit.html.erb +26 -0
  68. data/app/views/asset_host_core/admin/api_users/index.html.erb +31 -0
  69. data/app/views/asset_host_core/admin/api_users/new.html.erb +17 -0
  70. data/app/views/asset_host_core/admin/api_users/show.html.erb +23 -0
  71. data/app/views/asset_host_core/admin/assets/index.html.erb +19 -0
  72. data/app/views/asset_host_core/admin/assets/metadata.html.erb +24 -0
  73. data/app/views/asset_host_core/admin/assets/show.html.erb +86 -0
  74. data/app/views/asset_host_core/admin/home/chooser.html.erb +49 -0
  75. data/app/views/asset_host_core/admin/outputs/_form_fields.html.erb +5 -0
  76. data/app/views/asset_host_core/admin/outputs/edit.html.erb +26 -0
  77. data/app/views/asset_host_core/admin/outputs/index.html.erb +27 -0
  78. data/app/views/asset_host_core/admin/outputs/new.html.erb +13 -0
  79. data/app/views/asset_host_core/admin/outputs/show.html.erb +17 -0
  80. data/app/views/asset_host_core/shared/_footerjs.html.erb +3 -0
  81. data/app/views/asset_host_core/shared/_navbar.html.erb +28 -0
  82. data/app/views/kaminari/_first_page.html.erb +3 -0
  83. data/app/views/kaminari/_gap.html.erb +3 -0
  84. data/app/views/kaminari/_last_page.html.erb +3 -0
  85. data/app/views/kaminari/_next_page.html.erb +3 -0
  86. data/app/views/kaminari/_page.html.erb +3 -0
  87. data/app/views/kaminari/_paginator.html.erb +17 -0
  88. data/app/views/kaminari/_prev_page.html.erb +3 -0
  89. data/app/views/layouts/asset_host_core/application.html.erb +54 -0
  90. data/app/views/layouts/asset_host_core/full_width.html.erb +32 -0
  91. data/app/views/layouts/asset_host_core/minimal.html.erb +45 -0
  92. data/config/initializers/simple_form.rb +142 -0
  93. data/config/initializers/simple_form_bootstrap.rb +45 -0
  94. data/config/locales/simple_form.en.yml +26 -0
  95. data/config/routes.rb +49 -0
  96. data/lib/asset_host_core.rb +38 -0
  97. data/lib/asset_host_core/config.rb +39 -0
  98. data/lib/asset_host_core/engine.rb +94 -0
  99. data/lib/asset_host_core/loaders.rb +34 -0
  100. data/lib/asset_host_core/loaders/asset_host.rb +30 -0
  101. data/lib/asset_host_core/loaders/base.rb +22 -0
  102. data/lib/asset_host_core/loaders/brightcove.rb +67 -0
  103. data/lib/asset_host_core/loaders/flickr.rb +114 -0
  104. data/lib/asset_host_core/loaders/url.rb +59 -0
  105. data/lib/asset_host_core/loaders/vimeo.rb +76 -0
  106. data/lib/asset_host_core/loaders/youtube.rb +90 -0
  107. data/lib/asset_host_core/model_methods.rb +61 -0
  108. data/lib/asset_host_core/paperclip.rb +4 -0
  109. data/lib/asset_host_core/paperclip/asset_thumbnail.rb +92 -0
  110. data/lib/asset_host_core/paperclip/attachment.rb +206 -0
  111. data/lib/asset_host_core/paperclip/trimmer.rb +33 -0
  112. data/lib/asset_host_core/resque_job.rb +13 -0
  113. data/lib/asset_host_core/version.rb +3 -0
  114. data/lib/tasks/asset_host_core_tasks.rake +4 -0
  115. data/spec/controllers/admin/api_users_controller_spec.rb +21 -0
  116. data/spec/controllers/admin/assets_controller_spec.rb +59 -0
  117. data/spec/controllers/admin/home_controller_spec.rb +4 -0
  118. data/spec/controllers/admin/outputs_controller_spec.rb +4 -0
  119. data/spec/controllers/api/assets_controller_spec.rb +133 -0
  120. data/spec/controllers/api/outputs_controller_spec.rb +51 -0
  121. data/spec/controllers/public_controller_spec.rb +4 -0
  122. data/spec/factories.rb +39 -0
  123. data/spec/features/api_users_spec.rb +78 -0
  124. data/spec/fixtures/api/brightcove/video.json +137 -0
  125. data/spec/fixtures/api/flickr/photos_getInfo.json +78 -0
  126. data/spec/fixtures/api/flickr/photos_getSizes.json +82 -0
  127. data/spec/fixtures/api/flickr/photos_licenses_getInfo.json +52 -0
  128. data/spec/fixtures/api/vimeo/video.json +28 -0
  129. data/spec/fixtures/api/youtube/discovery.json +5190 -0
  130. data/spec/fixtures/api/youtube/video.json +44 -0
  131. data/spec/fixtures/images/chipmunk.jpg +0 -0
  132. data/spec/fixtures/images/dude.jpg +0 -0
  133. data/spec/fixtures/images/ernie.jpg +0 -0
  134. data/spec/fixtures/images/fry.png +0 -0
  135. data/spec/fixtures/images/hat.jpg +0 -0
  136. data/spec/fixtures/images/spongebob.png +0 -0
  137. data/spec/fixtures/images/stars.jpg +0 -0
  138. data/spec/internal/app/controllers/application_controller.rb +16 -0
  139. data/spec/internal/app/controllers/sessions_controller.rb +24 -0
  140. data/spec/internal/app/models/user.rb +10 -0
  141. data/spec/internal/app/views/sessions/new.html.erb +14 -0
  142. data/spec/internal/config/database.yml +3 -0
  143. data/spec/internal/config/initializers/assethost_config.rb +57 -0
  144. data/spec/internal/config/routes.rb +7 -0
  145. data/spec/internal/db/combustion_test.sqlite +0 -0
  146. data/spec/internal/db/schema.rb +106 -0
  147. data/spec/internal/log/test.log +14769 -0
  148. data/spec/internal/public/favicon.ico +0 -0
  149. data/spec/internal/public/images/1_27f7745237849975ca90591c1fba5934_original. +0 -0
  150. data/spec/internal/public/images/1_7d33319deca787d5bb3f62ff06563ad2_original. +0 -0
  151. data/spec/internal/public/images/1_b6d48c8b1286104ce76649731e09645f_original. +0 -0
  152. data/spec/internal/public/images/1_b6d48c8b1286104ce76649731e09645f_original.jpg +0 -0
  153. data/spec/internal/public/images/1_b6d48c8b1286104ce76649731e09645f_original.txt +0 -0
  154. data/spec/internal/public/images/1_e179cbd27e07cb55042d0db36cdac095_original. +0 -0
  155. data/spec/internal/public/images/1_e669edd3dfd74be66fc38416e82e3a37_original. +0 -0
  156. data/spec/lib/asset_host_core/loaders/asset_host_spec.rb +33 -0
  157. data/spec/lib/asset_host_core/loaders/brightcove_spec.rb +51 -0
  158. data/spec/lib/asset_host_core/loaders/flickr_spec.rb +72 -0
  159. data/spec/lib/asset_host_core/loaders/url_spec.rb +42 -0
  160. data/spec/lib/asset_host_core/loaders/vimeo_spec.rb +51 -0
  161. data/spec/lib/asset_host_core/loaders/youtube_spec.rb +73 -0
  162. data/spec/lib/asset_host_core/loaders_spec.rb +4 -0
  163. data/spec/lib/asset_host_core/model_methods_spec.rb +4 -0
  164. data/spec/lib/asset_host_core/paperclip/asset_thumbnail_spec.rb +4 -0
  165. data/spec/lib/asset_host_core/paperclip/attachment_spec.rb +4 -0
  166. data/spec/lib/asset_host_core/resque_job_spec.rb +4 -0
  167. data/spec/lib/asset_host_core_spec.rb +4 -0
  168. data/spec/models/api_user_spec.rb +58 -0
  169. data/spec/models/asset_output_spec.rb +4 -0
  170. data/spec/models/asset_spec.rb +4 -0
  171. data/spec/models/output_spec.rb +4 -0
  172. data/spec/models/permission_spec.rb +4 -0
  173. data/spec/spec_helper.rb +30 -0
  174. data/spec/support/fixture_loader.rb +9 -0
  175. data/spec/support/param_helper.rb +14 -0
  176. data/spec/support/permission_matcher.rb +17 -0
  177. data/vendor/assets/images/jquery-ui/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  178. data/vendor/assets/images/jquery-ui/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  179. data/vendor/assets/images/jquery-ui/ui-bg_flat_10_000000_40x100.png +0 -0
  180. data/vendor/assets/images/jquery-ui/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  181. data/vendor/assets/images/jquery-ui/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  182. data/vendor/assets/images/jquery-ui/ui-bg_glass_65_ffffff_1x400.png +0 -0
  183. data/vendor/assets/images/jquery-ui/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  184. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  185. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  186. data/vendor/assets/images/jquery-ui/ui-icons_222222_256x240.png +0 -0
  187. data/vendor/assets/images/jquery-ui/ui-icons_228ef1_256x240.png +0 -0
  188. data/vendor/assets/images/jquery-ui/ui-icons_ef8c08_256x240.png +0 -0
  189. data/vendor/assets/images/jquery-ui/ui-icons_ffd27a_256x240.png +0 -0
  190. data/vendor/assets/images/jquery-ui/ui-icons_ffffff_256x240.png +0 -0
  191. data/vendor/assets/javascripts/backbone.js +1158 -0
  192. data/vendor/assets/javascripts/backbone.modelbinding.js +475 -0
  193. data/vendor/assets/javascripts/exif.js +695 -0
  194. data/vendor/assets/javascripts/jquery-ui.js +5614 -0
  195. data/vendor/assets/javascripts/simplemodal.js +698 -0
  196. data/vendor/assets/javascripts/spin.jquery.js +81 -0
  197. data/vendor/assets/javascripts/spin.min.js +1 -0
  198. data/vendor/assets/javascripts/underscore.min.js +1 -0
  199. metadata +658 -0
@@ -0,0 +1,698 @@
1
+ /*
2
+ * SimpleModal 1.4.1 - jQuery Plugin
3
+ * http://www.ericmmartin.com/projects/simplemodal/
4
+ * Copyright (c) 2010 Eric Martin (http://twitter.com/ericmmartin)
5
+ * Dual licensed under the MIT and GPL licenses
6
+ * Revision: $Id: jquery.simplemodal.js 261 2010-11-05 21:16:20Z emartin24 $
7
+ */
8
+
9
+ /**
10
+ * SimpleModal is a lightweight jQuery plugin that provides a simple
11
+ * interface to create a modal dialog.
12
+ *
13
+ * The goal of SimpleModal is to provide developers with a cross-browser
14
+ * overlay and container that will be populated with data provided to
15
+ * SimpleModal.
16
+ *
17
+ * There are two ways to call SimpleModal:
18
+ * 1) As a chained function on a jQuery object, like $('#myDiv').modal();.
19
+ * This call would place the DOM object, #myDiv, inside a modal dialog.
20
+ * Chaining requires a jQuery object. An optional options object can be
21
+ * passed as a parameter.
22
+ *
23
+ * @example $('<div>my data</div>').modal({options});
24
+ * @example $('#myDiv').modal({options});
25
+ * @example jQueryObject.modal({options});
26
+ *
27
+ * 2) As a stand-alone function, like $.modal(data). The data parameter
28
+ * is required and an optional options object can be passed as a second
29
+ * parameter. This method provides more flexibility in the types of data
30
+ * that are allowed. The data could be a DOM object, a jQuery object, HTML
31
+ * or a string.
32
+ *
33
+ * @example $.modal('<div>my data</div>', {options});
34
+ * @example $.modal('my data', {options});
35
+ * @example $.modal($('#myDiv'), {options});
36
+ * @example $.modal(jQueryObject, {options});
37
+ * @example $.modal(document.getElementById('myDiv'), {options});
38
+ *
39
+ * A SimpleModal call can contain multiple elements, but only one modal
40
+ * dialog can be created at a time. Which means that all of the matched
41
+ * elements will be displayed within the modal container.
42
+ *
43
+ * SimpleModal internally sets the CSS needed to display the modal dialog
44
+ * properly in all browsers, yet provides the developer with the flexibility
45
+ * to easily control the look and feel. The styling for SimpleModal can be
46
+ * done through external stylesheets, or through SimpleModal, using the
47
+ * overlayCss, containerCss, and dataCss options.
48
+ *
49
+ * SimpleModal has been tested in the following browsers:
50
+ * - IE 6, 7, 8, 9
51
+ * - Firefox 2, 3, 4
52
+ * - Opera 9, 10
53
+ * - Safari 3, 4, 5
54
+ * - Chrome 1, 2, 3, 4, 5, 6
55
+ *
56
+ * @name SimpleModal
57
+ * @type jQuery
58
+ * @requires jQuery v1.2.4
59
+ * @cat Plugins/Windows and Overlays
60
+ * @author Eric Martin (http://ericmmartin.com)
61
+ * @version 1.4.1
62
+ */
63
+ ;(function ($) {
64
+ var ie6 = $.browser.msie && parseInt($.browser.version) === 6 && typeof window['XMLHttpRequest'] !== 'object',
65
+ ie7 = $.browser.msie && parseInt($.browser.version) === 7,
66
+ ieQuirks = null,
67
+ w = [];
68
+
69
+ /*
70
+ * Create and display a modal dialog.
71
+ *
72
+ * @param {string, object} data A string, jQuery object or DOM object
73
+ * @param {object} [options] An optional object containing options overrides
74
+ */
75
+ $.modal = function (data, options) {
76
+ return $.modal.impl.init(data, options);
77
+ };
78
+
79
+ /*
80
+ * Close the modal dialog.
81
+ */
82
+ $.modal.close = function () {
83
+ $.modal.impl.close();
84
+ };
85
+
86
+ /*
87
+ * Set focus on first or last visible input in the modal dialog. To focus on the last
88
+ * element, call $.modal.focus('last'). If no input elements are found, focus is placed
89
+ * on the data wrapper element.
90
+ */
91
+ $.modal.focus = function (pos) {
92
+ $.modal.impl.focus(pos);
93
+ };
94
+
95
+ /*
96
+ * Determine and set the dimensions of the modal dialog container.
97
+ * setPosition() is called if the autoPosition option is true.
98
+ */
99
+ $.modal.setContainerDimensions = function () {
100
+ $.modal.impl.setContainerDimensions();
101
+ };
102
+
103
+ /*
104
+ * Re-position the modal dialog.
105
+ */
106
+ $.modal.setPosition = function () {
107
+ $.modal.impl.setPosition();
108
+ };
109
+
110
+ /*
111
+ * Update the modal dialog. If new dimensions are passed, they will be used to determine
112
+ * the dimensions of the container.
113
+ *
114
+ * setContainerDimensions() is called, which in turn calls setPosition(), if enabled.
115
+ * Lastly, focus() is called is the focus option is true.
116
+ */
117
+ $.modal.update = function (height, width) {
118
+ $.modal.impl.update(height, width);
119
+ };
120
+
121
+ /*
122
+ * Chained function to create a modal dialog.
123
+ *
124
+ * @param {object} [options] An optional object containing options overrides
125
+ */
126
+ $.fn.modal = function (options) {
127
+ return $.modal.impl.init(this, options);
128
+ };
129
+
130
+ /*
131
+ * SimpleModal default options
132
+ *
133
+ * appendTo: (String:'body') The jQuery selector to append the elements to. For .NET, use 'form'.
134
+ * focus: (Boolean:true) Focus in the first visible, enabled element?
135
+ * opacity: (Number:50) The opacity value for the overlay div, from 0 - 100
136
+ * overlayId: (String:'simplemodal-overlay') The DOM element id for the overlay div
137
+ * overlayCss: (Object:{}) The CSS styling for the overlay div
138
+ * containerId: (String:'simplemodal-container') The DOM element id for the container div
139
+ * containerCss: (Object:{}) The CSS styling for the container div
140
+ * dataId: (String:'simplemodal-data') The DOM element id for the data div
141
+ * dataCss: (Object:{}) The CSS styling for the data div
142
+ * minHeight: (Number:null) The minimum height for the container
143
+ * minWidth: (Number:null) The minimum width for the container
144
+ * maxHeight: (Number:null) The maximum height for the container. If not specified, the window height is used.
145
+ * maxWidth: (Number:null) The maximum width for the container. If not specified, the window width is used.
146
+ * autoResize: (Boolean:false) Automatically resize the container if it exceeds the browser window dimensions?
147
+ * autoPosition: (Boolean:true) Automatically position the container upon creation and on window resize?
148
+ * zIndex: (Number: 1000) Starting z-index value
149
+ * close: (Boolean:true) If true, closeHTML, escClose and overClose will be used if set.
150
+ If false, none of them will be used.
151
+ * closeHTML: (String:'<a class="modalCloseImg" title="Close"></a>') The HTML for the default close link.
152
+ SimpleModal will automatically add the closeClass to this element.
153
+ * closeClass: (String:'simplemodal-close') The CSS class used to bind to the close event
154
+ * escClose: (Boolean:true) Allow Esc keypress to close the dialog?
155
+ * overlayClose: (Boolean:false) Allow click on overlay to close the dialog?
156
+ * position: (Array:null) Position of container [top, left]. Can be number of pixels or percentage
157
+ * persist: (Boolean:false) Persist the data across modal calls? Only used for existing
158
+ DOM elements. If true, the data will be maintained across modal calls, if false,
159
+ the data will be reverted to its original state.
160
+ * modal: (Boolean:true) User will be unable to interact with the page below the modal or tab away from the dialog.
161
+ If false, the overlay, iframe, and certain events will be disabled allowing the user to interact
162
+ with the page below the dialog.
163
+ * onOpen: (Function:null) The callback function used in place of SimpleModal's open
164
+ * onShow: (Function:null) The callback function used after the modal dialog has opened
165
+ * onClose: (Function:null) The callback function used in place of SimpleModal's close
166
+ */
167
+ $.modal.defaults = {
168
+ appendTo: 'body',
169
+ focus: true,
170
+ opacity: 50,
171
+ overlayId: 'simplemodal-overlay',
172
+ overlayCss: {},
173
+ containerId: 'simplemodal-container',
174
+ containerCss: {},
175
+ dataId: 'simplemodal-data',
176
+ dataCss: {},
177
+ minHeight: null,
178
+ minWidth: null,
179
+ maxHeight: null,
180
+ maxWidth: null,
181
+ autoResize: false,
182
+ autoPosition: true,
183
+ zIndex: 1000,
184
+ close: true,
185
+ closeHTML: '<a class="modalCloseImg" title="Close"></a>',
186
+ closeClass: 'simplemodal-close',
187
+ escClose: true,
188
+ overlayClose: false,
189
+ position: null,
190
+ persist: false,
191
+ modal: true,
192
+ onOpen: null,
193
+ onShow: null,
194
+ onClose: null
195
+ };
196
+
197
+ /*
198
+ * Main modal object
199
+ * o = options
200
+ */
201
+ $.modal.impl = {
202
+ /*
203
+ * Contains the modal dialog elements and is the object passed
204
+ * back to the callback (onOpen, onShow, onClose) functions
205
+ */
206
+ d: {},
207
+ /*
208
+ * Initialize the modal dialog
209
+ */
210
+ init: function (data, options) {
211
+ var s = this;
212
+
213
+ // don't allow multiple calls
214
+ if (s.d.data) {
215
+ return false;
216
+ }
217
+
218
+ // $.boxModel is undefined if checked earlier
219
+ ieQuirks = $.browser.msie && !$.boxModel;
220
+
221
+ // merge defaults and user options
222
+ s.o = $.extend({}, $.modal.defaults, options);
223
+
224
+ // keep track of z-index
225
+ s.zIndex = s.o.zIndex;
226
+
227
+ // set the onClose callback flag
228
+ s.occb = false;
229
+
230
+ // determine how to handle the data based on its type
231
+ if (typeof data === 'object') {
232
+ // convert DOM object to a jQuery object
233
+ data = data instanceof jQuery ? data : $(data);
234
+ s.d.placeholder = false;
235
+
236
+ // if the object came from the DOM, keep track of its parent
237
+ if (data.parent().parent().size() > 0) {
238
+ data.before($('<span></span>')
239
+ .attr('id', 'simplemodal-placeholder')
240
+ .css({display: 'none'}));
241
+
242
+ s.d.placeholder = true;
243
+ s.display = data.css('display');
244
+
245
+ // persist changes? if not, make a clone of the element
246
+ if (!s.o.persist) {
247
+ s.d.orig = data.clone(true);
248
+ }
249
+ }
250
+ }
251
+ else if (typeof data === 'string' || typeof data === 'number') {
252
+ // just insert the data as innerHTML
253
+ data = $('<div></div>').html(data);
254
+ }
255
+ else {
256
+ // unsupported data type!
257
+ alert('SimpleModal Error: Unsupported data type: ' + typeof data);
258
+ return s;
259
+ }
260
+
261
+ // create the modal overlay, container and, if necessary, iframe
262
+ s.create(data);
263
+ data = null;
264
+
265
+ // display the modal dialog
266
+ s.open();
267
+
268
+ // useful for adding events/manipulating data in the modal dialog
269
+ if ($.isFunction(s.o.onShow)) {
270
+ s.o.onShow.apply(s, [s.d]);
271
+ }
272
+
273
+ // don't break the chain =)
274
+ return s;
275
+ },
276
+ /*
277
+ * Create and add the modal overlay and container to the page
278
+ */
279
+ create: function (data) {
280
+ var s = this;
281
+
282
+ // get the window properties
283
+ w = s.getDimensions();
284
+
285
+ // add an iframe to prevent select options from bleeding through
286
+ if (s.o.modal && ie6) {
287
+ s.d.iframe = $('<iframe src="javascript:false;"></iframe>')
288
+ .css($.extend(s.o.iframeCss, {
289
+ display: 'none',
290
+ opacity: 0,
291
+ position: 'fixed',
292
+ height: w[0],
293
+ width: w[1],
294
+ zIndex: s.o.zIndex,
295
+ top: 0,
296
+ left: 0
297
+ }))
298
+ .appendTo(s.o.appendTo);
299
+ }
300
+
301
+ // create the overlay
302
+ s.d.overlay = $('<div></div>')
303
+ .attr('id', s.o.overlayId)
304
+ .addClass('simplemodal-overlay')
305
+ .css($.extend(s.o.overlayCss, {
306
+ display: 'none',
307
+ opacity: s.o.opacity / 100,
308
+ height: s.o.modal ? w[0] : 0,
309
+ width: s.o.modal ? w[1] : 0,
310
+ position: 'fixed',
311
+ left: 0,
312
+ top: 0,
313
+ zIndex: s.o.zIndex + 1
314
+ }))
315
+ .appendTo(s.o.appendTo);
316
+
317
+ // create the container
318
+ s.d.container = $('<div></div>')
319
+ .attr('id', s.o.containerId)
320
+ .addClass('simplemodal-container')
321
+ .css($.extend(s.o.containerCss, {
322
+ display: 'none',
323
+ position: 'fixed',
324
+ zIndex: s.o.zIndex + 2
325
+ }))
326
+ .append(s.o.close && s.o.closeHTML
327
+ ? $(s.o.closeHTML).addClass(s.o.closeClass)
328
+ : '')
329
+ .appendTo(s.o.appendTo);
330
+
331
+ s.d.wrap = $('<div></div>')
332
+ .attr('tabIndex', -1)
333
+ .addClass('simplemodal-wrap')
334
+ .css({height: '100%', outline: 0, width: '100%'})
335
+ .appendTo(s.d.container);
336
+
337
+ // add styling and attributes to the data
338
+ // append to body to get correct dimensions, then move to wrap
339
+ s.d.data = data
340
+ .attr('id', data.attr('id') || s.o.dataId)
341
+ .addClass('simplemodal-data')
342
+ .css($.extend(s.o.dataCss, {
343
+ display: 'none'
344
+ }))
345
+ .appendTo('body');
346
+ data = null;
347
+
348
+ s.setContainerDimensions();
349
+ s.d.data.appendTo(s.d.wrap);
350
+
351
+ // fix issues with IE
352
+ if (ie6 || ieQuirks) {
353
+ s.fixIE();
354
+ }
355
+ },
356
+ /*
357
+ * Bind events
358
+ */
359
+ bindEvents: function () {
360
+ var s = this;
361
+
362
+ // bind the close event to any element with the closeClass class
363
+ $('.' + s.o.closeClass).bind('click.simplemodal', function (e) {
364
+ e.preventDefault();
365
+ s.close();
366
+ });
367
+
368
+ // bind the overlay click to the close function, if enabled
369
+ if (s.o.modal && s.o.close && s.o.overlayClose) {
370
+ s.d.overlay.bind('click.simplemodal', function (e) {
371
+ e.preventDefault();
372
+ s.close();
373
+ });
374
+ }
375
+
376
+ // bind keydown events
377
+ $(document).bind('keydown.simplemodal', function (e) {
378
+ if (s.o.modal && e.keyCode === 9) { // TAB
379
+ s.watchTab(e);
380
+ }
381
+ else if ((s.o.close && s.o.escClose) && e.keyCode === 27) { // ESC
382
+ e.preventDefault();
383
+ s.close();
384
+ }
385
+ });
386
+
387
+ // update window size
388
+ $(window).bind('resize.simplemodal', function () {
389
+ // redetermine the window width/height
390
+ w = s.getDimensions();
391
+
392
+ // reposition the dialog
393
+ s.o.autoResize ? s.setContainerDimensions() : s.o.autoPosition && s.setPosition();
394
+
395
+ if (ie6 || ieQuirks) {
396
+ s.fixIE();
397
+ }
398
+ else if (s.o.modal) {
399
+ // update the iframe & overlay
400
+ s.d.iframe && s.d.iframe.css({height: w[0], width: w[1]});
401
+ s.d.overlay.css({height: w[0], width: w[1]});
402
+ }
403
+ });
404
+ },
405
+ /*
406
+ * Unbind events
407
+ */
408
+ unbindEvents: function () {
409
+ $('.' + this.o.closeClass).unbind('click.simplemodal');
410
+ $(document).unbind('keydown.simplemodal');
411
+ $(window).unbind('resize.simplemodal');
412
+ this.d.overlay.unbind('click.simplemodal');
413
+ },
414
+ /*
415
+ * Fix issues in IE6 and IE7 in quirks mode
416
+ */
417
+ fixIE: function () {
418
+ var s = this, p = s.o.position;
419
+
420
+ // simulate fixed position - adapted from BlockUI
421
+ $.each([s.d.iframe || null, !s.o.modal ? null : s.d.overlay, s.d.container], function (i, el) {
422
+ if (el) {
423
+ var bch = 'document.body.clientHeight', bcw = 'document.body.clientWidth',
424
+ bsh = 'document.body.scrollHeight', bsl = 'document.body.scrollLeft',
425
+ bst = 'document.body.scrollTop', bsw = 'document.body.scrollWidth',
426
+ ch = 'document.documentElement.clientHeight', cw = 'document.documentElement.clientWidth',
427
+ sl = 'document.documentElement.scrollLeft', st = 'document.documentElement.scrollTop',
428
+ s = el[0].style;
429
+
430
+ s.position = 'absolute';
431
+ if (i < 2) {
432
+ s.removeExpression('height');
433
+ s.removeExpression('width');
434
+ s.setExpression('height','' + bsh + ' > ' + bch + ' ? ' + bsh + ' : ' + bch + ' + "px"');
435
+ s.setExpression('width','' + bsw + ' > ' + bcw + ' ? ' + bsw + ' : ' + bcw + ' + "px"');
436
+ }
437
+ else {
438
+ var te, le;
439
+ if (p && p.constructor === Array) {
440
+ var top = p[0]
441
+ ? typeof p[0] === 'number' ? p[0].toString() : p[0].replace(/px/, '')
442
+ : el.css('top').replace(/px/, '');
443
+ te = top.indexOf('%') === -1
444
+ ? top + ' + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"'
445
+ : parseInt(top.replace(/%/, '')) + ' * ((' + ch + ' || ' + bch + ') / 100) + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"';
446
+
447
+ if (p[1]) {
448
+ var left = typeof p[1] === 'number' ? p[1].toString() : p[1].replace(/px/, '');
449
+ le = left.indexOf('%') === -1
450
+ ? left + ' + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"'
451
+ : parseInt(left.replace(/%/, '')) + ' * ((' + cw + ' || ' + bcw + ') / 100) + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"';
452
+ }
453
+ }
454
+ else {
455
+ te = '(' + ch + ' || ' + bch + ') / 2 - (this.offsetHeight / 2) + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"';
456
+ le = '(' + cw + ' || ' + bcw + ') / 2 - (this.offsetWidth / 2) + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"';
457
+ }
458
+ s.removeExpression('top');
459
+ s.removeExpression('left');
460
+ s.setExpression('top', te);
461
+ s.setExpression('left', le);
462
+ }
463
+ }
464
+ });
465
+ },
466
+ /*
467
+ * Place focus on the first or last visible input
468
+ */
469
+ focus: function (pos) {
470
+ var s = this, p = pos && $.inArray(pos, ['first', 'last']) !== -1 ? pos : 'first';
471
+
472
+ // focus on dialog or the first visible/enabled input element
473
+ var input = $(':input:enabled:visible:' + p, s.d.wrap);
474
+ setTimeout(function () {
475
+ input.length > 0 ? input.focus() : s.d.wrap.focus();
476
+ }, 10);
477
+ },
478
+ getDimensions: function () {
479
+ var el = $(window);
480
+
481
+ // fix a jQuery/Opera bug with determining the window height
482
+ var h = $.browser.opera && $.browser.version > '9.5' && $.fn.jquery < '1.3'
483
+ || $.browser.opera && $.browser.version < '9.5' && $.fn.jquery > '1.2.6'
484
+ ? el[0].innerHeight : el.height();
485
+
486
+ return [h, el.width()];
487
+ },
488
+ getVal: function (v, d) {
489
+ return v ? (typeof v === 'number' ? v
490
+ : v === 'auto' ? 0
491
+ : v.indexOf('%') > 0 ? ((parseInt(v.replace(/%/, '')) / 100) * (d === 'h' ? w[0] : w[1]))
492
+ : parseInt(v.replace(/px/, '')))
493
+ : null;
494
+ },
495
+ /*
496
+ * Update the container. Set new dimensions, if provided.
497
+ * Focus, if enabled. Re-bind events.
498
+ */
499
+ update: function (height, width) {
500
+ var s = this;
501
+
502
+ // prevent update if dialog does not exist
503
+ if (!s.d.data) {
504
+ return false;
505
+ }
506
+
507
+ // reset orig values
508
+ s.d.origHeight = s.getVal(height, 'h');
509
+ s.d.origWidth = s.getVal(width, 'w');
510
+
511
+ // hide data to prevent screen flicker
512
+ s.d.data.hide();
513
+ height && s.d.container.css('height', height);
514
+ width && s.d.container.css('width', width);
515
+ s.setContainerDimensions();
516
+ s.d.data.show();
517
+ s.o.focus && s.focus();
518
+
519
+ // rebind events
520
+ s.unbindEvents();
521
+ s.bindEvents();
522
+ },
523
+ setContainerDimensions: function () {
524
+ var s = this,
525
+ badIE = ie6 || ie7;
526
+
527
+ // get the dimensions for the container and data
528
+ var ch = s.d.origHeight ? s.d.origHeight : $.browser.opera ? s.d.container.height() : s.getVal(badIE ? s.d.container[0].currentStyle['height'] : s.d.container.css('height'), 'h'),
529
+ cw = s.d.origWidth ? s.d.origWidth : $.browser.opera ? s.d.container.width() : s.getVal(badIE ? s.d.container[0].currentStyle['width'] : s.d.container.css('width'), 'w'),
530
+ dh = s.d.data.outerHeight(true), dw = s.d.data.outerWidth(true);
531
+
532
+ s.d.origHeight = s.d.origHeight || ch;
533
+ s.d.origWidth = s.d.origWidth || cw;
534
+
535
+ // mxoh = max option height, mxow = max option width
536
+ var mxoh = s.o.maxHeight ? s.getVal(s.o.maxHeight, 'h') : null,
537
+ mxow = s.o.maxWidth ? s.getVal(s.o.maxWidth, 'w') : null,
538
+ mh = mxoh && mxoh < w[0] ? mxoh : w[0],
539
+ mw = mxow && mxow < w[1] ? mxow : w[1];
540
+
541
+ // moh = min option height
542
+ var moh = s.o.minHeight ? s.getVal(s.o.minHeight, 'h') : 'auto';
543
+ if (!ch) {
544
+ if (!dh) {ch = moh;}
545
+ else {
546
+ if (dh > mh) {ch = mh;}
547
+ else if (s.o.minHeight && moh !== 'auto' && dh < moh) {ch = moh;}
548
+ else {ch = dh;}
549
+ }
550
+ }
551
+ else {
552
+ ch = s.o.autoResize && ch > mh ? mh : ch < moh ? moh : ch;
553
+ }
554
+
555
+ // mow = min option width
556
+ var mow = s.o.minWidth ? s.getVal(s.o.minWidth, 'w') : 'auto';
557
+ if (!cw) {
558
+ if (!dw) {cw = mow;}
559
+ else {
560
+ if (dw > mw) {cw = mw;}
561
+ else if (s.o.minWidth && mow !== 'auto' && dw < mow) {cw = mow;}
562
+ else {cw = dw;}
563
+ }
564
+ }
565
+ else {
566
+ cw = s.o.autoResize && cw > mw ? mw : cw < mow ? mow : cw;
567
+ }
568
+
569
+ s.d.container.css({height: ch, width: cw});
570
+ s.d.wrap.css({overflow: (dh > ch || dw > cw) ? 'auto' : 'visible'});
571
+ s.o.autoPosition && s.setPosition();
572
+ },
573
+ setPosition: function () {
574
+ var s = this, top, left,
575
+ hc = (w[0]/2) - (s.d.container.outerHeight(true)/2),
576
+ vc = (w[1]/2) - (s.d.container.outerWidth(true)/2);
577
+
578
+ if (s.o.position && Object.prototype.toString.call(s.o.position) === '[object Array]') {
579
+ top = s.o.position[0] || hc;
580
+ left = s.o.position[1] || vc;
581
+ } else {
582
+ top = hc;
583
+ left = vc;
584
+ }
585
+ s.d.container.css({left: left, top: top});
586
+ },
587
+ watchTab: function (e) {
588
+ var s = this;
589
+
590
+ if ($(e.target).parents('.simplemodal-container').length > 0) {
591
+ // save the list of inputs
592
+ s.inputs = $(':input:enabled:visible:first, :input:enabled:visible:last', s.d.data[0]);
593
+
594
+ // if it's the first or last tabbable element, refocus
595
+ if ((!e.shiftKey && e.target === s.inputs[s.inputs.length -1]) ||
596
+ (e.shiftKey && e.target === s.inputs[0]) ||
597
+ s.inputs.length === 0) {
598
+ e.preventDefault();
599
+ var pos = e.shiftKey ? 'last' : 'first';
600
+ s.focus(pos);
601
+ }
602
+ }
603
+ else {
604
+ // might be necessary when custom onShow callback is used
605
+ e.preventDefault();
606
+ s.focus();
607
+ }
608
+ },
609
+ /*
610
+ * Open the modal dialog elements
611
+ * - Note: If you use the onOpen callback, you must "show" the
612
+ * overlay and container elements manually
613
+ * (the iframe will be handled by SimpleModal)
614
+ */
615
+ open: function () {
616
+ var s = this;
617
+ // display the iframe
618
+ s.d.iframe && s.d.iframe.show();
619
+
620
+ if ($.isFunction(s.o.onOpen)) {
621
+ // execute the onOpen callback
622
+ s.o.onOpen.apply(s, [s.d]);
623
+ }
624
+ else {
625
+ // display the remaining elements
626
+ s.d.overlay.show();
627
+ s.d.container.show();
628
+ s.d.data.show();
629
+ }
630
+
631
+ s.o.focus && s.focus();
632
+
633
+ // bind default events
634
+ s.bindEvents();
635
+ },
636
+ /*
637
+ * Close the modal dialog
638
+ * - Note: If you use an onClose callback, you must remove the
639
+ * overlay, container and iframe elements manually
640
+ *
641
+ * @param {boolean} external Indicates whether the call to this
642
+ * function was internal or external. If it was external, the
643
+ * onClose callback will be ignored
644
+ */
645
+ close: function () {
646
+ var s = this;
647
+
648
+ // prevent close when dialog does not exist
649
+ if (!s.d.data) {
650
+ return false;
651
+ }
652
+
653
+ // remove the default events
654
+ s.unbindEvents();
655
+
656
+ if ($.isFunction(s.o.onClose) && !s.occb) {
657
+ // set the onClose callback flag
658
+ s.occb = true;
659
+
660
+ // execute the onClose callback
661
+ s.o.onClose.apply(s, [s.d]);
662
+ }
663
+ else {
664
+ // if the data came from the DOM, put it back
665
+ if (s.d.placeholder) {
666
+ var ph = $('#simplemodal-placeholder');
667
+ // save changes to the data?
668
+ if (s.o.persist) {
669
+ // insert the (possibly) modified data back into the DOM
670
+ ph.replaceWith(s.d.data.removeClass('simplemodal-data').css('display', s.display));
671
+ }
672
+ else {
673
+ // remove the current and insert the original,
674
+ // unmodified data back into the DOM
675
+ s.d.data.hide().remove();
676
+ ph.replaceWith(s.d.orig);
677
+ }
678
+ }
679
+ else {
680
+ // otherwise, remove it
681
+ s.d.data.hide().remove();
682
+ }
683
+
684
+ // remove the remaining elements
685
+ s.d.container.hide().remove();
686
+ s.d.overlay.hide();
687
+ s.d.iframe && s.d.iframe.hide().remove();
688
+ setTimeout(function(){
689
+ // opera work-around
690
+ s.d.overlay.remove();
691
+
692
+ // reset the dialog object
693
+ s.d = {};
694
+ }, 10);
695
+ }
696
+ }
697
+ };
698
+ })(jQuery);