ab_admin 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. data/Gemfile +6 -6
  2. data/Guardfile +6 -6
  3. data/README.md +5 -5
  4. data/app/assets/images/admin/Jcrop.gif +0 -0
  5. data/app/assets/javascripts/ab_admin/components/admin_assets.js.coffee +20 -19
  6. data/app/assets/javascripts/ab_admin/components/croppable_image.js.coffee +22 -38
  7. data/app/assets/javascripts/ab_admin/components/gmaps.js.coffee +2 -2
  8. data/app/assets/javascripts/ab_admin/core/ui_utils.js.coffee +6 -2
  9. data/app/assets/stylesheets/ab_admin/components/_base.css.scss +17 -1
  10. data/app/assets/stylesheets/ab_admin/components/_form.css.scss +1 -1
  11. data/app/assets/stylesheets/ab_admin/main.css.scss +1 -0
  12. data/app/controllers/admin/assets_controller.rb +10 -10
  13. data/app/controllers/admin/base_controller.rb +39 -37
  14. data/app/controllers/admin/locators_controller.rb +5 -4
  15. data/app/controllers/admin/manager_controller.rb +11 -10
  16. data/app/controllers/admin/settings_controller.rb +4 -3
  17. data/app/controllers/admin/static_pages_controller.rb +1 -1
  18. data/app/controllers/admin/structures_controller.rb +2 -2
  19. data/app/views/ab_admin/devise/passwords/edit.html.slim +5 -5
  20. data/app/views/ab_admin/devise/passwords/new.html.slim +3 -3
  21. data/app/views/ab_admin/devise/sessions/new.html.slim +5 -5
  22. data/app/views/admin/admin_comments/_comment.html.slim +3 -3
  23. data/app/views/admin/admin_comments/_comments.html.slim +2 -2
  24. data/app/views/admin/admin_comments/_form.html.slim +5 -5
  25. data/app/views/admin/admin_comments/create.js.erb +1 -1
  26. data/app/views/admin/base/_form.html.slim +1 -1
  27. data/app/views/admin/base/_search_layout.html.slim +4 -4
  28. data/app/views/admin/base/_tree.html.slim +1 -1
  29. data/app/views/admin/base/create.js.erb +1 -1
  30. data/app/views/admin/base/index.html.slim +3 -3
  31. data/app/views/admin/base/update.js.erb +1 -1
  32. data/app/views/admin/dashboards/index.html.slim +15 -1
  33. data/app/views/admin/fileupload/_asset.html.slim +1 -1
  34. data/app/views/admin/fileupload/_container.html.slim +2 -2
  35. data/app/views/admin/fileupload/_file.html.slim +1 -1
  36. data/app/views/admin/fileupload/_tmpl.html.slim +1 -1
  37. data/app/views/admin/headers/_form.html.slim +3 -3
  38. data/app/views/admin/locators/edit.html.slim +4 -4
  39. data/app/views/admin/locators/show.html.slim +3 -3
  40. data/app/views/admin/manager/_form.html.slim +2 -1
  41. data/app/views/admin/manager/_table.html.slim +6 -3
  42. data/app/views/admin/settings/_form.html.slim +8 -8
  43. data/app/views/admin/shared/_batch_actions.html.slim +1 -1
  44. data/app/views/admin/static_pages/_form.html.slim +3 -3
  45. data/app/views/admin/structures/_form.html.slim +7 -7
  46. data/app/views/admin/users/_form.html.slim +9 -9
  47. data/app/views/admin/users/_search_form.html.slim +4 -4
  48. data/app/views/admin/users/_table.html.slim +3 -3
  49. data/app/views/layouts/admin/_footer.html.slim +4 -0
  50. data/app/views/layouts/admin/_navigation.html.slim +2 -2
  51. data/app/views/layouts/admin/application.html.slim +3 -3
  52. data/app/views/layouts/admin/devise.html.slim +2 -2
  53. data/config/locales/ru.yml +1 -0
  54. data/config/routes.rb +23 -23
  55. data/db/migrate/20130101000001_create_users.rb +11 -11
  56. data/db/migrate/20130101000003_create_assets.rb +8 -8
  57. data/db/migrate/20130101000004_create_headers.rb +3 -3
  58. data/db/migrate/20130101000005_create_static_pages.rb +2 -2
  59. data/db/migrate/20130101000006_create_structures.rb +8 -8
  60. data/db/migrate/20130101000007_base_translations.rb +3 -3
  61. data/db/migrate/20130101000008_create_admin_comments.rb +3 -3
  62. data/features/dsl/action_items.feature +1 -1
  63. data/features/dsl/admin_comments.feature +2 -2
  64. data/features/dsl/batch_actions.feature +1 -1
  65. data/features/dsl/config.feature +2 -2
  66. data/features/dsl/custom_actions.feature +5 -5
  67. data/features/dsl/form.feature +4 -4
  68. data/features/dsl/in_place_edit.feature +1 -1
  69. data/features/dsl/list_edit.feature +1 -1
  70. data/features/dsl/resource_action_items.feature +1 -1
  71. data/features/dsl/table.feature +3 -3
  72. data/features/dsl/tree.feature +3 -3
  73. data/features/locators.feature +1 -1
  74. data/features/menu.feature +3 -3
  75. data/features/step_definitions/dsl/action_items_steps.rb +3 -3
  76. data/features/step_definitions/dsl/admin_comments_steps.rb +1 -1
  77. data/features/step_definitions/dsl/batch_actions_steps.rb +1 -1
  78. data/features/step_definitions/dsl/parent_resource_steps.rb +2 -2
  79. data/features/step_definitions/dsl/table_steps.rb +3 -3
  80. data/features/step_definitions/dsl/tree_steps.rb +3 -3
  81. data/features/step_definitions/menu_steps.rb +3 -3
  82. data/features/step_definitions/structure_steps.rb +1 -1
  83. data/features/step_definitions/user_steps.rb +7 -7
  84. data/features/step_definitions/web_steps/browsing_steps.rb +2 -2
  85. data/features/step_definitions/web_steps/form_steps.rb +7 -7
  86. data/features/support/selectors.rb +5 -5
  87. data/features/support/tolerance_for_selenium_sync_issues.rb +1 -1
  88. data/lib/ab_admin/abstract_resource.rb +3 -3
  89. data/lib/ab_admin/carrierwave/base_uploader.rb +7 -7
  90. data/lib/ab_admin/carrierwave/file_size_validator.rb +4 -4
  91. data/lib/ab_admin/carrierwave/glue.rb +1 -1
  92. data/lib/ab_admin/concerns/admin_addition.rb +17 -13
  93. data/lib/ab_admin/concerns/headerable.rb +2 -2
  94. data/lib/ab_admin/concerns/nested_set.rb +23 -1
  95. data/lib/ab_admin/concerns/reloadable.rb +56 -0
  96. data/lib/ab_admin/concerns/utilities.rb +3 -3
  97. data/lib/ab_admin/concerns/validations.rb +2 -2
  98. data/lib/ab_admin/config/base.rb +5 -5
  99. data/lib/ab_admin/config/optional_display.rb +4 -4
  100. data/lib/ab_admin/controllers/callbacks.rb +1 -1
  101. data/lib/ab_admin/controllers/can_can_manager_resource.rb +1 -1
  102. data/lib/ab_admin/controllers/head_options.rb +5 -9
  103. data/lib/ab_admin/controllers/tree.rb +2 -2
  104. data/lib/ab_admin/core_ext/other.rb +2 -2
  105. data/lib/ab_admin/core_ext/string.rb +2 -2
  106. data/lib/ab_admin/devise.rb +3 -3
  107. data/lib/ab_admin/engine.rb +1 -1
  108. data/lib/ab_admin/hooks/paginate_hooks.rb +2 -2
  109. data/lib/ab_admin/hooks/simple_form_hooks.rb +2 -2
  110. data/lib/ab_admin/i18n_tools/google_translate.rb +5 -5
  111. data/lib/ab_admin/i18n_tools/model_translator.rb +7 -7
  112. data/lib/ab_admin/i18n_tools/translate_app.rb +1 -1
  113. data/lib/ab_admin/menu_builder.rb +3 -3
  114. data/lib/ab_admin/models/asset.rb +14 -6
  115. data/lib/ab_admin/models/attachment_file.rb +2 -2
  116. data/lib/ab_admin/models/header.rb +1 -1
  117. data/lib/ab_admin/models/locator.rb +3 -3
  118. data/lib/ab_admin/models/structure.rb +8 -8
  119. data/lib/ab_admin/models/type_model.rb +3 -3
  120. data/lib/ab_admin/models/user.rb +7 -7
  121. data/lib/ab_admin/utils/csv_document.rb +2 -2
  122. data/lib/ab_admin/utils/logger.rb +1 -1
  123. data/lib/ab_admin/utils/xls_document.rb +4 -4
  124. data/lib/ab_admin/utils.rb +11 -11
  125. data/lib/ab_admin/version.rb +1 -1
  126. data/lib/ab_admin/views/admin_helpers.rb +13 -13
  127. data/lib/ab_admin/views/admin_navigation_helpers.rb +26 -26
  128. data/lib/ab_admin/views/form_builder.rb +36 -22
  129. data/lib/ab_admin/views/helpers.rb +6 -6
  130. data/lib/ab_admin/views/inputs/ckeditor_input.rb +1 -1
  131. data/lib/ab_admin/views/inputs/color_input.rb +1 -1
  132. data/lib/ab_admin/views/inputs/date_time_input.rb +7 -7
  133. data/lib/ab_admin/views/manager_helpers.rb +3 -3
  134. data/lib/ab_admin/views/search_form_builder.rb +18 -18
  135. data/lib/ab_admin/views/url_for_routes.rb +4 -4
  136. data/lib/ab_admin.rb +1 -2
  137. data/lib/generators/ab_admin/glob/glob_generator.rb +1 -1
  138. data/lib/generators/ab_admin/install/install_generator.rb +2 -2
  139. data/lib/generators/ab_admin/install/templates/config/admin_menu.rb +2 -0
  140. data/lib/generators/ab_admin/install/templates/config/seeds.rb +1 -1
  141. data/lib/generators/ab_admin/install/templates/config/unicorn_config.rb +3 -3
  142. data/lib/generators/ab_admin/install/templates/helpers/admin/structures_helper.rb +2 -2
  143. data/lib/generators/ab_admin/install/templates/models/ability.rb +4 -4
  144. data/lib/generators/ab_admin/install/templates/models/admin_comment.rb +4 -4
  145. data/lib/generators/ab_admin/install/templates/models/asset.rb +2 -1
  146. data/lib/generators/ab_admin/install/templates/models/attachment_file.rb +1 -1
  147. data/lib/generators/ab_admin/install/templates/models/avatar.rb +2 -2
  148. data/lib/generators/ab_admin/install/templates/models/locator.rb +3 -0
  149. data/lib/generators/ab_admin/install/templates/models/picture.rb +2 -2
  150. data/lib/generators/ab_admin/install/templates/models/settings.rb +3 -0
  151. data/lib/generators/ab_admin/install/templates/models/static_page.rb +3 -3
  152. data/lib/generators/ab_admin/install/templates/models/structure.rb +2 -2
  153. data/lib/generators/ab_admin/install/templates/models/user.rb +2 -2
  154. data/lib/generators/ab_admin/install/templates/spec/spec_helper.rb +2 -2
  155. data/lib/generators/ab_admin/install/templates/spec/support/shared_connection.rb +1 -1
  156. data/lib/generators/ab_admin/install/templates/uploaders/avatar_uploader.rb +2 -2
  157. data/lib/generators/ab_admin/install/templates/uploaders/picture_uploader.rb +4 -3
  158. data/lib/generators/ab_admin/model/model_generator.rb +4 -2
  159. data/lib/generators/ab_admin/model/templates/resource.erb +6 -6
  160. data/lib/generators/ab_admin/resource/resource_generator.rb +9 -9
  161. data/lib/generators/ab_admin/resource/templates/_form.haml.erb +10 -14
  162. data/lib/generators/ab_admin/resource/templates/_form.slim.erb +11 -11
  163. data/lib/generators/ab_admin/resource/templates/_search_form.haml.erb +1 -1
  164. data/lib/generators/ab_admin/resource/templates/_search_form.slim.erb +1 -1
  165. data/lib/generators/ab_admin/resource/templates/controller.erb +1 -1
  166. data/lib/generators/template.rb +8 -8
  167. data/lib/tasks/assets.rake +5 -5
  168. data/lib/tasks/cache.rake +1 -1
  169. data/lib/tasks/i18n.rake +1 -1
  170. data/spec/ab_admin_spec.rb +3 -3
  171. data/spec/dummy/app/models/ab_admin/ab_admin_catalogue.rb +1 -1
  172. data/spec/dummy/app/models/ab_admin/ab_admin_collection.rb +6 -6
  173. data/spec/dummy/app/models/ab_admin/ab_admin_product.rb +14 -14
  174. data/spec/dummy/app/models/admin_menu.rb +2 -2
  175. data/spec/dummy/app/models/ckeditor/asset.rb +1 -1
  176. data/spec/dummy/app/models/ckeditor/attachment_file.rb +1 -1
  177. data/spec/dummy/app/models/ckeditor/picture.rb +1 -1
  178. data/spec/dummy/app/models/collection.rb +5 -5
  179. data/spec/dummy/app/models/product.rb +5 -5
  180. data/spec/dummy/app/uploaders/ckeditor_attachment_file_uploader.rb +1 -1
  181. data/spec/dummy/app/uploaders/ckeditor_picture_uploader.rb +3 -3
  182. data/spec/dummy/app/views/layouts/application.html.erb +2 -2
  183. data/spec/dummy/config/application.rb +2 -2
  184. data/spec/dummy/config/environments/test.rb +1 -1
  185. data/spec/dummy/config/initializers/ckeditor.rb +2 -2
  186. data/spec/dummy/config/initializers/devise.rb +5 -5
  187. data/spec/dummy/config/initializers/session_store.rb +1 -1
  188. data/spec/dummy/config/initializers/simple_form.rb +8 -8
  189. data/spec/dummy/config/initializers/simple_form_bootstrap.rb +14 -14
  190. data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
  191. data/spec/dummy/config/routes.rb +2 -2
  192. data/spec/dummy/db/migrate/20130129151853_create_ckeditor_assets.rb +5 -5
  193. data/spec/dummy/db/migrate/20130130161853_create_collections.rb +2 -2
  194. data/spec/dummy/db/migrate/20130130162046_create_products.rb +2 -2
  195. data/spec/dummy/db/migrate/20130130175446_create_globalize_collection_product.rb +2 -2
  196. data/spec/dummy/db/migrate/20130207224516_create_catalogues.rb +3 -3
  197. data/spec/dummy/db/migrate/20130209223506_add_lat_lon_zoom_to_products.rb +1 -1
  198. data/spec/dummy/db/seeds.rb +5 -5
  199. data/spec/dummy/lib/capybara_irb.rb +10 -10
  200. data/spec/dummy/lib/tasks/cucumber.rake +10 -10
  201. data/spec/dummy/lib/templates/slim/scaffold/_form.html.slim +2 -2
  202. data/spec/factories/assets.rb +9 -9
  203. data/spec/factories/catalogues.rb +1 -1
  204. data/spec/factories/collections.rb +1 -1
  205. data/spec/factories/products.rb +2 -2
  206. data/spec/factories/structures.rb +2 -2
  207. data/spec/generators/ckeditor_assets_generator_spec.rb +1 -1
  208. data/spec/generators/install_generator_spec.rb +1 -1
  209. data/spec/generators/model_generator_spec.rb +2 -2
  210. data/spec/generators/resource_generator_spec.rb +1 -1
  211. data/spec/models/avatar_spec.rb +1 -1
  212. data/spec/models/picture_uploader_spec.rb +1 -1
  213. data/spec/models/structure_spec.rb +2 -2
  214. data/spec/models/user_spec.rb +1 -1
  215. data/spec/spec_helper.rb +3 -3
  216. data/spec/support/shared_connection.rb +1 -1
  217. data/vendor/assets/javascripts/ab_admin/jquery.Jcrop.js +1083 -0
  218. data/vendor/assets/stylesheets/ab_admin/jquery.Jcrop.min.css.scss +28 -0
  219. metadata +8 -6
  220. data/lib/ab_admin/views/inputs/association_input.rb +0 -13
  221. data/lib/ab_admin/views/inputs/tree_select_input.rb +0 -16
@@ -0,0 +1,1083 @@
1
+ /**
2
+ * jquery.Jcrop.min.js v0.9.9 (build:20110607)
3
+ * jQuery Image Cropping Plugin
4
+ * @author Kelly Hallman <khallman@gmail.com>
5
+ * Copyright (c) 2008-2011 Kelly Hallman - released under MIT License
6
+ * https://github.com/tapmodo/Jcrop
7
+ */
8
+
9
+ (function ($) {
10
+ $.Jcrop = function (obj, opt) {
11
+ var options = $.extend({}, $.Jcrop.defaults), docOffset, lastcurs, ie6mode = false;
12
+
13
+ function px(n) {
14
+ return parseInt(n, 10) + 'px';
15
+ }
16
+
17
+ function pct(n) {
18
+ return parseInt(n, 10) + '%';
19
+ }
20
+
21
+ function cssClass(cl) {
22
+ return options.baseClass + '-' + cl;
23
+ }
24
+
25
+ function supportsColorFade() {
26
+ return $.fx.step.hasOwnProperty('backgroundColor');
27
+ }
28
+
29
+ function getPos(obj) {
30
+ var pos = $(obj).offset();
31
+ return[pos.left, pos.top];
32
+ }
33
+
34
+ function mouseAbs(e) {
35
+ return[(e.pageX - docOffset[0]), (e.pageY - docOffset[1])];
36
+ }
37
+
38
+ function setOptions(opt) {
39
+ if (typeof(opt) !== 'object') {
40
+ opt = {};
41
+ }
42
+ options = $.extend(options, opt);
43
+ if (typeof(options.onChange) !== 'function') {
44
+ options.onChange = function () {
45
+ };
46
+ }
47
+ if (typeof(options.onSelect) !== 'function') {
48
+ options.onSelect = function () {
49
+ };
50
+ }
51
+ if (typeof(options.onRelease) !== 'function') {
52
+ options.onRelease = function () {
53
+ };
54
+ }
55
+ }
56
+
57
+ function myCursor(type) {
58
+ if (type !== lastcurs) {
59
+ Tracker.setCursor(type);
60
+ lastcurs = type;
61
+ }
62
+ }
63
+
64
+ function startDragMode(mode, pos) {
65
+ docOffset = getPos($img);
66
+ Tracker.setCursor(mode === 'move' ? mode : mode + '-resize');
67
+ if (mode === 'move') {
68
+ return Tracker.activateHandlers(createMover(pos), doneSelect);
69
+ }
70
+ var fc = Coords.getFixed();
71
+ var opp = oppLockCorner(mode);
72
+ var opc = Coords.getCorner(oppLockCorner(opp));
73
+ Coords.setPressed(Coords.getCorner(opp));
74
+ Coords.setCurrent(opc);
75
+ Tracker.activateHandlers(dragmodeHandler(mode, fc), doneSelect);
76
+ }
77
+
78
+ function dragmodeHandler(mode, f) {
79
+ return function (pos) {
80
+ if (!options.aspectRatio) {
81
+ switch (mode) {
82
+ case'e':
83
+ pos[1] = f.y2;
84
+ break;
85
+ case'w':
86
+ pos[1] = f.y2;
87
+ break;
88
+ case'n':
89
+ pos[0] = f.x2;
90
+ break;
91
+ case's':
92
+ pos[0] = f.x2;
93
+ break;
94
+ }
95
+ } else {
96
+ switch (mode) {
97
+ case'e':
98
+ pos[1] = f.y + 1;
99
+ break;
100
+ case'w':
101
+ pos[1] = f.y + 1;
102
+ break;
103
+ case'n':
104
+ pos[0] = f.x + 1;
105
+ break;
106
+ case's':
107
+ pos[0] = f.x + 1;
108
+ break;
109
+ }
110
+ }
111
+ Coords.setCurrent(pos);
112
+ Selection.update();
113
+ };
114
+ }
115
+
116
+ function createMover(pos) {
117
+ var lloc = pos;
118
+ KeyManager.watchKeys();
119
+ return function (pos) {
120
+ Coords.moveOffset([pos[0] - lloc[0], pos[1] - lloc[1]]);
121
+ lloc = pos;
122
+ Selection.update();
123
+ };
124
+ }
125
+
126
+ function oppLockCorner(ord) {
127
+ switch (ord) {
128
+ case'n':
129
+ return'sw';
130
+ case's':
131
+ return'nw';
132
+ case'e':
133
+ return'nw';
134
+ case'w':
135
+ return'ne';
136
+ case'ne':
137
+ return'sw';
138
+ case'nw':
139
+ return'se';
140
+ case'se':
141
+ return'nw';
142
+ case'sw':
143
+ return'ne';
144
+ }
145
+ }
146
+
147
+ function createDragger(ord) {
148
+ return function (e) {
149
+ if (options.disabled) {
150
+ return false;
151
+ }
152
+ if ((ord === 'move') && !options.allowMove) {
153
+ return false;
154
+ }
155
+ btndown = true;
156
+ startDragMode(ord, mouseAbs(e));
157
+ e.stopPropagation();
158
+ e.preventDefault();
159
+ return false;
160
+ };
161
+ }
162
+
163
+ function presize($obj, w, h) {
164
+ var nw = $obj.width(), nh = $obj.height();
165
+ if ((nw > w) && w > 0) {
166
+ nw = w;
167
+ nh = (w / $obj.width()) * $obj.height();
168
+ }
169
+ if ((nh > h) && h > 0) {
170
+ nh = h;
171
+ nw = (h / $obj.height()) * $obj.width();
172
+ }
173
+ xscale = $obj.width() / nw;
174
+ yscale = $obj.height() / nh;
175
+ $obj.width(nw).height(nh);
176
+ }
177
+
178
+ function unscale(c) {
179
+ return{x:parseInt(c.x * xscale, 10), y:parseInt(c.y * yscale, 10), x2:parseInt(c.x2 * xscale, 10), y2:parseInt(c.y2 * yscale, 10), w:parseInt(c.w * xscale, 10), h:parseInt(c.h * yscale, 10)};
180
+ }
181
+
182
+ function doneSelect(pos) {
183
+ var c = Coords.getFixed();
184
+ if ((c.w > options.minSelect[0]) && (c.h > options.minSelect[1])) {
185
+ Selection.enableHandles();
186
+ Selection.done();
187
+ } else {
188
+ Selection.release();
189
+ }
190
+ Tracker.setCursor(options.allowSelect ? 'crosshair' : 'default');
191
+ }
192
+
193
+ function newSelection(e) {
194
+ if (options.disabled) {
195
+ return false;
196
+ }
197
+ if (!options.allowSelect) {
198
+ return false;
199
+ }
200
+ btndown = true;
201
+ docOffset = getPos($img);
202
+ Selection.disableHandles();
203
+ myCursor('crosshair');
204
+ var pos = mouseAbs(e);
205
+ Coords.setPressed(pos);
206
+ Selection.update();
207
+ Tracker.activateHandlers(selectDrag, doneSelect);
208
+ KeyManager.watchKeys();
209
+ e.stopPropagation();
210
+ e.preventDefault();
211
+ return false;
212
+ }
213
+
214
+ function selectDrag(pos) {
215
+ Coords.setCurrent(pos);
216
+ Selection.update();
217
+ }
218
+
219
+ function newTracker() {
220
+ var trk = $('<div></div>').addClass(cssClass('tracker'));
221
+ if ($.browser.msie) {
222
+ trk.css({opacity:0, backgroundColor:'white'});
223
+ }
224
+ return trk;
225
+ }
226
+
227
+ if ($.browser.msie && ($.browser.version.split('.')[0] === '6')) {
228
+ ie6mode = true;
229
+ }
230
+ if (typeof(obj) !== 'object') {
231
+ obj = $(obj)[0];
232
+ }
233
+ if (typeof(opt) !== 'object') {
234
+ opt = {};
235
+ }
236
+ setOptions(opt);
237
+ var img_css = {border:'none', margin:0, padding:0, position:'absolute'};
238
+ var $origimg = $(obj);
239
+ var $img = $origimg.clone().removeAttr('id').css(img_css);
240
+ $img.width($origimg.width());
241
+ $img.height($origimg.height());
242
+ $origimg.after($img).hide();
243
+ presize($img, options.boxWidth, options.boxHeight);
244
+ var boundx = $img.width(), boundy = $img.height(), $div = $('<div />').width(boundx).height(boundy).addClass(cssClass('holder')).css({position:'relative', backgroundColor:options.bgColor}).insertAfter($origimg).append($img);
245
+ delete(options.bgColor);
246
+ if (options.addClass) {
247
+ $div.addClass(options.addClass);
248
+ }
249
+ var $img2 = $('<img />').attr('src', $img.attr('src')).css(img_css).width(boundx).height(boundy), $img_holder = $('<div />').width(pct(100)).height(pct(100)).css({zIndex:310, position:'absolute', overflow:'hidden'}).append($img2), $hdl_holder = $('<div />').width(pct(100)).height(pct(100)).css('zIndex', 320), $sel = $('<div />').css({position:'absolute', zIndex:300}).insertBefore($img).append($img_holder, $hdl_holder);
250
+ if (ie6mode) {
251
+ $sel.css({overflowY:'hidden'});
252
+ }
253
+ var bound = options.boundary;
254
+ var $trk = newTracker().width(boundx + (bound * 2)).height(boundy + (bound * 2)).css({position:'absolute', top:px(-bound), left:px(-bound), zIndex:290}).mousedown(newSelection);
255
+ var bgopacity = options.bgOpacity, xlimit, ylimit, xmin, ymin, xscale, yscale, enabled = true, btndown, animating, shift_down;
256
+ docOffset = getPos($img);
257
+ var Touch = (function () {
258
+ function hasTouchSupport() {
259
+ var support = {}, events = ['touchstart', 'touchmove', 'touchend'], el = document.createElement('div'), i;
260
+ try {
261
+ for (i = 0; i < events.length; i++) {
262
+ var eventName = events[i];
263
+ eventName = 'on' + eventName;
264
+ var isSupported = (eventName in el);
265
+ if (!isSupported) {
266
+ el.setAttribute(eventName, 'return;');
267
+ isSupported = typeof el[eventName] == 'function';
268
+ }
269
+ support[events[i]] = isSupported;
270
+ }
271
+ return support.touchstart && support.touchend && support.touchmove;
272
+ }
273
+ catch (err) {
274
+ return false;
275
+ }
276
+ }
277
+
278
+ function detectSupport() {
279
+ if ((options.touchSupport === true) || (options.touchSupport === false))return options.touchSupport; else return hasTouchSupport();
280
+ }
281
+
282
+ return{createDragger:function (ord) {
283
+ return function (e) {
284
+ e.pageX = e.originalEvent.changedTouches[0].pageX;
285
+ e.pageY = e.originalEvent.changedTouches[0].pageY;
286
+ if (options.disabled) {
287
+ return false;
288
+ }
289
+ if ((ord === 'move') && !options.allowMove) {
290
+ return false;
291
+ }
292
+ btndown = true;
293
+ startDragMode(ord, mouseAbs(e));
294
+ e.stopPropagation();
295
+ e.preventDefault();
296
+ return false;
297
+ };
298
+ }, newSelection:function (e) {
299
+ e.pageX = e.originalEvent.changedTouches[0].pageX;
300
+ e.pageY = e.originalEvent.changedTouches[0].pageY;
301
+ return newSelection(e);
302
+ }, isSupported:hasTouchSupport, support:detectSupport()};
303
+ }());
304
+ var Coords = (function () {
305
+ var x1 = 0, y1 = 0, x2 = 0, y2 = 0, ox, oy;
306
+
307
+ function setPressed(pos) {
308
+ pos = rebound(pos);
309
+ x2 = x1 = pos[0];
310
+ y2 = y1 = pos[1];
311
+ }
312
+
313
+ function setCurrent(pos) {
314
+ pos = rebound(pos);
315
+ ox = pos[0] - x2;
316
+ oy = pos[1] - y2;
317
+ x2 = pos[0];
318
+ y2 = pos[1];
319
+ }
320
+
321
+ function getOffset() {
322
+ return[ox, oy];
323
+ }
324
+
325
+ function moveOffset(offset) {
326
+ var ox = offset[0], oy = offset[1];
327
+ if (0 > x1 + ox) {
328
+ ox -= ox + x1;
329
+ }
330
+ if (0 > y1 + oy) {
331
+ oy -= oy + y1;
332
+ }
333
+ if (boundy < y2 + oy) {
334
+ oy += boundy - (y2 + oy);
335
+ }
336
+ if (boundx < x2 + ox) {
337
+ ox += boundx - (x2 + ox);
338
+ }
339
+ x1 += ox;
340
+ x2 += ox;
341
+ y1 += oy;
342
+ y2 += oy;
343
+ }
344
+
345
+ function getCorner(ord) {
346
+ var c = getFixed();
347
+ switch (ord) {
348
+ case'ne':
349
+ return[c.x2, c.y];
350
+ case'nw':
351
+ return[c.x, c.y];
352
+ case'se':
353
+ return[c.x2, c.y2];
354
+ case'sw':
355
+ return[c.x, c.y2];
356
+ }
357
+ }
358
+
359
+ function getFixed() {
360
+ if (!options.aspectRatio) {
361
+ return getRect();
362
+ }
363
+ var aspect = options.aspectRatio, min_x = options.minSize[0] / xscale, max_x = options.maxSize[0] / xscale, max_y = options.maxSize[1] / yscale, rw = x2 - x1, rh = y2 - y1, rwa = Math.abs(rw), rha = Math.abs(rh), real_ratio = rwa / rha, xx, yy;
364
+ if (max_x === 0) {
365
+ max_x = boundx * 10;
366
+ }
367
+ if (max_y === 0) {
368
+ max_y = boundy * 10;
369
+ }
370
+ if (real_ratio < aspect) {
371
+ yy = y2;
372
+ w = rha * aspect;
373
+ xx = rw < 0 ? x1 - w : w + x1;
374
+ if (xx < 0) {
375
+ xx = 0;
376
+ h = Math.abs((xx - x1) / aspect);
377
+ yy = rh < 0 ? y1 - h : h + y1;
378
+ } else if (xx > boundx) {
379
+ xx = boundx;
380
+ h = Math.abs((xx - x1) / aspect);
381
+ yy = rh < 0 ? y1 - h : h + y1;
382
+ }
383
+ } else {
384
+ xx = x2;
385
+ h = rwa / aspect;
386
+ yy = rh < 0 ? y1 - h : y1 + h;
387
+ if (yy < 0) {
388
+ yy = 0;
389
+ w = Math.abs((yy - y1) * aspect);
390
+ xx = rw < 0 ? x1 - w : w + x1;
391
+ } else if (yy > boundy) {
392
+ yy = boundy;
393
+ w = Math.abs(yy - y1) * aspect;
394
+ xx = rw < 0 ? x1 - w : w + x1;
395
+ }
396
+ }
397
+ if (xx > x1) {
398
+ if (xx - x1 < min_x) {
399
+ xx = x1 + min_x;
400
+ } else if (xx - x1 > max_x) {
401
+ xx = x1 + max_x;
402
+ }
403
+ if (yy > y1) {
404
+ yy = y1 + (xx - x1) / aspect;
405
+ } else {
406
+ yy = y1 - (xx - x1) / aspect;
407
+ }
408
+ } else if (xx < x1) {
409
+ if (x1 - xx < min_x) {
410
+ xx = x1 - min_x;
411
+ } else if (x1 - xx > max_x) {
412
+ xx = x1 - max_x;
413
+ }
414
+ if (yy > y1) {
415
+ yy = y1 + (x1 - xx) / aspect;
416
+ } else {
417
+ yy = y1 - (x1 - xx) / aspect;
418
+ }
419
+ }
420
+ if (xx < 0) {
421
+ x1 -= xx;
422
+ xx = 0;
423
+ } else if (xx > boundx) {
424
+ x1 -= xx - boundx;
425
+ xx = boundx;
426
+ }
427
+ if (yy < 0) {
428
+ y1 -= yy;
429
+ yy = 0;
430
+ } else if (yy > boundy) {
431
+ y1 -= yy - boundy;
432
+ yy = boundy;
433
+ }
434
+ return makeObj(flipCoords(x1, y1, xx, yy));
435
+ }
436
+
437
+ function rebound(p) {
438
+ if (p[0] < 0) {
439
+ p[0] = 0;
440
+ }
441
+ if (p[1] < 0) {
442
+ p[1] = 0;
443
+ }
444
+ if (p[0] > boundx) {
445
+ p[0] = boundx;
446
+ }
447
+ if (p[1] > boundy) {
448
+ p[1] = boundy;
449
+ }
450
+ return[p[0], p[1]];
451
+ }
452
+
453
+ function flipCoords(x1, y1, x2, y2) {
454
+ var xa = x1, xb = x2, ya = y1, yb = y2;
455
+ if (x2 < x1) {
456
+ xa = x2;
457
+ xb = x1;
458
+ }
459
+ if (y2 < y1) {
460
+ ya = y2;
461
+ yb = y1;
462
+ }
463
+ return[Math.round(xa), Math.round(ya), Math.round(xb), Math.round(yb)];
464
+ }
465
+
466
+ function getRect() {
467
+ var xsize = x2 - x1, ysize = y2 - y1, delta;
468
+ if (xlimit && (Math.abs(xsize) > xlimit)) {
469
+ x2 = (xsize > 0) ? (x1 + xlimit) : (x1 - xlimit);
470
+ }
471
+ if (ylimit && (Math.abs(ysize) > ylimit)) {
472
+ y2 = (ysize > 0) ? (y1 + ylimit) : (y1 - ylimit);
473
+ }
474
+ if (ymin / yscale && (Math.abs(ysize) < ymin / yscale)) {
475
+ y2 = (ysize > 0) ? (y1 + ymin / yscale) : (y1 - ymin / yscale);
476
+ }
477
+ if (xmin / xscale && (Math.abs(xsize) < xmin / xscale)) {
478
+ x2 = (xsize > 0) ? (x1 + xmin / xscale) : (x1 - xmin / xscale);
479
+ }
480
+ if (x1 < 0) {
481
+ x2 -= x1;
482
+ x1 -= x1;
483
+ }
484
+ if (y1 < 0) {
485
+ y2 -= y1;
486
+ y1 -= y1;
487
+ }
488
+ if (x2 < 0) {
489
+ x1 -= x2;
490
+ x2 -= x2;
491
+ }
492
+ if (y2 < 0) {
493
+ y1 -= y2;
494
+ y2 -= y2;
495
+ }
496
+ if (x2 > boundx) {
497
+ delta = x2 - boundx;
498
+ x1 -= delta;
499
+ x2 -= delta;
500
+ }
501
+ if (y2 > boundy) {
502
+ delta = y2 - boundy;
503
+ y1 -= delta;
504
+ y2 -= delta;
505
+ }
506
+ if (x1 > boundx) {
507
+ delta = x1 - boundy;
508
+ y2 -= delta;
509
+ y1 -= delta;
510
+ }
511
+ if (y1 > boundy) {
512
+ delta = y1 - boundy;
513
+ y2 -= delta;
514
+ y1 -= delta;
515
+ }
516
+ return makeObj(flipCoords(x1, y1, x2, y2));
517
+ }
518
+
519
+ function makeObj(a) {
520
+ return{x:a[0], y:a[1], x2:a[2], y2:a[3], w:a[2] - a[0], h:a[3] - a[1]};
521
+ }
522
+
523
+ return{flipCoords:flipCoords, setPressed:setPressed, setCurrent:setCurrent, getOffset:getOffset, moveOffset:moveOffset, getCorner:getCorner, getFixed:getFixed};
524
+ }());
525
+ var Selection = (function () {
526
+ var awake, hdep = 370;
527
+ var borders = {};
528
+ var handle = {};
529
+ var seehandles = false;
530
+ var hhs = options.handleOffset;
531
+
532
+ function insertBorder(type) {
533
+ var jq = $('<div />').css({position:'absolute', opacity:options.borderOpacity}).addClass(cssClass(type));
534
+ $img_holder.append(jq);
535
+ return jq;
536
+ }
537
+
538
+ function dragDiv(ord, zi) {
539
+ var jq = $('<div />').mousedown(createDragger(ord)).css({cursor:ord + '-resize', position:'absolute', zIndex:zi});
540
+ if (Touch.support) {
541
+ jq.bind('touchstart', Touch.createDragger(ord));
542
+ }
543
+ $hdl_holder.append(jq);
544
+ return jq;
545
+ }
546
+
547
+ function insertHandle(ord) {
548
+ return dragDiv(ord, hdep++).css({top:px(-hhs + 1), left:px(-hhs + 1), opacity:options.handleOpacity}).addClass(cssClass('handle'));
549
+ }
550
+
551
+ function insertDragbar(ord) {
552
+ var s = options.handleSize, h = s, w = s, t = hhs, l = hhs;
553
+ switch (ord) {
554
+ case'n':
555
+ case's':
556
+ w = pct(100);
557
+ break;
558
+ case'e':
559
+ case'w':
560
+ h = pct(100);
561
+ break;
562
+ }
563
+ return dragDiv(ord, hdep++).width(w).height(h).css({top:px(-t + 1), left:px(-l + 1)});
564
+ }
565
+
566
+ function createHandles(li) {
567
+ var i;
568
+ for (i = 0; i < li.length; i++) {
569
+ handle[li[i]] = insertHandle(li[i]);
570
+ }
571
+ }
572
+
573
+ function moveHandles(c) {
574
+ var midvert = Math.round((c.h / 2) - hhs), midhoriz = Math.round((c.w / 2) - hhs), north = -hhs + 1, west = -hhs + 1, east = c.w - hhs, south = c.h - hhs, x, y;
575
+ if (handle.e) {
576
+ handle.e.css({top:px(midvert), left:px(east)});
577
+ handle.w.css({top:px(midvert)});
578
+ handle.s.css({top:px(south), left:px(midhoriz)});
579
+ handle.n.css({left:px(midhoriz)});
580
+ }
581
+ if (handle.ne) {
582
+ handle.ne.css({left:px(east)});
583
+ handle.se.css({top:px(south), left:px(east)});
584
+ handle.sw.css({top:px(south)});
585
+ }
586
+ if (handle.b) {
587
+ handle.b.css({top:px(south)});
588
+ handle.r.css({left:px(east)});
589
+ }
590
+ }
591
+
592
+ function moveto(x, y) {
593
+ $img2.css({top:px(-y), left:px(-x)});
594
+ $sel.css({top:px(y), left:px(x)});
595
+ }
596
+
597
+ function resize(w, h) {
598
+ $sel.width(w).height(h);
599
+ }
600
+
601
+ function refresh() {
602
+ var c = Coords.getFixed();
603
+ Coords.setPressed([c.x, c.y]);
604
+ Coords.setCurrent([c.x2, c.y2]);
605
+ updateVisible();
606
+ }
607
+
608
+ function updateVisible() {
609
+ if (awake) {
610
+ return update();
611
+ }
612
+ }
613
+
614
+ function update() {
615
+ var c = Coords.getFixed();
616
+ resize(c.w, c.h);
617
+ moveto(c.x, c.y);
618
+ if (seehandles) {
619
+ moveHandles(c);
620
+ }
621
+ if (!awake) {
622
+ show();
623
+ }
624
+ options.onChange.call(api, unscale(c));
625
+ }
626
+
627
+ function show() {
628
+ $sel.show();
629
+ if (options.bgFade) {
630
+ $img.fadeTo(options.fadeTime, bgopacity);
631
+ } else {
632
+ $img.css('opacity', bgopacity);
633
+ }
634
+ awake = true;
635
+ }
636
+
637
+ function release() {
638
+ disableHandles();
639
+ $sel.hide();
640
+ if (options.bgFade) {
641
+ $img.fadeTo(options.fadeTime, 1);
642
+ } else {
643
+ $img.css('opacity', 1);
644
+ }
645
+ awake = false;
646
+ options.onRelease.call(api);
647
+ }
648
+
649
+ function showHandles() {
650
+ if (seehandles) {
651
+ moveHandles(Coords.getFixed());
652
+ $hdl_holder.show();
653
+ }
654
+ }
655
+
656
+ function enableHandles() {
657
+ seehandles = true;
658
+ if (options.allowResize) {
659
+ moveHandles(Coords.getFixed());
660
+ $hdl_holder.show();
661
+ return true;
662
+ }
663
+ }
664
+
665
+ function disableHandles() {
666
+ seehandles = false;
667
+ $hdl_holder.hide();
668
+ }
669
+
670
+ function animMode(v) {
671
+ if (animating === v) {
672
+ disableHandles();
673
+ } else {
674
+ enableHandles();
675
+ }
676
+ }
677
+
678
+ function done() {
679
+ animMode(false);
680
+ refresh();
681
+ }
682
+
683
+ if (options.drawBorders) {
684
+ borders = {top:insertBorder('hline'), bottom:insertBorder('hline bottom'), left:insertBorder('vline'), right:insertBorder('vline right')};
685
+ }
686
+ if (options.dragEdges) {
687
+ handle.t = insertDragbar('n');
688
+ handle.b = insertDragbar('s');
689
+ handle.r = insertDragbar('e');
690
+ handle.l = insertDragbar('w');
691
+ }
692
+ if (options.sideHandles) {
693
+ createHandles(['n', 's', 'e', 'w']);
694
+ }
695
+ if (options.cornerHandles) {
696
+ createHandles(['sw', 'nw', 'ne', 'se']);
697
+ }
698
+ var $track = newTracker().mousedown(createDragger('move')).css({cursor:'move', position:'absolute', zIndex:360});
699
+ if (Touch.support) {
700
+ $track.bind('touchstart.jcrop', Touch.createDragger('move'));
701
+ }
702
+ $img_holder.append($track);
703
+ disableHandles();
704
+ return{updateVisible:updateVisible, update:update, release:release, refresh:refresh, isAwake:function () {
705
+ return awake;
706
+ }, setCursor:function (cursor) {
707
+ $track.css('cursor', cursor);
708
+ }, enableHandles:enableHandles, enableOnly:function () {
709
+ seehandles = true;
710
+ }, showHandles:showHandles, disableHandles:disableHandles, animMode:animMode, done:done};
711
+ }());
712
+ var Tracker = (function () {
713
+ var onMove = function () {
714
+ }, onDone = function () {
715
+ }, trackDoc = options.trackDocument;
716
+
717
+ function toFront() {
718
+ $trk.css({zIndex:450});
719
+ if (trackDoc) {
720
+ $(document).bind('mousemove', trackMove).bind('mouseup', trackUp);
721
+ }
722
+ }
723
+
724
+ function toBack() {
725
+ $trk.css({zIndex:290});
726
+ if (trackDoc) {
727
+ $(document).unbind('mousemove', trackMove).unbind('mouseup', trackUp);
728
+ }
729
+ }
730
+
731
+ function trackMove(e) {
732
+ onMove(mouseAbs(e));
733
+ return false;
734
+ }
735
+
736
+ function trackUp(e) {
737
+ e.preventDefault();
738
+ e.stopPropagation();
739
+ if (btndown) {
740
+ btndown = false;
741
+ onDone(mouseAbs(e));
742
+ if (Selection.isAwake()) {
743
+ options.onSelect.call(api, unscale(Coords.getFixed()));
744
+ }
745
+ toBack();
746
+ onMove = function () {
747
+ };
748
+ onDone = function () {
749
+ };
750
+ }
751
+ return false;
752
+ }
753
+
754
+ function activateHandlers(move, done) {
755
+ btndown = true;
756
+ onMove = move;
757
+ onDone = done;
758
+ toFront();
759
+ return false;
760
+ }
761
+
762
+ function trackTouchMove(e) {
763
+ e.pageX = e.originalEvent.changedTouches[0].pageX;
764
+ e.pageY = e.originalEvent.changedTouches[0].pageY;
765
+ return trackMove(e);
766
+ }
767
+
768
+ function trackTouchEnd(e) {
769
+ e.pageX = e.originalEvent.changedTouches[0].pageX;
770
+ e.pageY = e.originalEvent.changedTouches[0].pageY;
771
+ return trackUp(e);
772
+ }
773
+
774
+ function setCursor(t) {
775
+ $trk.css('cursor', t);
776
+ }
777
+
778
+ if (Touch.support) {
779
+ $(document).bind('touchmove', trackTouchMove).bind('touchend', trackTouchEnd);
780
+ }
781
+ if (!trackDoc) {
782
+ $trk.mousemove(trackMove).mouseup(trackUp).mouseout(trackUp);
783
+ }
784
+ $img.before($trk);
785
+ return{activateHandlers:activateHandlers, setCursor:setCursor};
786
+ }());
787
+ var KeyManager = (function () {
788
+ var $keymgr = $('<input type="radio" />').css({position:'fixed', left:'-120px', width:'12px'}), $keywrap = $('<div />').css({position:'absolute', overflow:'hidden'}).append($keymgr);
789
+
790
+ function watchKeys() {
791
+ if (options.keySupport) {
792
+ $keymgr.show();
793
+ // $keymgr.focus();
794
+ }
795
+ }
796
+
797
+ function onBlur(e) {
798
+ $keymgr.hide();
799
+ }
800
+
801
+ function doNudge(e, x, y) {
802
+ if (options.allowMove) {
803
+ Coords.moveOffset([x, y]);
804
+ Selection.updateVisible();
805
+ }
806
+ e.preventDefault();
807
+ e.stopPropagation();
808
+ }
809
+
810
+ function parseKey(e) {
811
+ if (e.ctrlKey) {
812
+ return true;
813
+ }
814
+ shift_down = e.shiftKey ? true : false;
815
+ var nudge = shift_down ? 10 : 1;
816
+ switch (e.keyCode) {
817
+ case 37:
818
+ doNudge(e, -nudge, 0);
819
+ break;
820
+ case 39:
821
+ doNudge(e, nudge, 0);
822
+ break;
823
+ case 38:
824
+ doNudge(e, 0, -nudge);
825
+ break;
826
+ case 40:
827
+ doNudge(e, 0, nudge);
828
+ break;
829
+ case 27:
830
+ Selection.release();
831
+ break;
832
+ case 9:
833
+ return true;
834
+ }
835
+ return false;
836
+ }
837
+
838
+ if (options.keySupport) {
839
+ $keymgr.keydown(parseKey).blur(onBlur);
840
+ if (ie6mode || !options.fixedSupport) {
841
+ $keymgr.css({position:'absolute', left:'-20px'});
842
+ $keywrap.append($keymgr).insertBefore($img);
843
+ } else {
844
+ $keymgr.insertBefore($img);
845
+ }
846
+ }
847
+ return{watchKeys:watchKeys};
848
+ }());
849
+
850
+ function setClass(cname) {
851
+ $div.removeClass().addClass(cssClass('holder')).addClass(cname);
852
+ }
853
+
854
+ function animateTo(a, callback) {
855
+ var x1 = parseInt(a[0], 10) / xscale, y1 = parseInt(a[1], 10) / yscale, x2 = parseInt(a[2], 10) / xscale, y2 = parseInt(a[3], 10) / yscale;
856
+ if (animating) {
857
+ return;
858
+ }
859
+ var animto = Coords.flipCoords(x1, y1, x2, y2), c = Coords.getFixed(), initcr = [c.x, c.y, c.x2, c.y2], animat = initcr, interv = options.animationDelay, ix1 = animto[0] - initcr[0], iy1 = animto[1] - initcr[1], ix2 = animto[2] - initcr[2], iy2 = animto[3] - initcr[3], pcent = 0, velocity = options.swingSpeed;
860
+ x = animat[0];
861
+ y = animat[1];
862
+ x2 = animat[2];
863
+ y2 = animat[3];
864
+ Selection.animMode(true);
865
+ var anim_timer;
866
+
867
+ function queueAnimator() {
868
+ window.setTimeout(animator, interv);
869
+ }
870
+
871
+ var animator = (function () {
872
+ return function () {
873
+ pcent += (100 - pcent) / velocity;
874
+ animat[0] = x + ((pcent / 100) * ix1);
875
+ animat[1] = y + ((pcent / 100) * iy1);
876
+ animat[2] = x2 + ((pcent / 100) * ix2);
877
+ animat[3] = y2 + ((pcent / 100) * iy2);
878
+ if (pcent >= 99.8) {
879
+ pcent = 100;
880
+ }
881
+ if (pcent < 100) {
882
+ setSelectRaw(animat);
883
+ queueAnimator();
884
+ } else {
885
+ Selection.done();
886
+ if (typeof(callback) === 'function') {
887
+ callback.call(api);
888
+ }
889
+ }
890
+ };
891
+ }());
892
+ queueAnimator();
893
+ }
894
+
895
+ function setSelect(rect) {
896
+ setSelectRaw([parseInt(rect[0], 10) / xscale, parseInt(rect[1], 10) / yscale, parseInt(rect[2], 10) / xscale, parseInt(rect[3], 10) / yscale]);
897
+ }
898
+
899
+ function setSelectRaw(l) {
900
+ Coords.setPressed([l[0], l[1]]);
901
+ Coords.setCurrent([l[2], l[3]]);
902
+ Selection.update();
903
+ }
904
+
905
+ function tellSelect() {
906
+ return unscale(Coords.getFixed());
907
+ }
908
+
909
+ function tellScaled() {
910
+ return Coords.getFixed();
911
+ }
912
+
913
+ function setOptionsNew(opt) {
914
+ setOptions(opt);
915
+ interfaceUpdate();
916
+ }
917
+
918
+ function disableCrop() {
919
+ options.disabled = true;
920
+ Selection.disableHandles();
921
+ Selection.setCursor('default');
922
+ Tracker.setCursor('default');
923
+ }
924
+
925
+ function enableCrop() {
926
+ options.disabled = false;
927
+ interfaceUpdate();
928
+ }
929
+
930
+ function cancelCrop() {
931
+ Selection.done();
932
+ Tracker.activateHandlers(null, null);
933
+ }
934
+
935
+ function destroy() {
936
+ $div.remove();
937
+ $origimg.show();
938
+ $(obj).removeData('Jcrop');
939
+ }
940
+
941
+ function setImage(src, callback) {
942
+ Selection.release();
943
+ disableCrop();
944
+ var img = new Image();
945
+ img.onload = function () {
946
+ var iw = img.width;
947
+ var ih = img.height;
948
+ var bw = options.boxWidth;
949
+ var bh = options.boxHeight;
950
+ $img.width(iw).height(ih);
951
+ $img.attr('src', src);
952
+ $img2.attr('src', src);
953
+ presize($img, bw, bh);
954
+ boundx = $img.width();
955
+ boundy = $img.height();
956
+ $img2.width(boundx).height(boundy);
957
+ $trk.width(boundx + (bound * 2)).height(boundy + (bound * 2));
958
+ $div.width(boundx).height(boundy);
959
+ enableCrop();
960
+ if (typeof(callback) === 'function') {
961
+ callback.call(api);
962
+ }
963
+ };
964
+ img.src = src;
965
+ }
966
+
967
+ function interfaceUpdate(alt) {
968
+ if (options.allowResize) {
969
+ if (alt) {
970
+ Selection.enableOnly();
971
+ } else {
972
+ Selection.enableHandles();
973
+ }
974
+ } else {
975
+ Selection.disableHandles();
976
+ }
977
+ Tracker.setCursor(options.allowSelect ? 'crosshair' : 'default');
978
+ Selection.setCursor(options.allowMove ? 'move' : 'default');
979
+ if (options.hasOwnProperty('setSelect')) {
980
+ setSelect(options.setSelect);
981
+ Selection.done();
982
+ delete(options.setSelect);
983
+ }
984
+ if (options.hasOwnProperty('trueSize')) {
985
+ xscale = options.trueSize[0] / boundx;
986
+ yscale = options.trueSize[1] / boundy;
987
+ }
988
+ if (options.hasOwnProperty('bgColor')) {
989
+ if (supportsColorFade() && options.fadeTime) {
990
+ $div.animate({backgroundColor:options.bgColor}, {queue:false, duration:options.fadeTime});
991
+ } else {
992
+ $div.css('backgroundColor', options.bgColor);
993
+ }
994
+ delete(options.bgColor);
995
+ }
996
+ if (options.hasOwnProperty('bgOpacity')) {
997
+ bgopacity = options.bgOpacity;
998
+ if (Selection.isAwake()) {
999
+ if (options.fadeTime) {
1000
+ $img.fadeTo(options.fadeTime, bgopacity);
1001
+ } else {
1002
+ $div.css('opacity', options.opacity);
1003
+ }
1004
+ }
1005
+ delete(options.bgOpacity);
1006
+ }
1007
+ xlimit = options.maxSize[0] || 0;
1008
+ ylimit = options.maxSize[1] || 0;
1009
+ xmin = options.minSize[0] || 0;
1010
+ ymin = options.minSize[1] || 0;
1011
+ if (options.hasOwnProperty('outerImage')) {
1012
+ $img.attr('src', options.outerImage);
1013
+ delete(options.outerImage);
1014
+ }
1015
+ Selection.refresh();
1016
+ }
1017
+
1018
+ if (Touch.support) {
1019
+ $trk.bind('touchstart', Touch.newSelection);
1020
+ }
1021
+ $hdl_holder.hide();
1022
+ interfaceUpdate(true);
1023
+ var api = {setImage:setImage, animateTo:animateTo, setSelect:setSelect, setOptions:setOptionsNew, tellSelect:tellSelect, tellScaled:tellScaled, setClass:setClass, disable:disableCrop, enable:enableCrop, cancel:cancelCrop, release:Selection.release, destroy:destroy, focus:KeyManager.watchKeys, getBounds:function () {
1024
+ return[boundx * xscale, boundy * yscale];
1025
+ }, getWidgetSize:function () {
1026
+ return[boundx, boundy];
1027
+ }, getScaleFactor:function () {
1028
+ return[xscale, yscale];
1029
+ }, ui:{holder:$div, selection:$sel}};
1030
+ if ($.browser.msie) {
1031
+ $div.bind('selectstart', function () {
1032
+ return false;
1033
+ });
1034
+ }
1035
+ $origimg.data('Jcrop', api);
1036
+ return api;
1037
+ };
1038
+ $.fn.Jcrop = function (options, callback) {
1039
+ function attachWhenDone(from) {
1040
+ var opt = (typeof(options) === 'object') ? options : {};
1041
+ var loadsrc = opt.useImg || from.src;
1042
+ var img = new Image();
1043
+ img.onload = function () {
1044
+ function attachJcrop() {
1045
+ var api = $.Jcrop(from, opt);
1046
+ if (typeof(callback) === 'function') {
1047
+ callback.call(api);
1048
+ }
1049
+ }
1050
+
1051
+ function attachAttempt() {
1052
+ if (!img.width || !img.height) {
1053
+ window.setTimeout(attachAttempt, 50);
1054
+ } else {
1055
+ attachJcrop();
1056
+ }
1057
+ }
1058
+
1059
+ window.setTimeout(attachAttempt, 50);
1060
+ };
1061
+ img.src = loadsrc;
1062
+ }
1063
+
1064
+ this.each(function () {
1065
+ if ($(this).data('Jcrop')) {
1066
+ if (options === 'api') {
1067
+ return $(this).data('Jcrop');
1068
+ }
1069
+ else {
1070
+ $(this).data('Jcrop').setOptions(options);
1071
+ }
1072
+ }
1073
+ else {
1074
+ attachWhenDone(this);
1075
+ }
1076
+ });
1077
+ return this;
1078
+ };
1079
+ $.Jcrop.defaults = {allowSelect:true, allowMove:true, allowResize:true, trackDocument:true, baseClass:'jcrop', addClass:null, bgColor:'black', bgOpacity:0.6, bgFade:false, borderOpacity:0.4, handleOpacity:0.5, handleSize:9, handleOffset:5, aspectRatio:0, keySupport:true, cornerHandles:true, sideHandles:true, drawBorders:true, dragEdges:true, fixedSupport:true, touchSupport:null, boxWidth:0, boxHeight:0, boundary:2, fadeTime:400, animationDelay:20, swingSpeed:3, minSelect:[0, 0], maxSize:[0, 0], minSize:[0, 0], onChange:function () {
1080
+ }, onSelect:function () {
1081
+ }, onRelease:function () {
1082
+ }};
1083
+ }(jQuery));