luca 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +17 -0
  3. data/Gemfile.lock +77 -0
  4. data/Guardfile +22 -0
  5. data/README.md +291 -0
  6. data/Rakefile +28 -0
  7. data/app.rb +46 -0
  8. data/assets/images/glyphicons-halflings-white.png +0 -0
  9. data/assets/images/glyphicons-halflings.png +0 -0
  10. data/assets/javascripts/dependencies/backbone-min.js +37 -0
  11. data/assets/javascripts/dependencies/backbone-query.min.js +1 -0
  12. data/assets/javascripts/dependencies/bootstrap.min.js +1 -0
  13. data/assets/javascripts/dependencies/jasmine-html.js +190 -0
  14. data/assets/javascripts/dependencies/jasmine.js +2476 -0
  15. data/assets/javascripts/dependencies/jquery.js +4 -0
  16. data/assets/javascripts/dependencies/modal.js +698 -0
  17. data/assets/javascripts/dependencies/modernizr.min.js +30 -0
  18. data/assets/javascripts/dependencies/prettify.js +28 -0
  19. data/assets/javascripts/dependencies/sinon.js +3469 -0
  20. data/assets/javascripts/dependencies/spin-min.js +2 -0
  21. data/assets/javascripts/dependencies/underscore-min.js +31 -0
  22. data/assets/javascripts/dependencies/underscore-string.min.js +14 -0
  23. data/assets/javascripts/dependencies.coffee +7 -0
  24. data/assets/javascripts/luca-ui-base.coffee +12 -0
  25. data/assets/javascripts/luca-ui-spec.coffee +2 -0
  26. data/assets/javascripts/luca-ui.coffee +3 -0
  27. data/assets/javascripts/sandbox/collections/sample.coffee +0 -0
  28. data/assets/javascripts/sandbox/config.coffee +7 -0
  29. data/assets/javascripts/sandbox/sandbox.coffee +16 -0
  30. data/assets/javascripts/sandbox/templates/features/collection_helpers.luca +33 -0
  31. data/assets/javascripts/sandbox/templates/features/form_demo_code.luca +48 -0
  32. data/assets/javascripts/sandbox/templates/features/grid_demo_code.luca +24 -0
  33. data/assets/javascripts/sandbox/templates/features/introduction.luca +11 -0
  34. data/assets/javascripts/sandbox/templates/features/view_helpers.luca +43 -0
  35. data/assets/javascripts/sandbox/templates/navigation.luca +8 -0
  36. data/assets/javascripts/sandbox/views/form_demo.coffee +47 -0
  37. data/assets/javascripts/sandbox/views/grid_demo.coffee +23 -0
  38. data/assets/javascripts/sandbox/views/pages/collection_events_sample.coffee +1 -0
  39. data/assets/javascripts/sandbox/views/pages/pages_controller.coffee +28 -0
  40. data/assets/javascripts/sandbox.coffee +4 -0
  41. data/assets/javascripts/spec-dependencies.coffee +4 -0
  42. data/assets/stylesheets/bootstrap-responsive.min.css +3 -0
  43. data/assets/stylesheets/bootstrap.min.css +610 -0
  44. data/assets/stylesheets/jasmine.css +166 -0
  45. data/assets/stylesheets/luca-ui-bootstrap.css +5 -0
  46. data/assets/stylesheets/luca-ui-spec.css +3 -0
  47. data/assets/stylesheets/luca-ui.css +3 -0
  48. data/assets/stylesheets/prettify.css +40 -0
  49. data/assets/stylesheets/sandbox/sandbox.scss +4 -0
  50. data/assets/stylesheets/sandbox.css +3 -0
  51. data/config.ru +11 -0
  52. data/lib/luca/command_line.rb +69 -0
  53. data/lib/luca/rails/engine.rb +12 -0
  54. data/lib/luca/rails/version.rb +6 -0
  55. data/lib/luca/rails.rb +9 -0
  56. data/lib/luca/template.rb +51 -0
  57. data/lib/luca/test_harness.rb +106 -0
  58. data/lib/luca.rb +1 -0
  59. data/lib/sprockets/luca_template.rb +49 -0
  60. data/lib/templates/spec_manifest_javascripts.erb +7 -0
  61. data/lib/templates/spec_manifest_stylesheets.erb +11 -0
  62. data/luca.gemspec +26 -0
  63. data/public/jasmine/index.html +26 -0
  64. data/public/sandbox/api.js +1 -0
  65. data/spec/components/application_spec.coffee +0 -0
  66. data/spec/components/collection_loader_view_spec.coffee +0 -0
  67. data/spec/components/controller_spec.coffee +0 -0
  68. data/spec/components/form_view_spec.coffee +13 -0
  69. data/spec/components/grid_view_spec.coffee +0 -0
  70. data/spec/components/record_manager_spec.coffee +0 -0
  71. data/spec/components/template_spec.coffee +0 -0
  72. data/spec/containers/card_view_spec.coffee +1 -0
  73. data/spec/containers/column_view_spec.coffee +0 -0
  74. data/spec/containers/modal_view_spec.coffee +0 -0
  75. data/spec/containers/panel_view_spec.coffee +0 -0
  76. data/spec/containers/split_view_spec.coffee +0 -0
  77. data/spec/containers/tab_view_spec.coffee +0 -0
  78. data/spec/containers/viewport_spec.coffee +0 -0
  79. data/spec/core/collection_spec.coffee +215 -0
  80. data/spec/core/container_spec.coffee +0 -0
  81. data/spec/core/field_spec.coffee +0 -0
  82. data/spec/core/observer_spec.coffee +0 -0
  83. data/spec/core/view_spec.coffee +87 -0
  84. data/spec/framework_spec.coffee +48 -0
  85. data/spec/helper.coffee +120 -0
  86. data/spec/managers/collection_manager_spec.coffee +95 -0
  87. data/spec/managers/socket_manager_spec.coffee +0 -0
  88. data/src/components/application.coffee +83 -0
  89. data/src/components/base_toolbar.coffee +16 -0
  90. data/src/components/collection_loader_view.coffee +37 -0
  91. data/src/components/controller.coffee +41 -0
  92. data/src/components/fields/button_field.coffee +40 -0
  93. data/src/components/fields/checkbox_field.coffee +41 -0
  94. data/src/components/fields/file_upload_field.coffee +15 -0
  95. data/src/components/fields/hidden_field.coffee +18 -0
  96. data/src/components/fields/select_field.coffee +100 -0
  97. data/src/components/fields/text_area_field.coffee +43 -0
  98. data/src/components/fields/text_field.coffee +42 -0
  99. data/src/components/fields/type_ahead_field.coffee +10 -0
  100. data/src/components/form_button_toolbar.coffee +26 -0
  101. data/src/components/form_view.coffee +205 -0
  102. data/src/components/grid_view.coffee +208 -0
  103. data/src/components/record_manager.coffee +215 -0
  104. data/src/components/router.coffee +34 -0
  105. data/src/components/template.coffee +19 -0
  106. data/src/containers/card_view.coffee +89 -0
  107. data/src/containers/column_view.coffee +48 -0
  108. data/src/containers/modal_view.coffee +85 -0
  109. data/src/containers/panel_view.coffee +24 -0
  110. data/src/containers/split_view.coffee +12 -0
  111. data/src/containers/tab_view.coffee +77 -0
  112. data/src/containers/viewport.coffee +16 -0
  113. data/src/core/collection.coffee +319 -0
  114. data/src/core/container.coffee +256 -0
  115. data/src/core/field.coffee +68 -0
  116. data/src/core/observer.coffee +17 -0
  117. data/src/core/view.coffee +190 -0
  118. data/src/framework.coffee +110 -0
  119. data/src/index.coffee +255 -0
  120. data/src/managers/collection_manager.coffee +168 -0
  121. data/src/managers/socket_manager.coffee +54 -0
  122. data/src/modules/deferrable.coffee +18 -0
  123. data/src/modules/local_storage.coffee +50 -0
  124. data/src/stylesheets/base.scss +78 -0
  125. data/src/stylesheets/components/form_view.scss +54 -0
  126. data/src/stylesheets/components/grid_view.scss +111 -0
  127. data/src/stylesheets/components/toolbar.scss +15 -0
  128. data/src/stylesheets/containers/container.scss +7 -0
  129. data/src/stylesheets/containers/modal_view.scss +0 -0
  130. data/src/stylesheets/containers/tab_view.scss +33 -0
  131. data/src/stylesheets/normalize.scss +430 -0
  132. data/src/templates/components/bootstrap_form_controls.luca +7 -0
  133. data/src/templates/components/collection_loader_view.luca +5 -0
  134. data/src/templates/components/form_view.luca +15 -0
  135. data/src/templates/components/grid_view.luca +9 -0
  136. data/src/templates/components/grid_view_empty_text.luca +3 -0
  137. data/src/templates/containers/basic.luca +1 -0
  138. data/src/templates/containers/tab_selector_container.luca +8 -0
  139. data/src/templates/containers/tab_view.luca +1 -0
  140. data/src/templates/containers/toolbar_wrapper.luca +1 -0
  141. data/src/templates/fields/button_field.luca +2 -0
  142. data/src/templates/fields/button_field_link.luca +5 -0
  143. data/src/templates/fields/checkbox_field.luca +9 -0
  144. data/src/templates/fields/file_upload_field.luca +8 -0
  145. data/src/templates/fields/hidden_field.luca +1 -0
  146. data/src/templates/fields/select_field.luca +7 -0
  147. data/src/templates/fields/text_area_field.luca +8 -0
  148. data/src/templates/fields/text_field.luca +13 -0
  149. data/src/templates/sample/contents.luca +1 -0
  150. data/src/templates/sample/welcome.luca +1 -0
  151. data/vendor/assets/images/glyphicons-halflings-white.png +0 -0
  152. data/vendor/assets/images/glyphicons-halflings.png +0 -0
  153. data/vendor/assets/javascripts/luca-spec-dependencies.js +6135 -0
  154. data/vendor/assets/javascripts/luca-ui-base.js +1527 -0
  155. data/vendor/assets/javascripts/luca-ui-spec.js +3654 -0
  156. data/vendor/assets/javascripts/luca-ui.js +2763 -0
  157. data/vendor/assets/luca-ui/base.css +85 -0
  158. data/vendor/assets/luca-ui/components/application.js +91 -0
  159. data/vendor/assets/luca-ui/components/base_toolbar.js +23 -0
  160. data/vendor/assets/luca-ui/components/controller.js +38 -0
  161. data/vendor/assets/luca-ui/components/fields/button_field.js +45 -0
  162. data/vendor/assets/luca-ui/components/fields/checkbox_field.js +43 -0
  163. data/vendor/assets/luca-ui/components/fields/file_upload_field.js +20 -0
  164. data/vendor/assets/luca-ui/components/fields/hidden_field.js +20 -0
  165. data/vendor/assets/luca-ui/components/fields/select_field.js +97 -0
  166. data/vendor/assets/luca-ui/components/fields/text_area_field.js +48 -0
  167. data/vendor/assets/luca-ui/components/fields/text_field.js +46 -0
  168. data/vendor/assets/luca-ui/components/fields/type_ahead_field.js +13 -0
  169. data/vendor/assets/luca-ui/components/form_button_toolbar.js +32 -0
  170. data/vendor/assets/luca-ui/components/form_view.css +32 -0
  171. data/vendor/assets/luca-ui/components/form_view.js +207 -0
  172. data/vendor/assets/luca-ui/components/grid_view.css +76 -0
  173. data/vendor/assets/luca-ui/components/grid_view.js +202 -0
  174. data/vendor/assets/luca-ui/components/record_manager.js +207 -0
  175. data/vendor/assets/luca-ui/components/router.js +36 -0
  176. data/vendor/assets/luca-ui/components/template.js +26 -0
  177. data/vendor/assets/luca-ui/components/toolbar.css +11 -0
  178. data/vendor/assets/luca-ui/containers/card_view.js +98 -0
  179. data/vendor/assets/luca-ui/containers/column_view.js +52 -0
  180. data/vendor/assets/luca-ui/containers/container.css +3 -0
  181. data/vendor/assets/luca-ui/containers/modal_view.css +0 -0
  182. data/vendor/assets/luca-ui/containers/modal_view.js +87 -0
  183. data/vendor/assets/luca-ui/containers/panel_view.js +34 -0
  184. data/vendor/assets/luca-ui/containers/split_view.js +13 -0
  185. data/vendor/assets/luca-ui/containers/tab_view.css +16 -0
  186. data/vendor/assets/luca-ui/containers/tab_view.js +80 -0
  187. data/vendor/assets/luca-ui/containers/viewport.js +18 -0
  188. data/vendor/assets/luca-ui/core/collection.js +221 -0
  189. data/vendor/assets/luca-ui/core/container.js +205 -0
  190. data/vendor/assets/luca-ui/core/field.js +59 -0
  191. data/vendor/assets/luca-ui/core/observer.js +42 -0
  192. data/vendor/assets/luca-ui/core/view.js +127 -0
  193. data/vendor/assets/luca-ui/framework.js +110 -0
  194. data/vendor/assets/luca-ui/index.js +5 -0
  195. data/vendor/assets/luca-ui/managers/collection_manager.js +98 -0
  196. data/vendor/assets/luca-ui/managers/socket_manager.js +52 -0
  197. data/vendor/assets/luca-ui/modules/deferrable.js +21 -0
  198. data/vendor/assets/luca-ui/modules/local_storage.js +81 -0
  199. data/vendor/assets/luca-ui/normalize.css +359 -0
  200. data/vendor/assets/luca-ui/stylesheets/base.css +85 -0
  201. data/vendor/assets/luca-ui/stylesheets/components/form_view.css +32 -0
  202. data/vendor/assets/luca-ui/stylesheets/components/grid_view.css +76 -0
  203. data/vendor/assets/luca-ui/stylesheets/components/toolbar.css +11 -0
  204. data/vendor/assets/luca-ui/stylesheets/containers/container.css +3 -0
  205. data/vendor/assets/luca-ui/stylesheets/containers/modal_view.css +0 -0
  206. data/vendor/assets/luca-ui/stylesheets/containers/tab_view.css +16 -0
  207. data/vendor/assets/luca-ui/stylesheets/normalize.css +359 -0
  208. data/vendor/assets/luca-ui/templates/components/bootstrap_form_controls.js +4 -0
  209. data/vendor/assets/luca-ui/templates/components/form_view.js +4 -0
  210. data/vendor/assets/luca-ui/templates/components/grid_view.js +4 -0
  211. data/vendor/assets/luca-ui/templates/components/grid_view_empty_text.js +4 -0
  212. data/vendor/assets/luca-ui/templates/containers/basic.js +4 -0
  213. data/vendor/assets/luca-ui/templates/containers/tab_selector_container.js +4 -0
  214. data/vendor/assets/luca-ui/templates/containers/tab_view.js +4 -0
  215. data/vendor/assets/luca-ui/templates/containers/toolbar_wrapper.js +4 -0
  216. data/vendor/assets/luca-ui/templates/fields/button_field.js +4 -0
  217. data/vendor/assets/luca-ui/templates/fields/button_field_link.js +4 -0
  218. data/vendor/assets/luca-ui/templates/fields/checkbox_field.js +4 -0
  219. data/vendor/assets/luca-ui/templates/fields/file_upload_field.js +4 -0
  220. data/vendor/assets/luca-ui/templates/fields/hidden_field.js +4 -0
  221. data/vendor/assets/luca-ui/templates/fields/select_field.js +4 -0
  222. data/vendor/assets/luca-ui/templates/fields/text_area_field.js +4 -0
  223. data/vendor/assets/luca-ui/templates/fields/text_field.js +4 -0
  224. data/vendor/assets/luca-ui/templates/sample/contents.js +4 -0
  225. data/vendor/assets/luca-ui/templates/sample/welcome.js +4 -0
  226. data/vendor/assets/stylesheets/luca-spec-dependencies.css +166 -0
  227. data/vendor/assets/stylesheets/luca-ui-bootstrap.css +1201 -0
  228. data/vendor/assets/stylesheets/luca-ui-spec.css +586 -0
  229. data/vendor/assets/stylesheets/luca-ui.css +586 -0
  230. data/views/index.erb +20 -0
  231. data/views/jasmine.erb +22 -0
  232. data/views/spec_harness.erb +29 -0
  233. metadata +361 -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);