alchemy_cms 5.2.5 → 6.0.0.b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (270) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +6 -14
  3. data/.gitignore +0 -1
  4. data/.hound.yml +1 -1
  5. data/.rubocop.yml +46 -4
  6. data/CHANGELOG.md +80 -29
  7. data/Gemfile +4 -2
  8. data/README.md +5 -2
  9. data/alchemy_cms.gemspec +78 -65
  10. data/app/assets/javascripts/alchemy/admin.js +0 -2
  11. data/app/assets/javascripts/alchemy/alchemy.base.js.coffee +0 -27
  12. data/app/assets/javascripts/alchemy/alchemy.confirm_dialog.js.coffee +2 -1
  13. data/app/assets/javascripts/alchemy/alchemy.dialog.js.coffee +1 -1
  14. data/app/assets/javascripts/alchemy/alchemy.dragndrop.js.coffee +0 -25
  15. data/app/assets/javascripts/alchemy/alchemy.element_editors.js.coffee +1 -1
  16. data/app/assets/javascripts/alchemy/alchemy.elements_window.js.coffee +2 -0
  17. data/app/assets/javascripts/alchemy/alchemy.fixed_elements.js +1 -1
  18. data/app/assets/javascripts/alchemy/alchemy.gui.js.coffee +3 -1
  19. data/app/assets/javascripts/alchemy/alchemy.image_overlay.coffee +1 -1
  20. data/app/assets/javascripts/alchemy/alchemy.link_dialog.js.coffee +40 -27
  21. data/app/assets/javascripts/alchemy/templates/node_folder.hbs +1 -1
  22. data/app/assets/stylesheets/alchemy/admin.scss +1 -1
  23. data/app/assets/stylesheets/alchemy/archive.scss +4 -4
  24. data/app/assets/stylesheets/alchemy/buttons.scss +0 -4
  25. data/app/assets/stylesheets/alchemy/elements.scss +73 -61
  26. data/app/assets/stylesheets/alchemy/images.scss +8 -0
  27. data/app/assets/stylesheets/alchemy/node-select.scss +4 -3
  28. data/app/assets/stylesheets/alchemy/page-select.scss +1 -0
  29. data/app/assets/stylesheets/tinymce/skins/alchemy/content.min.css.scss +3 -3
  30. data/app/assets/stylesheets/tinymce/skins/alchemy/skin.min.css.scss +7 -7
  31. data/app/controllers/alchemy/admin/attachments_controller.rb +6 -2
  32. data/app/controllers/alchemy/admin/base_controller.rb +5 -7
  33. data/app/controllers/alchemy/admin/elements_controller.rb +58 -34
  34. data/app/controllers/alchemy/admin/essence_audios_controller.rb +30 -0
  35. data/app/controllers/alchemy/admin/essence_files_controller.rb +0 -14
  36. data/app/controllers/alchemy/admin/essence_pictures_controller.rb +8 -79
  37. data/app/controllers/alchemy/admin/essence_videos_controller.rb +33 -0
  38. data/app/controllers/alchemy/admin/ingredients_controller.rb +30 -0
  39. data/app/controllers/alchemy/admin/layoutpages_controller.rb +0 -1
  40. data/app/controllers/alchemy/admin/pages_controller.rb +6 -13
  41. data/app/controllers/alchemy/admin/pictures_controller.rb +35 -9
  42. data/app/controllers/alchemy/api/elements_controller.rb +10 -5
  43. data/app/controllers/alchemy/api/pages_controller.rb +2 -4
  44. data/app/controllers/concerns/alchemy/admin/archive_overlay.rb +13 -3
  45. data/app/controllers/concerns/alchemy/admin/crop_action.rb +26 -0
  46. data/app/decorators/alchemy/element_editor.rb +23 -1
  47. data/app/decorators/alchemy/ingredient_editor.rb +154 -0
  48. data/app/helpers/alchemy/admin/elements_helper.rb +1 -0
  49. data/app/helpers/alchemy/admin/essences_helper.rb +1 -1
  50. data/app/helpers/alchemy/admin/ingredients_helper.rb +42 -0
  51. data/app/helpers/alchemy/elements_block_helper.rb +22 -7
  52. data/app/helpers/alchemy/elements_helper.rb +12 -5
  53. data/app/helpers/alchemy/pages_helper.rb +3 -11
  54. data/app/jobs/alchemy/base_job.rb +11 -0
  55. data/app/jobs/alchemy/publish_page_job.rb +11 -0
  56. data/app/models/alchemy/attachment.rb +1 -1
  57. data/app/models/alchemy/content/factory.rb +23 -27
  58. data/app/models/alchemy/content.rb +1 -6
  59. data/app/models/alchemy/element/definitions.rb +29 -27
  60. data/app/models/alchemy/element/element_contents.rb +131 -122
  61. data/app/models/alchemy/element/element_essences.rb +100 -98
  62. data/app/models/alchemy/element/element_ingredients.rb +176 -0
  63. data/app/models/alchemy/element/presenters.rb +89 -87
  64. data/app/models/alchemy/element.rb +40 -73
  65. data/app/models/alchemy/elements_repository.rb +126 -0
  66. data/app/models/alchemy/essence_audio.rb +12 -0
  67. data/app/models/alchemy/essence_headline.rb +40 -0
  68. data/app/models/alchemy/essence_picture.rb +4 -116
  69. data/app/models/alchemy/essence_richtext.rb +12 -0
  70. data/app/models/alchemy/essence_video.rb +12 -0
  71. data/app/models/alchemy/image_cropper_settings.rb +87 -0
  72. data/app/models/alchemy/ingredient.rb +219 -0
  73. data/app/models/alchemy/ingredient_validator.rb +97 -0
  74. data/app/models/alchemy/ingredients/audio.rb +29 -0
  75. data/app/models/alchemy/ingredients/boolean.rb +21 -0
  76. data/app/models/alchemy/ingredients/datetime.rb +20 -0
  77. data/app/models/alchemy/ingredients/file.rb +30 -0
  78. data/app/models/alchemy/ingredients/headline.rb +42 -0
  79. data/app/models/alchemy/ingredients/html.rb +19 -0
  80. data/app/models/alchemy/ingredients/link.rb +16 -0
  81. data/app/models/alchemy/ingredients/node.rb +23 -0
  82. data/app/models/alchemy/ingredients/page.rb +23 -0
  83. data/app/models/alchemy/ingredients/picture.rb +41 -0
  84. data/app/models/alchemy/ingredients/richtext.rb +57 -0
  85. data/app/models/alchemy/ingredients/select.rb +10 -0
  86. data/app/models/alchemy/ingredients/text.rb +17 -0
  87. data/app/models/alchemy/ingredients/video.rb +33 -0
  88. data/app/models/alchemy/language.rb +0 -11
  89. data/app/models/alchemy/node.rb +1 -1
  90. data/app/models/alchemy/page/fixed_attributes.rb +53 -51
  91. data/app/models/alchemy/page/page_elements.rb +186 -205
  92. data/app/models/alchemy/page/page_naming.rb +66 -64
  93. data/app/models/alchemy/page/page_natures.rb +139 -142
  94. data/app/models/alchemy/page/page_scopes.rb +113 -102
  95. data/app/models/alchemy/page/publisher.rb +50 -0
  96. data/app/models/alchemy/page/url_path.rb +1 -1
  97. data/app/models/alchemy/page.rb +67 -33
  98. data/app/models/alchemy/page_version.rb +58 -0
  99. data/app/models/alchemy/picture/calculations.rb +2 -8
  100. data/app/models/alchemy/picture/preprocessor.rb +2 -0
  101. data/app/models/alchemy/picture/transformations.rb +24 -96
  102. data/app/models/alchemy/picture.rb +4 -2
  103. data/app/models/concerns/alchemy/picture_thumbnails.rb +181 -0
  104. data/app/models/concerns/alchemy/touch_elements.rb +2 -2
  105. data/app/presenters/alchemy/picture_view.rb +88 -0
  106. data/app/serializers/alchemy/element_serializer.rb +5 -0
  107. data/app/serializers/alchemy/page_tree_serializer.rb +3 -2
  108. data/app/services/alchemy/delete_elements.rb +44 -0
  109. data/app/services/alchemy/duplicate_element.rb +56 -0
  110. data/app/views/alchemy/admin/attachments/_archive_overlay.html.erb +1 -2
  111. data/app/views/alchemy/admin/attachments/_file_to_assign.html.erb +3 -3
  112. data/app/views/alchemy/admin/attachments/assign.js.erb +11 -0
  113. data/app/views/alchemy/admin/crop.html.erb +36 -0
  114. data/app/views/alchemy/admin/elements/_element.html.erb +14 -10
  115. data/app/views/alchemy/admin/elements/{_element_footer.html.erb → _footer.html.erb} +0 -0
  116. data/app/views/alchemy/admin/elements/{_new_element_form.html.erb → _form.html.erb} +1 -1
  117. data/app/views/alchemy/admin/elements/{_element_header.html.erb → _header.html.erb} +1 -1
  118. data/app/views/alchemy/admin/elements/{_element_toolbar.html.erb → _toolbar.html.erb} +5 -6
  119. data/app/views/alchemy/admin/elements/{trash.js.erb → destroy.js.erb} +1 -3
  120. data/app/views/alchemy/admin/elements/new.html.erb +3 -3
  121. data/app/views/alchemy/admin/elements/order.js.erb +0 -17
  122. data/app/views/alchemy/admin/elements/update.js.erb +3 -2
  123. data/app/views/alchemy/admin/essence_audios/edit.html.erb +7 -0
  124. data/app/views/alchemy/admin/essence_pictures/update.js.erb +0 -1
  125. data/app/views/alchemy/admin/essence_videos/edit.html.erb +11 -0
  126. data/app/views/alchemy/admin/ingredients/_audio_fields.html.erb +4 -0
  127. data/app/views/alchemy/admin/ingredients/_file_fields.html.erb +18 -0
  128. data/app/views/alchemy/admin/ingredients/_picture_fields.html.erb +25 -0
  129. data/app/views/alchemy/admin/ingredients/_video_fields.html.erb +8 -0
  130. data/app/views/alchemy/admin/ingredients/edit.html.erb +4 -0
  131. data/app/views/alchemy/admin/layoutpages/edit.html.erb +0 -5
  132. data/app/views/alchemy/admin/nodes/_node.html.erb +2 -2
  133. data/app/views/alchemy/admin/pages/_anchor_link.html.erb +1 -1
  134. data/app/views/alchemy/admin/pages/_external_link.html.erb +1 -1
  135. data/app/views/alchemy/admin/pages/_file_link.html.erb +1 -1
  136. data/app/views/alchemy/admin/pages/_form.html.erb +0 -6
  137. data/app/views/alchemy/admin/pages/_internal_link.html.erb +1 -1
  138. data/app/views/alchemy/admin/pages/_tinymce_custom_config.html.erb +5 -2
  139. data/app/views/alchemy/admin/pages/edit.html.erb +36 -24
  140. data/app/views/alchemy/admin/partials/_remote_search_form.html.erb +2 -4
  141. data/app/views/alchemy/admin/partials/_routes.html.erb +7 -11
  142. data/app/views/alchemy/admin/pictures/_filter_and_size_bar.html.erb +4 -8
  143. data/app/views/alchemy/admin/pictures/_infos.html.erb +0 -1
  144. data/app/views/alchemy/admin/pictures/_picture_to_assign.html.erb +4 -4
  145. data/app/views/alchemy/admin/pictures/assign.js.erb +10 -0
  146. data/app/views/alchemy/admin/resources/_form.html.erb +1 -0
  147. data/app/views/alchemy/essences/_essence_audio_editor.html.erb +4 -0
  148. data/app/views/alchemy/essences/_essence_audio_view.html.erb +15 -0
  149. data/app/views/alchemy/essences/_essence_file_editor.html.erb +15 -6
  150. data/app/views/alchemy/essences/_essence_headline_editor.html.erb +36 -0
  151. data/app/views/alchemy/essences/_essence_headline_view.html.erb +10 -0
  152. data/app/views/alchemy/essences/_essence_link_editor.html.erb +8 -4
  153. data/app/views/alchemy/essences/_essence_picture_editor.html.erb +27 -12
  154. data/app/views/alchemy/essences/_essence_text_editor.html.erb +12 -4
  155. data/app/views/alchemy/essences/_essence_video_editor.html.erb +4 -0
  156. data/app/views/alchemy/essences/_essence_video_view.html.erb +18 -0
  157. data/app/views/alchemy/essences/shared/_essence_picture_tools.html.erb +21 -16
  158. data/app/views/alchemy/essences/shared/_linkable_essence_tools.html.erb +2 -2
  159. data/app/views/alchemy/ingredients/_audio_editor.html.erb +5 -0
  160. data/app/views/alchemy/ingredients/_audio_view.html.erb +14 -0
  161. data/app/views/alchemy/ingredients/_boolean_editor.html.erb +11 -0
  162. data/app/views/alchemy/ingredients/_boolean_view.html.erb +1 -0
  163. data/app/views/alchemy/ingredients/_datetime_editor.html.erb +17 -0
  164. data/app/views/alchemy/ingredients/_datetime_view.html.erb +9 -0
  165. data/app/views/alchemy/ingredients/_file_editor.html.erb +50 -0
  166. data/app/views/alchemy/ingredients/_file_view.html.erb +17 -0
  167. data/app/views/alchemy/ingredients/_headline_editor.html.erb +30 -0
  168. data/app/views/alchemy/ingredients/_headline_view.html.erb +9 -0
  169. data/app/views/alchemy/ingredients/_html_editor.html.erb +8 -0
  170. data/app/views/alchemy/ingredients/_html_view.html.erb +1 -0
  171. data/app/views/alchemy/ingredients/_link_editor.html.erb +24 -0
  172. data/app/views/alchemy/ingredients/_link_view.html.erb +9 -0
  173. data/app/views/alchemy/ingredients/_node_editor.html.erb +25 -0
  174. data/app/views/alchemy/ingredients/_node_view.html.erb +1 -0
  175. data/app/views/alchemy/ingredients/_page_editor.html.erb +24 -0
  176. data/app/views/alchemy/ingredients/_page_view.html.erb +4 -0
  177. data/app/views/alchemy/ingredients/_picture_editor.html.erb +59 -0
  178. data/app/views/alchemy/ingredients/_picture_view.html.erb +5 -0
  179. data/app/views/alchemy/ingredients/_richtext_editor.html.erb +12 -0
  180. data/app/views/alchemy/ingredients/_richtext_view.html.erb +3 -0
  181. data/app/views/alchemy/ingredients/_select_editor.html.erb +29 -0
  182. data/app/views/alchemy/ingredients/_select_view.html.erb +1 -0
  183. data/app/views/alchemy/ingredients/_text_editor.html.erb +19 -0
  184. data/app/views/alchemy/ingredients/_text_view.html.erb +16 -0
  185. data/app/views/alchemy/ingredients/_video_editor.html.erb +5 -0
  186. data/app/views/alchemy/ingredients/_video_view.html.erb +17 -0
  187. data/app/views/alchemy/ingredients/shared/_link_tools.html.erb +20 -0
  188. data/app/views/alchemy/ingredients/shared/_picture_tools.html.erb +57 -0
  189. data/config/brakeman.ignore +66 -159
  190. data/config/initializers/dragonfly.rb +10 -0
  191. data/config/locales/alchemy.en.yml +23 -15
  192. data/config/routes.rb +17 -22
  193. data/db/migrate/20201207131309_create_page_versions.rb +19 -0
  194. data/db/migrate/20201207135820_add_page_version_id_to_alchemy_elements.rb +76 -0
  195. data/db/migrate/20210205143548_rename_public_on_and_public_until_on_alchemy_pages.rb +10 -0
  196. data/db/migrate/20210326105046_add_sanitized_body_to_alchemy_essence_richtexts.rb +7 -0
  197. data/db/migrate/20210406093436_add_alchemy_essence_headlines.rb +12 -0
  198. data/db/migrate/20210506135919_create_essence_audios.rb +19 -0
  199. data/db/migrate/20210506140258_create_essence_videos.rb +23 -0
  200. data/db/migrate/20210508091432_create_alchemy_ingredients.rb +22 -0
  201. data/lib/alchemy/admin/preview_url.rb +2 -0
  202. data/lib/alchemy/deprecation.rb +1 -1
  203. data/lib/alchemy/dragonfly/processors/auto_orient.rb +18 -0
  204. data/lib/alchemy/dragonfly/processors/crop_resize.rb +35 -0
  205. data/lib/alchemy/elements_finder.rb +14 -60
  206. data/lib/alchemy/engine.rb +1 -1
  207. data/lib/alchemy/essence.rb +1 -2
  208. data/lib/alchemy/hints.rb +8 -4
  209. data/lib/alchemy/page_layout.rb +0 -13
  210. data/lib/alchemy/permissions.rb +30 -29
  211. data/lib/alchemy/resource.rb +13 -3
  212. data/lib/alchemy/tasks/tidy.rb +29 -0
  213. data/lib/alchemy/test_support/essence_shared_examples.rb +0 -1
  214. data/lib/alchemy/test_support/factories/element_factory.rb +8 -8
  215. data/lib/alchemy/test_support/factories/essence_audio_factory.rb +7 -0
  216. data/lib/alchemy/test_support/factories/essence_video_factory.rb +7 -0
  217. data/lib/alchemy/test_support/factories/ingredient_factory.rb +25 -0
  218. data/lib/alchemy/test_support/factories/page_factory.rb +20 -1
  219. data/lib/alchemy/test_support/factories/page_version_factory.rb +23 -0
  220. data/lib/alchemy/test_support/having_crop_action_examples.rb +170 -0
  221. data/lib/alchemy/test_support/having_picture_thumbnails_examples.rb +646 -0
  222. data/lib/alchemy/test_support/shared_ingredient_editor_examples.rb +21 -0
  223. data/lib/alchemy/test_support/shared_ingredient_examples.rb +57 -0
  224. data/lib/alchemy/test_support.rb +2 -11
  225. data/lib/alchemy/tinymce.rb +17 -0
  226. data/lib/alchemy/upgrader/five_point_zero.rb +0 -32
  227. data/lib/alchemy/upgrader/six_point_zero.rb +21 -0
  228. data/lib/alchemy/upgrader/tasks/add_page_versions.rb +33 -0
  229. data/lib/alchemy/upgrader/tasks/ingredients_migrator.rb +51 -0
  230. data/lib/alchemy/version.rb +1 -1
  231. data/lib/generators/alchemy/elements/elements_generator.rb +1 -0
  232. data/lib/generators/alchemy/elements/templates/view.html.erb +9 -0
  233. data/lib/generators/alchemy/elements/templates/view.html.haml +9 -0
  234. data/lib/generators/alchemy/elements/templates/view.html.slim +9 -0
  235. data/lib/generators/alchemy/ingredient/ingredient_generator.rb +38 -0
  236. data/lib/generators/alchemy/ingredient/templates/editor.html.erb +14 -0
  237. data/lib/generators/alchemy/ingredient/templates/model.rb.tt +13 -0
  238. data/lib/generators/alchemy/ingredient/templates/view.html.erb +1 -0
  239. data/lib/generators/alchemy/install/install_generator.rb +1 -2
  240. data/lib/generators/alchemy/install/templates/dragonfly.rb.tt +1 -1
  241. data/lib/generators/alchemy/menus/templates/node.html.erb +1 -1
  242. data/lib/generators/alchemy/menus/templates/node.html.haml +1 -1
  243. data/lib/generators/alchemy/menus/templates/node.html.slim +1 -1
  244. data/lib/generators/alchemy/menus/templates/wrapper.html.erb +1 -1
  245. data/lib/generators/alchemy/menus/templates/wrapper.html.haml +1 -1
  246. data/lib/generators/alchemy/menus/templates/wrapper.html.slim +1 -1
  247. data/lib/tasks/alchemy/tidy.rake +12 -0
  248. data/lib/tasks/alchemy/upgrade.rake +21 -15
  249. data/package/admin.js +9 -1
  250. data/package/src/file_editors.js +28 -0
  251. data/package/src/image_cropper.js +103 -0
  252. data/package/src/image_loader.js +58 -0
  253. data/package/src/node_tree.js +5 -5
  254. data/package/src/picture_editors.js +169 -0
  255. data/package/src/utils/__tests__/ajax.spec.js +20 -12
  256. data/package/src/utils/ajax.js +8 -3
  257. data/package.json +3 -2
  258. data/vendor/assets/javascripts/jquery_plugins/jquery.Jcrop.min.js +3 -18
  259. data/vendor/assets/stylesheets/jquery.Jcrop.min.scss +2 -28
  260. metadata +285 -56
  261. data/app/assets/javascripts/alchemy/alchemy.image_cropper.js.coffee +0 -44
  262. data/app/assets/javascripts/alchemy/alchemy.trash_window.js.coffee +0 -30
  263. data/app/assets/stylesheets/alchemy/trash.scss +0 -8
  264. data/app/controllers/alchemy/admin/trash_controller.rb +0 -44
  265. data/app/views/alchemy/admin/essence_files/assign.js.erb +0 -3
  266. data/app/views/alchemy/admin/essence_pictures/assign.js.erb +0 -4
  267. data/app/views/alchemy/admin/essence_pictures/crop.html.erb +0 -48
  268. data/app/views/alchemy/admin/trash/clear.js.erb +0 -4
  269. data/app/views/alchemy/admin/trash/index.html.erb +0 -31
  270. data/lib/alchemy/test_support/factories.rb +0 -20
@@ -0,0 +1,58 @@
1
+ // Shows spinner while loading images and
2
+ // fades the image after its been loaded
3
+
4
+ const DEFAULT_SPINNER_OPTIONS = { fill: "#fff" }
5
+
6
+ export default class ImageLoader {
7
+ static init(scope = document, spinnerOptions = DEFAULT_SPINNER_OPTIONS) {
8
+ if (typeof scope === "string") {
9
+ scope = document.querySelector(scope)
10
+ }
11
+ scope.querySelectorAll("img").forEach((image) => {
12
+ const loader = new ImageLoader(image, spinnerOptions)
13
+ loader.load()
14
+ })
15
+ }
16
+
17
+ constructor(image, spinnerOptions = DEFAULT_SPINNER_OPTIONS) {
18
+ this.image = image
19
+ this.parent = image.parentNode
20
+ this.spinner = new Alchemy.Spinner("small", spinnerOptions)
21
+ this.bind()
22
+ }
23
+
24
+ bind() {
25
+ this.image.addEventListener("load", this.onLoaded.bind(this))
26
+ this.image.addEventListener("error", this.onError.bind(this))
27
+ }
28
+
29
+ load(force = false) {
30
+ if (!force && this.image.complete) return
31
+
32
+ this.image.classList.add("loading")
33
+ this.spinner.spin(this.image.parentElement)
34
+ }
35
+
36
+ onLoaded() {
37
+ this.removeSpinner()
38
+ this.image.classList.remove("loading")
39
+ this.unbind()
40
+ }
41
+
42
+ onError() {
43
+ this.removeSpinner()
44
+ this.parent.innerHtml = '<span class="icon warn"></span>'
45
+ this.unbind()
46
+ }
47
+
48
+ unbind() {
49
+ this.image.removeEventListener("load", this.onLoaded)
50
+ this.image.removeEventListener("error", this.onError)
51
+ }
52
+
53
+ removeSpinner() {
54
+ this.parent.querySelectorAll(".spinner").forEach((spinner) => {
55
+ spinner.remove()
56
+ })
57
+ }
58
+ }
@@ -6,7 +6,7 @@ function displayNodeFolders() {
6
6
  document.querySelectorAll("li.menu-item").forEach((el) => {
7
7
  const leftIconArea = el.querySelector(".nodes_tree-left_images")
8
8
  const list = el.querySelector(".children")
9
- const node = { folded: el.dataset.folded === "true", id: el.dataset.id }
9
+ const node = { folded: el.dataset.folded === "true", id: el.dataset.id, type: el.dataset.type }
10
10
 
11
11
  if (list.children.length > 0 || node.folded) {
12
12
  leftIconArea.innerHTML = HandlebarsTemplates.node_folder({ node: node })
@@ -17,9 +17,9 @@ function displayNodeFolders() {
17
17
  }
18
18
 
19
19
  function onFinishDragging(evt) {
20
- const url = Alchemy.routes.move_api_node_path(evt.item.dataset.id)
20
+ const url = Alchemy.routes[evt.item.dataset.type].move_api_path(evt.item.dataset.id)
21
21
  const data = {
22
- target_parent_id: evt.to.dataset.nodeId,
22
+ target_parent_id: evt.to.dataset.recordId,
23
23
  new_position: evt.newIndex
24
24
  }
25
25
 
@@ -36,9 +36,9 @@ function onFinishDragging(evt) {
36
36
 
37
37
  function handleNodeFolders() {
38
38
  on("click", ".nodes_tree", ".node_folder", function () {
39
- const nodeId = this.dataset.nodeId
39
+ const nodeId = this.dataset.recordId
40
40
  const menu_item = this.closest("li.menu-item")
41
- const url = Alchemy.routes.toggle_folded_api_node_path(nodeId)
41
+ const url = Alchemy.routes[this.dataset.recordType].toggle_folded_api_path(nodeId)
42
42
  const list = menu_item.querySelector(".children")
43
43
 
44
44
  ajax("PATCH", url)
@@ -0,0 +1,169 @@
1
+ import debounce from "lodash/debounce"
2
+ import max from "lodash/max"
3
+ import ajax from "./utils/ajax"
4
+ import ImageLoader from "./image_loader"
5
+
6
+ const UPDATE_DELAY = 125
7
+ const IMAGE_PLACEHOLDER = '<i class="icon far fa-image fa-fw"></i>'
8
+ const EMPTY_IMAGE = '<img src="" class="img_paddingtop" />'
9
+ const THUMBNAIL_SIZE = "160x120"
10
+
11
+ class PictureEditor {
12
+ constructor(container) {
13
+ this.container = container
14
+ this.cropFromField = container.querySelector("[data-crop-from]")
15
+ this.cropSizeField = container.querySelector("[data-crop-size]")
16
+ this.pictureIdField = container.querySelector("[data-picture-id]")
17
+ this.targetSizeField = container.querySelector("[data-target-size]")
18
+ this.imageCropperField = container.querySelector("[data-image-cropper]")
19
+ this.image = container.querySelector("img")
20
+ this.thumbnailBackground = container.querySelector(".thumbnail_background")
21
+ this.deleteButton = container.querySelector(".picture_tool.delete")
22
+ this.cropLink = container.querySelector(".crop_link")
23
+
24
+ this.targetSize = this.targetSizeField.dataset.targetSize
25
+ this.pictureId = this.pictureIdField.value
26
+
27
+ if (this.image) {
28
+ this.imageLoader = new ImageLoader(this.image)
29
+ }
30
+
31
+ this.update = debounce(() => {
32
+ this.updateImage()
33
+ this.updateCropLink()
34
+ }, UPDATE_DELAY)
35
+
36
+ this.deleteButton.addEventListener("click", this.removeImage.bind(this))
37
+ }
38
+
39
+ observe() {
40
+ const observer = new MutationObserver(this.mutationCallback.bind(this))
41
+
42
+ observer.observe(this.cropFromField, { attributes: true })
43
+ observer.observe(this.cropSizeField, { attributes: true })
44
+ observer.observe(this.pictureIdField, { attributes: true })
45
+ }
46
+
47
+ mutationCallback(mutationsList) {
48
+ for (const mutation of mutationsList) {
49
+ if ("pictureId" in mutation.target.dataset) {
50
+ this.cropFromField.value = ""
51
+ this.cropSizeField.value = ""
52
+ this.pictureId = mutation.target.value
53
+ }
54
+ this.update()
55
+ }
56
+ }
57
+
58
+ updateImage() {
59
+ if (!this.pictureId) return
60
+
61
+ this.ensureImage()
62
+ this.image.removeAttribute("alt")
63
+ this.image.removeAttribute("src")
64
+ this.imageLoader.load(true)
65
+ ajax("GET", `/admin/pictures/${this.pictureId}/url`, {
66
+ crop: this.imageCropperEnabled,
67
+ crop_from: this.cropFrom,
68
+ crop_size: this.cropSize,
69
+ flatten: true,
70
+ size: THUMBNAIL_SIZE
71
+ })
72
+ .then(({ data }) => {
73
+ this.image.src = data.url
74
+ this.image.alt = data.alt
75
+ this.image.title = data.title
76
+ })
77
+ .catch((error) => {
78
+ console.error(error.message || error)
79
+ Alchemy.growl(error.message || error, "error")
80
+ })
81
+ }
82
+
83
+ ensureImage() {
84
+ if (this.image) return
85
+
86
+ this.thumbnailBackground.innerHTML = EMPTY_IMAGE
87
+ this.image = this.container.querySelector("img")
88
+ this.imageLoader = new ImageLoader(this.image)
89
+ }
90
+
91
+ removeImage() {
92
+ this.thumbnailBackground.innerHTML = IMAGE_PLACEHOLDER
93
+ this.pictureIdField.value = ""
94
+ this.image = null
95
+ this.cropLink.classList.add("disabled")
96
+ Alchemy.setElementDirty(this.container.closest(".element-editor"))
97
+ }
98
+
99
+ updateCropLink() {
100
+ if (!this.pictureId || !this.imageCropperEnabled) return
101
+
102
+ this.cropLink.classList.remove("disabled")
103
+
104
+ if (this.cropLink.href.match(/(picture_id=)\d+/)) {
105
+ this.cropLink.href = this.cropLink.href.replace(
106
+ /(picture_id=)\d+/,
107
+ "$1" + this.pictureId
108
+ )
109
+ } else {
110
+ this.cropLink.href = this.cropLink.href + `&picture_id=${this.pictureId}`
111
+ }
112
+ }
113
+
114
+ get cropFrom() {
115
+ if (this.cropFromField.value === "") {
116
+ return this.defaultCropFrom.join("x")
117
+ }
118
+ return this.cropFromField.value
119
+ }
120
+
121
+ get cropSize() {
122
+ if (this.cropSizeField.value === "") {
123
+ return this.defaultCropSize.join("x")
124
+ }
125
+ return this.cropSizeField.value
126
+ }
127
+
128
+ get defaultCropSize() {
129
+ if (!this.imageCropperEnabled) return []
130
+
131
+ const mask = this.targetSize.split("x").map((n) => parseInt(n))
132
+ const zoom = max([
133
+ mask[0] / this.imageFileWidth,
134
+ mask[1] / this.imageFileHeight
135
+ ])
136
+
137
+ return [Math.round(mask[0] / zoom), Math.round(mask[1] / zoom)]
138
+ }
139
+
140
+ get defaultCropFrom() {
141
+ if (!this.imageCropperEnabled) return []
142
+
143
+ const dimensions = this.defaultCropSize
144
+
145
+ return [
146
+ Math.round((this.imageFileWidth - dimensions[0]) / 2),
147
+ Math.round((this.imageFileHeight - dimensions[1]) / 2)
148
+ ]
149
+ }
150
+
151
+ get imageFileWidth() {
152
+ return parseInt(this.pictureIdField.dataset.imageFileWidth)
153
+ }
154
+
155
+ get imageFileHeight() {
156
+ return parseInt(this.pictureIdField.dataset.imageFileHeight)
157
+ }
158
+
159
+ get imageCropperEnabled() {
160
+ return this.targetSizeField.dataset.imageCropper === "true"
161
+ }
162
+ }
163
+
164
+ export default function init(selector) {
165
+ document.querySelectorAll(selector).forEach((node) => {
166
+ const thumbnail = new PictureEditor(node)
167
+ thumbnail.observe()
168
+ })
169
+ }
@@ -10,7 +10,7 @@ beforeEach(() => {
10
10
 
11
11
  describe("ajax('get')", () => {
12
12
  it("sends X-CSRF-TOKEN header", async () => {
13
- xhrMock.get("/users", (req, res) => {
13
+ xhrMock.get("http://localhost/users", (req, res) => {
14
14
  expect(req.header("X-CSRF-TOKEN")).toEqual(token)
15
15
  return res.status(200).body('{"message":"Ok"}')
16
16
  })
@@ -18,7 +18,7 @@ describe("ajax('get')", () => {
18
18
  })
19
19
 
20
20
  it("sends Content-Type header", async () => {
21
- xhrMock.get("/users", (req, res) => {
21
+ xhrMock.get("http://localhost/users", (req, res) => {
22
22
  expect(req.header("Content-Type")).toEqual(
23
23
  "application/json; charset=utf-8"
24
24
  )
@@ -28,7 +28,7 @@ describe("ajax('get')", () => {
28
28
  })
29
29
 
30
30
  it("sends Accept header", async () => {
31
- xhrMock.get("/users", (req, res) => {
31
+ xhrMock.get("http://localhost/users", (req, res) => {
32
32
  expect(req.header("Accept")).toEqual("application/json")
33
33
  return res.status(200).body('{"message":"Ok"}')
34
34
  })
@@ -36,7 +36,7 @@ describe("ajax('get')", () => {
36
36
  })
37
37
 
38
38
  it("returns JSON", async () => {
39
- xhrMock.get("/users", (_req, res) => {
39
+ xhrMock.get("http://localhost/users", (_req, res) => {
40
40
  return res.status(200).body('{"email":"mail@example.com"}')
41
41
  })
42
42
  await ajax("get", "/users").then((res) => {
@@ -45,7 +45,7 @@ describe("ajax('get')", () => {
45
45
  })
46
46
 
47
47
  it("JSON parse errors get rejected", async () => {
48
- xhrMock.get("/users", (_req, res) => {
48
+ xhrMock.get("http://localhost/users", (_req, res) => {
49
49
  return res.status(200).body('email => "mail@example.com"')
50
50
  })
51
51
  expect.assertions(1)
@@ -55,7 +55,7 @@ describe("ajax('get')", () => {
55
55
  })
56
56
 
57
57
  it("network errors get rejected", async () => {
58
- xhrMock.get("/users", () => {
58
+ xhrMock.get("http://localhost/users", () => {
59
59
  return Promise.reject(new Error())
60
60
  })
61
61
  expect.assertions(1)
@@ -65,7 +65,7 @@ describe("ajax('get')", () => {
65
65
  })
66
66
 
67
67
  it("server errors get rejected", async () => {
68
- xhrMock.get("/users", (_req, res) => {
68
+ xhrMock.get("http://localhost/users", (_req, res) => {
69
69
  return res.status(401).body('{"error":"Unauthorized"}')
70
70
  })
71
71
  expect.assertions(1)
@@ -75,7 +75,7 @@ describe("ajax('get')", () => {
75
75
  })
76
76
 
77
77
  it("server errors parsing errors get rejected", async () => {
78
- xhrMock.get("/users", (_req, res) => {
78
+ xhrMock.get("http://localhost/users", (_req, res) => {
79
79
  return res.status(401).body("Unauthorized")
80
80
  })
81
81
  expect.assertions(1)
@@ -83,11 +83,19 @@ describe("ajax('get')", () => {
83
83
  expect(e.message).toMatch("Unexpected token")
84
84
  })
85
85
  })
86
+
87
+ it("params get attached as query string", async () => {
88
+ xhrMock.get("http://localhost/users?name=foo", (_req, res) => {
89
+ return res.status(200).body(`{"name":"foo"}`)
90
+ })
91
+ const { data } = await ajax("get", "/users", { name: "foo" })
92
+ expect(data.name).toEqual("foo")
93
+ })
86
94
  })
87
95
 
88
96
  describe("ajax('post')", () => {
89
97
  it("sends X-CSRF-TOKEN header", async () => {
90
- xhrMock.post("/users", (req, res) => {
98
+ xhrMock.post("http://localhost/users", (req, res) => {
91
99
  expect(req.header("X-CSRF-TOKEN")).toEqual(token)
92
100
  return res.status(200).body('{"message":"Ok"}')
93
101
  })
@@ -95,7 +103,7 @@ describe("ajax('post')", () => {
95
103
  })
96
104
 
97
105
  it("sends Content-Type header", async () => {
98
- xhrMock.post("/users", (req, res) => {
106
+ xhrMock.post("http://localhost/users", (req, res) => {
99
107
  expect(req.header("Content-Type")).toEqual(
100
108
  "application/json; charset=utf-8"
101
109
  )
@@ -105,7 +113,7 @@ describe("ajax('post')", () => {
105
113
  })
106
114
 
107
115
  it("sends Accept header", async () => {
108
- xhrMock.post("/users", (req, res) => {
116
+ xhrMock.post("http://localhost/users", (req, res) => {
109
117
  expect(req.header("Accept")).toEqual("application/json")
110
118
  return res.status(200).body('{"message":"Ok"}')
111
119
  })
@@ -113,7 +121,7 @@ describe("ajax('post')", () => {
113
121
  })
114
122
 
115
123
  it("sends JSON data", async () => {
116
- xhrMock.post("/users", (req, res) => {
124
+ xhrMock.post("http://localhost/users", (req, res) => {
117
125
  expect(req.body()).toEqual('{"email":"mail@example.com"}')
118
126
  return res.status(200).body('{"message":"Ok"}')
119
127
  })
@@ -29,16 +29,21 @@ function getToken() {
29
29
  return metaTag.attributes.content.textContent
30
30
  }
31
31
 
32
- export default function ajax(method, url, data) {
32
+ export default function ajax(method, path, data) {
33
33
  const xhr = new XMLHttpRequest()
34
34
  const promise = buildPromise(xhr)
35
+ const url = new URL(window.location.origin + path)
35
36
 
36
- xhr.open(method, url)
37
+ if (data && method.toLowerCase() === "get") {
38
+ url.search = new URLSearchParams(data).toString()
39
+ }
40
+
41
+ xhr.open(method, url.toString())
37
42
  xhr.setRequestHeader("Content-type", "application/json; charset=utf-8")
38
43
  xhr.setRequestHeader("Accept", "application/json")
39
44
  xhr.setRequestHeader("X-CSRF-Token", getToken())
40
45
 
41
- if (data) {
46
+ if (data && method.toLowerCase() !== "get") {
42
47
  xhr.send(JSON.stringify(data))
43
48
  } else {
44
49
  xhr.send()
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alchemy_cms/admin",
3
- "version": "5.2.5",
3
+ "version": "0.2.0",
4
4
  "description": "AlchemyCMS",
5
5
  "browser": "package/admin.js",
6
6
  "files": [
@@ -24,12 +24,13 @@
24
24
  },
25
25
  "homepage": "https://github.com/AlchemyCMS/alchemy_cms#readme",
26
26
  "dependencies": {
27
+ "lodash-es": "^4.17.21",
27
28
  "sortablejs": "^1.10.2"
28
29
  },
29
30
  "devDependencies": {
30
31
  "@babel/core": "^7.9.6",
31
32
  "@babel/preset-env": "^7.9.6",
32
- "babel-jest": "^26.0.1",
33
+ "babel-jest": "^27.0.1",
33
34
  "jest": "^25.2.7",
34
35
  "prettier": "^2.0.2",
35
36
  "xhr-mock": "^2.5.1"
@@ -1,22 +1,7 @@
1
1
  /**
2
- * jquery.Jcrop.min.js v0.9.12 (build:20130202)
2
+ * jquery.Jcrop.min.js v0.9.15 (build:20180819)
3
3
  * jQuery Image Cropping Plugin - released under MIT License
4
- * Copyright (c) 2008-2013 Tapmodo Interactive LLC
4
+ * Copyright (c) 2008-2018 Tapmodo Interactive LLC
5
5
  * https://github.com/tapmodo/Jcrop
6
6
  */
7
- (function(a){a.Jcrop=function(b,c){function i(a){return Math.round(a)+"px"}function j(a){return d.baseClass+"-"+a}function k(){return a.fx.step.hasOwnProperty("backgroundColor")}function l(b){var c=a(b).offset();return[c.left,c.top]}function m(a){return[a.pageX-e[0],a.pageY-e[1]]}function n(b){typeof b!="object"&&(b={}),d=a.extend(d,b),a.each(["onChange","onSelect","onRelease","onDblClick"],function(a,b){typeof d[b]!="function"&&(d[b]=function(){})})}function o(a,b,c){e=l(D),bc.setCursor(a==="move"?a:a+"-resize");if(a==="move")return bc.activateHandlers(q(b),v,c);var d=_.getFixed(),f=r(a),g=_.getCorner(r(f));_.setPressed(_.getCorner(f)),_.setCurrent(g),bc.activateHandlers(p(a,d),v,c)}function p(a,b){return function(c){if(!d.aspectRatio)switch(a){case"e":c[1]=b.y2;break;case"w":c[1]=b.y2;break;case"n":c[0]=b.x2;break;case"s":c[0]=b.x2}else switch(a){case"e":c[1]=b.y+1;break;case"w":c[1]=b.y+1;break;case"n":c[0]=b.x+1;break;case"s":c[0]=b.x+1}_.setCurrent(c),bb.update()}}function q(a){var b=a;return bd.watchKeys
8
- (),function(a){_.moveOffset([a[0]-b[0],a[1]-b[1]]),b=a,bb.update()}}function r(a){switch(a){case"n":return"sw";case"s":return"nw";case"e":return"nw";case"w":return"ne";case"ne":return"sw";case"nw":return"se";case"se":return"nw";case"sw":return"ne"}}function s(a){return function(b){return d.disabled?!1:a==="move"&&!d.allowMove?!1:(e=l(D),W=!0,o(a,m(b)),b.stopPropagation(),b.preventDefault(),!1)}}function t(a,b,c){var d=a.width(),e=a.height();d>b&&b>0&&(d=b,e=b/a.width()*a.height()),e>c&&c>0&&(e=c,d=c/a.height()*a.width()),T=a.width()/d,U=a.height()/e,a.width(d).height(e)}function u(a){return{x:a.x*T,y:a.y*U,x2:a.x2*T,y2:a.y2*U,w:a.w*T,h:a.h*U}}function v(a){var b=_.getFixed();b.w>d.minSelect[0]&&b.h>d.minSelect[1]?(bb.enableHandles(),bb.done()):bb.release(),bc.setCursor(d.allowSelect?"crosshair":"default")}function w(a){if(d.disabled)return!1;if(!d.allowSelect)return!1;W=!0,e=l(D),bb.disableHandles(),bc.setCursor("crosshair");var b=m(a);return _.setPressed(b),bb.update(),bc.activateHandlers(x,v,a.type.substring
9
- (0,5)==="touch"),bd.watchKeys(),a.stopPropagation(),a.preventDefault(),!1}function x(a){_.setCurrent(a),bb.update()}function y(){var b=a("<div></div>").addClass(j("tracker"));return g&&b.css({opacity:0,backgroundColor:"white"}),b}function be(a){G.removeClass().addClass(j("holder")).addClass(a)}function bf(a,b){function t(){window.setTimeout(u,l)}var c=a[0]/T,e=a[1]/U,f=a[2]/T,g=a[3]/U;if(X)return;var h=_.flipCoords(c,e,f,g),i=_.getFixed(),j=[i.x,i.y,i.x2,i.y2],k=j,l=d.animationDelay,m=h[0]-j[0],n=h[1]-j[1],o=h[2]-j[2],p=h[3]-j[3],q=0,r=d.swingSpeed;c=k[0],e=k[1],f=k[2],g=k[3],bb.animMode(!0);var s,u=function(){return function(){q+=(100-q)/r,k[0]=Math.round(c+q/100*m),k[1]=Math.round(e+q/100*n),k[2]=Math.round(f+q/100*o),k[3]=Math.round(g+q/100*p),q>=99.8&&(q=100),q<100?(bh(k),t()):(bb.done(),bb.animMode(!1),typeof b=="function"&&b.call(bs))}}();t()}function bg(a){bh([a[0]/T,a[1]/U,a[2]/T,a[3]/U]),d.onSelect.call(bs,u(_.getFixed())),bb.enableHandles()}function bh(a){_.setPressed([a[0],a[1]]),_.setCurrent([a[2],
10
- a[3]]),bb.update()}function bi(){return u(_.getFixed())}function bj(){return _.getFixed()}function bk(a){n(a),br()}function bl(){d.disabled=!0,bb.disableHandles(),bb.setCursor("default"),bc.setCursor("default")}function bm(){d.disabled=!1,br()}function bn(){bb.done(),bc.activateHandlers(null,null)}function bo(){G.remove(),A.show(),A.css("visibility","visible"),a(b).removeData("Jcrop")}function bp(a,b){bb.release(),bl();var c=new Image;c.onload=function(){var e=c.width,f=c.height,g=d.boxWidth,h=d.boxHeight;D.width(e).height(f),D.attr("src",a),H.attr("src",a),t(D,g,h),E=D.width(),F=D.height(),H.width(E).height(F),M.width(E+L*2).height(F+L*2),G.width(E).height(F),ba.resize(E,F),bm(),typeof b=="function"&&b.call(bs)},c.src=a}function bq(a,b,c){var e=b||d.bgColor;d.bgFade&&k()&&d.fadeTime&&!c?a.animate({backgroundColor:e},{queue:!1,duration:d.fadeTime}):a.css("backgroundColor",e)}function br(a){d.allowResize?a?bb.enableOnly():bb.enableHandles():bb.disableHandles(),bc.setCursor(d.allowSelect?"crosshair":"default"),bb
11
- .setCursor(d.allowMove?"move":"default"),d.hasOwnProperty("trueSize")&&(T=d.trueSize[0]/E,U=d.trueSize[1]/F),d.hasOwnProperty("setSelect")&&(bg(d.setSelect),bb.done(),delete d.setSelect),ba.refresh(),d.bgColor!=N&&(bq(d.shade?ba.getShades():G,d.shade?d.shadeColor||d.bgColor:d.bgColor),N=d.bgColor),O!=d.bgOpacity&&(O=d.bgOpacity,d.shade?ba.refresh():bb.setBgOpacity(O)),P=d.maxSize[0]||0,Q=d.maxSize[1]||0,R=d.minSize[0]||0,S=d.minSize[1]||0,d.hasOwnProperty("outerImage")&&(D.attr("src",d.outerImage),delete d.outerImage),bb.refresh()}var d=a.extend({},a.Jcrop.defaults),e,f=navigator.userAgent.toLowerCase(),g=/msie/.test(f),h=/msie [1-6]\./.test(f);typeof b!="object"&&(b=a(b)[0]),typeof c!="object"&&(c={}),n(c);var z={border:"none",visibility:"visible",margin:0,padding:0,position:"absolute",top:0,left:0},A=a(b),B=!0;if(b.tagName=="IMG"){if(A[0].width!=0&&A[0].height!=0)A.width(A[0].width),A.height(A[0].height);else{var C=new Image;C.src=A[0].src,A.width(C.width),A.height(C.height)}var D=A.clone().removeAttr("id").
12
- css(z).show();D.width(A.width()),D.height(A.height()),A.after(D).hide()}else D=A.css(z).show(),B=!1,d.shade===null&&(d.shade=!0);t(D,d.boxWidth,d.boxHeight);var E=D.width(),F=D.height(),G=a("<div />").width(E).height(F).addClass(j("holder")).css({position:"relative",backgroundColor:d.bgColor}).insertAfter(A).append(D);d.addClass&&G.addClass(d.addClass);var H=a("<div />"),I=a("<div />").width("100%").height("100%").css({zIndex:310,position:"absolute",overflow:"hidden"}),J=a("<div />").width("100%").height("100%").css("zIndex",320),K=a("<div />").css({position:"absolute",zIndex:600}).dblclick(function(){var a=_.getFixed();d.onDblClick.call(bs,a)}).insertBefore(D).append(I,J);B&&(H=a("<img />").attr("src",D.attr("src")).css(z).width(E).height(F),I.append(H)),h&&K.css({overflowY:"hidden"});var L=d.boundary,M=y().width(E+L*2).height(F+L*2).css({position:"absolute",top:i(-L),left:i(-L),zIndex:290}).mousedown(w),N=d.bgColor,O=d.bgOpacity,P,Q,R,S,T,U,V=!0,W,X,Y;e=l(D);var Z=function(){function a(){var a={},b=["touchstart"
13
- ,"touchmove","touchend"],c=document.createElement("div"),d;try{for(d=0;d<b.length;d++){var e=b[d];e="on"+e;var f=e in c;f||(c.setAttribute(e,"return;"),f=typeof c[e]=="function"),a[b[d]]=f}return a.touchstart&&a.touchend&&a.touchmove}catch(g){return!1}}function b(){return d.touchSupport===!0||d.touchSupport===!1?d.touchSupport:a()}return{createDragger:function(a){return function(b){return d.disabled?!1:a==="move"&&!d.allowMove?!1:(e=l(D),W=!0,o(a,m(Z.cfilter(b)),!0),b.stopPropagation(),b.preventDefault(),!1)}},newSelection:function(a){return w(Z.cfilter(a))},cfilter:function(a){return a.pageX=a.originalEvent.changedTouches[0].pageX,a.pageY=a.originalEvent.changedTouches[0].pageY,a},isSupported:a,support:b()}}(),_=function(){function h(d){d=n(d),c=a=d[0],e=b=d[1]}function i(a){a=n(a),f=a[0]-c,g=a[1]-e,c=a[0],e=a[1]}function j(){return[f,g]}function k(d){var f=d[0],g=d[1];0>a+f&&(f-=f+a),0>b+g&&(g-=g+b),F<e+g&&(g+=F-(e+g)),E<c+f&&(f+=E-(c+f)),a+=f,c+=f,b+=g,e+=g}function l(a){var b=m();switch(a){case"ne":return[
14
- b.x2,b.y];case"nw":return[b.x,b.y];case"se":return[b.x2,b.y2];case"sw":return[b.x,b.y2]}}function m(){if(!d.aspectRatio)return p();var f=d.aspectRatio,g=d.minSize[0]/T,h=d.maxSize[0]/T,i=d.maxSize[1]/U,j=c-a,k=e-b,l=Math.abs(j),m=Math.abs(k),n=l/m,r,s,t,u;return h===0&&(h=E*10),i===0&&(i=F*10),n<f?(s=e,t=m*f,r=j<0?a-t:t+a,r<0?(r=0,u=Math.abs((r-a)/f),s=k<0?b-u:u+b):r>E&&(r=E,u=Math.abs((r-a)/f),s=k<0?b-u:u+b)):(r=c,u=l/f,s=k<0?b-u:b+u,s<0?(s=0,t=Math.abs((s-b)*f),r=j<0?a-t:t+a):s>F&&(s=F,t=Math.abs(s-b)*f,r=j<0?a-t:t+a)),r>a?(r-a<g?r=a+g:r-a>h&&(r=a+h),s>b?s=b+(r-a)/f:s=b-(r-a)/f):r<a&&(a-r<g?r=a-g:a-r>h&&(r=a-h),s>b?s=b+(a-r)/f:s=b-(a-r)/f),r<0?(a-=r,r=0):r>E&&(a-=r-E,r=E),s<0?(b-=s,s=0):s>F&&(b-=s-F,s=F),q(o(a,b,r,s))}function n(a){return a[0]<0&&(a[0]=0),a[1]<0&&(a[1]=0),a[0]>E&&(a[0]=E),a[1]>F&&(a[1]=F),[Math.round(a[0]),Math.round(a[1])]}function o(a,b,c,d){var e=a,f=c,g=b,h=d;return c<a&&(e=c,f=a),d<b&&(g=d,h=b),[e,g,f,h]}function p(){var d=c-a,f=e-b,g;return P&&Math.abs(d)>P&&(c=d>0?a+P:a-P),Q&&Math.abs
15
- (f)>Q&&(e=f>0?b+Q:b-Q),S/U&&Math.abs(f)<S/U&&(e=f>0?b+S/U:b-S/U),R/T&&Math.abs(d)<R/T&&(c=d>0?a+R/T:a-R/T),a<0&&(c-=a,a-=a),b<0&&(e-=b,b-=b),c<0&&(a-=c,c-=c),e<0&&(b-=e,e-=e),c>E&&(g=c-E,a-=g,c-=g),e>F&&(g=e-F,b-=g,e-=g),a>E&&(g=a-F,e-=g,b-=g),b>F&&(g=b-F,e-=g,b-=g),q(o(a,b,c,e))}function q(a){return{x:a[0],y:a[1],x2:a[2],y2:a[3],w:a[2]-a[0],h:a[3]-a[1]}}var a=0,b=0,c=0,e=0,f,g;return{flipCoords:o,setPressed:h,setCurrent:i,getOffset:j,moveOffset:k,getCorner:l,getFixed:m}}(),ba=function(){function f(a,b){e.left.css({height:i(b)}),e.right.css({height:i(b)})}function g(){return h(_.getFixed())}function h(a){e.top.css({left:i(a.x),width:i(a.w),height:i(a.y)}),e.bottom.css({top:i(a.y2),left:i(a.x),width:i(a.w),height:i(F-a.y2)}),e.right.css({left:i(a.x2),width:i(E-a.x2)}),e.left.css({width:i(a.x)})}function j(){return a("<div />").css({position:"absolute",backgroundColor:d.shadeColor||d.bgColor}).appendTo(c)}function k(){b||(b=!0,c.insertBefore(D),g(),bb.setBgOpacity(1,0,1),H.hide(),l(d.shadeColor||d.bgColor,1),bb.
16
- isAwake()?n(d.bgOpacity,1):n(1,1))}function l(a,b){bq(p(),a,b)}function m(){b&&(c.remove(),H.show(),b=!1,bb.isAwake()?bb.setBgOpacity(d.bgOpacity,1,1):(bb.setBgOpacity(1,1,1),bb.disableHandles()),bq(G,0,1))}function n(a,e){b&&(d.bgFade&&!e?c.animate({opacity:1-a},{queue:!1,duration:d.fadeTime}):c.css({opacity:1-a}))}function o(){d.shade?k():m(),bb.isAwake()&&n(d.bgOpacity)}function p(){return c.children()}var b=!1,c=a("<div />").css({position:"absolute",zIndex:240,opacity:0}),e={top:j(),left:j().height(F),right:j().height(F),bottom:j()};return{update:g,updateRaw:h,getShades:p,setBgColor:l,enable:k,disable:m,resize:f,refresh:o,opacity:n}}(),bb=function(){function k(b){var c=a("<div />").css({position:"absolute",opacity:d.borderOpacity}).addClass(j(b));return I.append(c),c}function l(b,c){var d=a("<div />").mousedown(s(b)).css({cursor:b+"-resize",position:"absolute",zIndex:c}).addClass("ord-"+b);return Z.support&&d.bind("touchstart.jcrop",Z.createDragger(b)),J.append(d),d}function m(a){var b=d.handleSize,e=l(a,c++
17
- ).css({opacity:d.handleOpacity}).addClass(j("handle"));return b&&e.width(b).height(b),e}function n(a){return l(a,c++).addClass("jcrop-dragbar")}function o(a){var b;for(b=0;b<a.length;b++)g[a[b]]=n(a[b])}function p(a){var b,c;for(c=0;c<a.length;c++){switch(a[c]){case"n":b="hline";break;case"s":b="hline bottom";break;case"e":b="vline right";break;case"w":b="vline"}e[a[c]]=k(b)}}function q(a){var b;for(b=0;b<a.length;b++)f[a[b]]=m(a[b])}function r(a,b){d.shade||H.css({top:i(-b),left:i(-a)}),K.css({top:i(b),left:i(a)})}function t(a,b){K.width(Math.round(a)).height(Math.round(b))}function v(){var a=_.getFixed();_.setPressed([a.x,a.y]),_.setCurrent([a.x2,a.y2]),w()}function w(a){if(b)return x(a)}function x(a){var c=_.getFixed();t(c.w,c.h),r(c.x,c.y),d.shade&&ba.updateRaw(c),b||A(),a?d.onSelect.call(bs,u(c)):d.onChange.call(bs,u(c))}function z(a,c,e){if(!b&&!c)return;d.bgFade&&!e?D.animate({opacity:a},{queue:!1,duration:d.fadeTime}):D.css("opacity",a)}function A(){K.show(),d.shade?ba.opacity(O):z(O,!0),b=!0}function B
18
- (){F(),K.hide(),d.shade?ba.opacity(1):z(1),b=!1,d.onRelease.call(bs)}function C(){h&&J.show()}function E(){h=!0;if(d.allowResize)return J.show(),!0}function F(){h=!1,J.hide()}function G(a){a?(X=!0,F()):(X=!1,E())}function L(){G(!1),v()}var b,c=370,e={},f={},g={},h=!1;d.dragEdges&&a.isArray(d.createDragbars)&&o(d.createDragbars),a.isArray(d.createHandles)&&q(d.createHandles),d.drawBorders&&a.isArray(d.createBorders)&&p(d.createBorders),a(document).bind("touchstart.jcrop-ios",function(b){a(b.currentTarget).hasClass("jcrop-tracker")&&b.stopPropagation()});var M=y().mousedown(s("move")).css({cursor:"move",position:"absolute",zIndex:360});return Z.support&&M.bind("touchstart.jcrop",Z.createDragger("move")),I.append(M),F(),{updateVisible:w,update:x,release:B,refresh:v,isAwake:function(){return b},setCursor:function(a){M.css("cursor",a)},enableHandles:E,enableOnly:function(){h=!0},showHandles:C,disableHandles:F,animMode:G,setBgOpacity:z,done:L}}(),bc=function(){function f(b){M.css({zIndex:450}),b?a(document).bind("touchmove.jcrop"
19
- ,k).bind("touchend.jcrop",l):e&&a(document).bind("mousemove.jcrop",h).bind("mouseup.jcrop",i)}function g(){M.css({zIndex:290}),a(document).unbind(".jcrop")}function h(a){return b(m(a)),!1}function i(a){return a.preventDefault(),a.stopPropagation(),W&&(W=!1,c(m(a)),bb.isAwake()&&d.onSelect.call(bs,u(_.getFixed())),g(),b=function(){},c=function(){}),!1}function j(a,d,e){return W=!0,b=a,c=d,f(e),!1}function k(a){return b(m(Z.cfilter(a))),!1}function l(a){return i(Z.cfilter(a))}function n(a){M.css("cursor",a)}var b=function(){},c=function(){},e=d.trackDocument;return e||M.mousemove(h).mouseup(i).mouseout(i),D.before(M),{activateHandlers:j,setCursor:n}}(),bd=function(){function e(){d.keySupport&&(b.show(),b.focus())}function f(a){b.hide()}function g(a,b,c){d.allowMove&&(_.moveOffset([b,c]),bb.updateVisible(!0)),a.preventDefault(),a.stopPropagation()}function i(a){if(a.ctrlKey||a.metaKey)return!0;Y=a.shiftKey?!0:!1;var b=Y?10:1;switch(a.keyCode){case 37:g(a,-b,0);break;case 39:g(a,b,0);break;case 38:g(a,0,-b);break;
20
- case 40:g(a,0,b);break;case 27:d.allowSelect&&bb.release();break;case 9:return!0}return!1}var b=a('<input type="radio" />').css({position:"fixed",left:"-120px",width:"12px"}).addClass("jcrop-keymgr"),c=a("<div />").css({position:"absolute",overflow:"hidden"}).append(b);return d.keySupport&&(b.keydown(i).blur(f),h||!d.fixedSupport?(b.css({position:"absolute",left:"-20px"}),c.append(b).insertBefore(D)):b.insertBefore(D)),{watchKeys:e}}();Z.support&&M.bind("touchstart.jcrop",Z.newSelection),J.hide(),br(!0);var bs={setImage:bp,animateTo:bf,setSelect:bg,setOptions:bk,tellSelect:bi,tellScaled:bj,setClass:be,disable:bl,enable:bm,cancel:bn,release:bb.release,destroy:bo,focus:bd.watchKeys,getBounds:function(){return[E*T,F*U]},getWidgetSize:function(){return[E,F]},getScaleFactor:function(){return[T,U]},getOptions:function(){return d},ui:{holder:G,selection:K}};return g&&G.bind("selectstart",function(){return!1}),A.data("Jcrop",bs),bs},a.fn.Jcrop=function(b,c){var d;return this.each(function(){if(a(this).data("Jcrop")){if(
21
- b==="api")return a(this).data("Jcrop");a(this).data("Jcrop").setOptions(b)}else this.tagName=="IMG"?a.Jcrop.Loader(this,function(){a(this).css({display:"block",visibility:"hidden"}),d=a.Jcrop(this,b),a.isFunction(c)&&c.call(d)}):(a(this).css({display:"block",visibility:"hidden"}),d=a.Jcrop(this,b),a.isFunction(c)&&c.call(d))}),this},a.Jcrop.Loader=function(b,c,d){function g(){f.complete?(e.unbind(".jcloader"),a.isFunction(c)&&c.call(f)):window.setTimeout(g,50)}var e=a(b),f=e[0];e.bind("load.jcloader",g).bind("error.jcloader",function(b){e.unbind(".jcloader"),a.isFunction(d)&&d.call(f)}),f.complete&&a.isFunction(c)&&(e.unbind(".jcloader"),c.call(f))},a.Jcrop.defaults={allowSelect:!0,allowMove:!0,allowResize:!0,trackDocument:!0,baseClass:"jcrop",addClass:null,bgColor:"black",bgOpacity:.6,bgFade:!1,borderOpacity:.4,handleOpacity:.5,handleSize:null,aspectRatio:0,keySupport:!0,createHandles:["n","s","e","w","nw","ne","se","sw"],createDragbars:["n","s","e","w"],createBorders:["n","s","e","w"],drawBorders:!0,dragEdges
22
- :!0,fixedSupport:!0,touchSupport:null,shade:null,boxWidth:0,boxHeight:0,boundary:2,fadeTime:400,animationDelay:20,swingSpeed:3,minSelect:[0,0],maxSize:[0,0],minSize:[0,0],onChange:function(){},onSelect:function(){},onDblClick:function(){},onRelease:function(){}}})(jQuery);
7
+ !function($){$.Jcrop=function(obj,opt){function px(n){return Math.round(n)+"px"}function cssClass(cl){return options.baseClass+"-"+cl}function supportsColorFade(){return $.fx.step.hasOwnProperty("backgroundColor")}function getPos(obj){var pos=$(obj).offset();return[pos.left,pos.top]}function mouseAbs(e){return[e.pageX-docOffset[0],e.pageY-docOffset[1]]}function setOptions(opt){"object"!=typeof opt&&(opt={}),options=$.extend(options,opt),$.each(["onChange","onSelect","onRelease","onDblClick"],function(i,e){"function"!=typeof options[e]&&(options[e]=function(){})})}function startDragMode(mode,pos,touch){if(docOffset=getPos($img),Tracker.setCursor("move"===mode?mode:mode+"-resize"),"move"===mode)return Tracker.activateHandlers(createMover(pos),doneSelect,touch);var fc=Coords.getFixed(),opp=oppLockCorner(mode),opc=Coords.getCorner(oppLockCorner(opp));Coords.setPressed(Coords.getCorner(opp)),Coords.setCurrent(opc),Tracker.activateHandlers(dragmodeHandler(mode,fc),doneSelect,touch)}function dragmodeHandler(mode,f){return function(pos){if(options.aspectRatio)switch(mode){case"e":pos[1]=f.y+1;break;case"w":pos[1]=f.y+1;break;case"n":pos[0]=f.x+1;break;case"s":pos[0]=f.x+1}else switch(mode){case"e":pos[1]=f.y2;break;case"w":pos[1]=f.y2;break;case"n":pos[0]=f.x2;break;case"s":pos[0]=f.x2}Coords.setCurrent(pos),Selection.update()}}function createMover(pos){var lloc=pos;return KeyManager.watchKeys(),function(pos){Coords.moveOffset([pos[0]-lloc[0],pos[1]-lloc[1]]),lloc=pos,Selection.update()}}function oppLockCorner(ord){switch(ord){case"n":return"sw";case"s":return"nw";case"e":return"nw";case"w":return"ne";case"ne":return"sw";case"nw":return"se";case"se":return"nw";case"sw":return"ne"}}function createDragger(ord){return function(e){return options.disabled?!1:"move"!==ord||options.allowMove?(docOffset=getPos($img),btndown=!0,startDragMode(ord,mouseAbs(e)),e.stopPropagation(),e.preventDefault(),!1):!1}}function presize($obj,w,h){var nw=$obj.width(),nh=$obj.height();nw>w&&w>0&&(nw=w,nh=w/$obj.width()*$obj.height()),nh>h&&h>0&&(nh=h,nw=h/$obj.height()*$obj.width()),xscale=$obj.width()/nw,yscale=$obj.height()/nh,$obj.width(nw).height(nh)}function unscale(c){return{x:c.x*xscale,y:c.y*yscale,x2:c.x2*xscale,y2:c.y2*yscale,w:c.w*xscale,h:c.h*yscale}}function doneSelect(){var c=Coords.getFixed();c.w>options.minSelect[0]&&c.h>options.minSelect[1]?(Selection.enableHandles(),Selection.done()):Selection.release(),Tracker.setCursor(options.allowSelect?"crosshair":"default")}function newSelection(e){if(!options.disabled&&options.allowSelect){btndown=!0,docOffset=getPos($img),Selection.disableHandles(),Tracker.setCursor("crosshair");var pos=mouseAbs(e);return Coords.setPressed(pos),Selection.update(),Tracker.activateHandlers(selectDrag,doneSelect,"touch"===e.type.substring(0,5)),KeyManager.watchKeys(),e.stopPropagation(),e.preventDefault(),!1}}function selectDrag(pos){Coords.setCurrent(pos),Selection.update()}function newTracker(){var trk=$("<div></div>").addClass(cssClass("tracker"));return is_msie&&trk.css({opacity:0,backgroundColor:"white"}),trk}function setClass(cname){$div.removeClass().addClass(cssClass("holder")).addClass(cname)}function animateTo(a,callback){function queueAnimator(){window.setTimeout(animator,interv)}var x1=a[0]/xscale,y1=a[1]/yscale,x2=a[2]/xscale,y2=a[3]/yscale;if(!animating){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;x1=animat[0],y1=animat[1],x2=animat[2],y2=animat[3],Selection.animMode(!0);var animator=function(){return function(){pcent+=(100-pcent)/velocity,animat[0]=Math.round(x1+pcent/100*ix1),animat[1]=Math.round(y1+pcent/100*iy1),animat[2]=Math.round(x2+pcent/100*ix2),animat[3]=Math.round(y2+pcent/100*iy2),pcent>=99.8&&(pcent=100),100>pcent?(setSelectRaw(animat),queueAnimator()):(Selection.done(),Selection.animMode(!1),"function"==typeof callback&&callback.call(api))}}();queueAnimator()}}function setSelect(rect){setSelectRaw([rect[0]/xscale,rect[1]/yscale,rect[2]/xscale,rect[3]/yscale]),options.onSelect.call(api,unscale(Coords.getFixed())),Selection.enableHandles()}function setSelectRaw(l){Coords.setPressed([l[0],l[1]]),Coords.setCurrent([l[2],l[3]]),Selection.update()}function tellSelect(){return unscale(Coords.getFixed())}function tellScaled(){return Coords.getFixed()}function setOptionsNew(opt){setOptions(opt),interfaceUpdate()}function disableCrop(){options.disabled=!0,Selection.disableHandles(),Selection.setCursor("default"),Tracker.setCursor("default")}function enableCrop(){options.disabled=!1,interfaceUpdate()}function cancelCrop(){Selection.done(),Tracker.activateHandlers(null,null)}function destroy(){$div.remove(),$origimg.show(),$origimg.css("visibility","visible"),$(obj).removeData("Jcrop")}function setImage(src,callback){Selection.release(),disableCrop();var img=new Image;img.onload=function(){var iw=img.width,ih=img.height,bw=options.boxWidth,bh=options.boxHeight;$img.width(iw).height(ih),$img.attr("src",src),$img2.attr("src",src),presize($img,bw,bh),boundx=$img.width(),boundy=$img.height(),$img2.width(boundx).height(boundy),$trk.width(boundx+2*bound).height(boundy+2*bound),$div.width(boundx).height(boundy),Shade.resize(boundx,boundy),enableCrop(),"function"==typeof callback&&callback.call(api)},img.src=src}function colorChangeMacro($obj,color,now){var mycolor=color||options.bgColor;options.bgFade&&supportsColorFade()&&options.fadeTime&&!now?$obj.animate({backgroundColor:mycolor},{queue:!1,duration:options.fadeTime}):$obj.css("backgroundColor",mycolor)}function interfaceUpdate(alt){options.allowResize?alt?Selection.enableOnly():Selection.enableHandles():Selection.disableHandles(),Tracker.setCursor(options.allowSelect?"crosshair":"default"),Selection.setCursor(options.allowMove?"move":"default"),options.hasOwnProperty("trueSize")&&(xscale=options.trueSize[0]/boundx,yscale=options.trueSize[1]/boundy),options.hasOwnProperty("setSelect")&&(setSelect(options.setSelect),Selection.done(),delete options.setSelect),Shade.refresh(),options.bgColor!=bgcolor&&(colorChangeMacro(options.shade?Shade.getShades():$div,options.shade?options.shadeColor||options.bgColor:options.bgColor),bgcolor=options.bgColor),bgopacity!=options.bgOpacity&&(bgopacity=options.bgOpacity,options.shade?Shade.refresh():Selection.setBgOpacity(bgopacity)),xlimit=options.maxSize[0]||0,ylimit=options.maxSize[1]||0,xmin=options.minSize[0]||0,ymin=options.minSize[1]||0,options.hasOwnProperty("outerImage")&&($img.attr("src",options.outerImage),delete options.outerImage),Selection.refresh()}var docOffset,options=$.extend({},$.Jcrop.defaults),_ua=navigator.userAgent.toLowerCase(),is_msie=/msie/.test(_ua),ie6mode=/msie [1-6]\./.test(_ua);"object"!=typeof obj&&(obj=$(obj)[0]),"object"!=typeof opt&&(opt={}),setOptions(opt);var img_css={border:"none",visibility:"visible",margin:0,padding:0,position:"absolute",top:0,left:0},$origimg=$(obj),img_mode=!0;if("IMG"==obj.tagName){if(0!=$origimg[0].width&&0!=$origimg[0].height)$origimg.width($origimg[0].width),$origimg.height($origimg[0].height);else{var tempImage=new Image;tempImage.src=$origimg[0].src,$origimg.width(tempImage.width),$origimg.height(tempImage.height)}var $img=$origimg.clone().removeAttr("id").css(img_css).show();$img.width($origimg.width()),$img.height($origimg.height()),$origimg.after($img).hide()}else $img=$origimg.css(img_css).show(),img_mode=!1,null===options.shade&&(options.shade=!0);presize($img,options.boxWidth,options.boxHeight);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);options.addClass&&$div.addClass(options.addClass);var $img2=$("<div />"),$img_holder=$("<div />").width("100%").height("100%").css({zIndex:310,position:"absolute",overflow:"hidden"}),$hdl_holder=$("<div />").width("100%").height("100%").css("zIndex",320),$sel=$("<div />").css({position:"absolute",zIndex:600}).dblclick(function(){var c=Coords.getFixed();options.onDblClick.call(api,c)}).insertBefore($img).append($img_holder,$hdl_holder);img_mode&&($img2=$("<img />").attr("src",$img.attr("src")).css(img_css).width(boundx).height(boundy),$img_holder.append($img2)),ie6mode&&$sel.css({overflowY:"hidden"});var xlimit,ylimit,xmin,ymin,xscale,yscale,btndown,animating,shift_down,bound=options.boundary,$trk=newTracker().width(boundx+2*bound).height(boundy+2*bound).css({position:"absolute",top:px(-bound),left:px(-bound),zIndex:290}).mousedown(newSelection),bgcolor=options.bgColor,bgopacity=options.bgOpacity;docOffset=getPos($img);var Touch=function(){function hasTouchSupport(){var i,support={},events=["touchstart","touchmove","touchend"],el=document.createElement("div");try{for(i=0;i<events.length;i++){var eventName=events[i];eventName="on"+eventName;var isSupported=eventName in el;isSupported||(el.setAttribute(eventName,"return;"),isSupported="function"==typeof el[eventName]),support[events[i]]=isSupported}return support.touchstart&&support.touchend&&support.touchmove}catch(err){return!1}}function detectSupport(){return options.touchSupport===!0||options.touchSupport===!1?options.touchSupport:hasTouchSupport()}return{createDragger:function(ord){return function(e){return options.disabled?!1:"move"!==ord||options.allowMove?(docOffset=getPos($img),btndown=!0,startDragMode(ord,mouseAbs(Touch.cfilter(e)),!0),e.stopPropagation(),e.preventDefault(),!1):!1}},newSelection:function(e){return newSelection(Touch.cfilter(e))},cfilter:function(e){return e.pageX=e.originalEvent.changedTouches[0].pageX,e.pageY=e.originalEvent.changedTouches[0].pageY,e},isSupported:hasTouchSupport,support:detectSupport()}}(),Coords=function(){function setPressed(pos){pos=rebound(pos),x2=x1=pos[0],y2=y1=pos[1]}function setCurrent(pos){pos=rebound(pos),ox=pos[0]-x2,oy=pos[1]-y2,x2=pos[0],y2=pos[1]}function getOffset(){return[ox,oy]}function moveOffset(offset){var ox=offset[0],oy=offset[1];0>x1+ox&&(ox-=ox+x1),0>y1+oy&&(oy-=oy+y1),y2+oy>boundy&&(oy+=boundy-(y2+oy)),x2+ox>boundx&&(ox+=boundx-(x2+ox)),x1+=ox,x2+=ox,y1+=oy,y2+=oy}function getCorner(ord){var c=getFixed();switch(ord){case"ne":return[c.x2,c.y];case"nw":return[c.x,c.y];case"se":return[c.x2,c.y2];case"sw":return[c.x,c.y2]}}function getFixed(){if(!options.aspectRatio)return getRect();var xx,yy,w,h,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;return 0===max_x&&(max_x=10*boundx),0===max_y&&(max_y=10*boundy),aspect>real_ratio?(yy=y2,w=rha*aspect,xx=0>rw?x1-w:w+x1,0>xx?(xx=0,h=Math.abs((xx-x1)/aspect),yy=0>rh?y1-h:h+y1):xx>boundx&&(xx=boundx,h=Math.abs((xx-x1)/aspect),yy=0>rh?y1-h:h+y1)):(xx=x2,h=rwa/aspect,yy=0>rh?y1-h:y1+h,0>yy?(yy=0,w=Math.abs((yy-y1)*aspect),xx=0>rw?x1-w:w+x1):yy>boundy&&(yy=boundy,w=Math.abs(yy-y1)*aspect,xx=0>rw?x1-w:w+x1)),xx>x1?(min_x>xx-x1?xx=x1+min_x:xx-x1>max_x&&(xx=x1+max_x),yy=yy>y1?y1+(xx-x1)/aspect:y1-(xx-x1)/aspect):x1>xx&&(min_x>x1-xx?xx=x1-min_x:x1-xx>max_x&&(xx=x1-max_x),yy=yy>y1?y1+(x1-xx)/aspect:y1-(x1-xx)/aspect),0>xx?(x1-=xx,xx=0):xx>boundx&&(x1-=xx-boundx,xx=boundx),0>yy?(y1-=yy,yy=0):yy>boundy&&(y1-=yy-boundy,yy=boundy),makeObj(flipCoords(x1,y1,xx,yy))}function rebound(p){return p[0]<0&&(p[0]=0),p[1]<0&&(p[1]=0),p[0]>boundx&&(p[0]=boundx),p[1]>boundy&&(p[1]=boundy),[Math.round(p[0]),Math.round(p[1])]}function flipCoords(x1,y1,x2,y2){var xa=x1,xb=x2,ya=y1,yb=y2;return x1>x2&&(xa=x2,xb=x1),y1>y2&&(ya=y2,yb=y1),[xa,ya,xb,yb]}function getRect(){var delta,xsize=x2-x1,ysize=y2-y1;return xlimit&&Math.abs(xsize)>xlimit&&(x2=xsize>0?x1+xlimit:x1-xlimit),ylimit&&Math.abs(ysize)>ylimit&&(y2=ysize>0?y1+ylimit:y1-ylimit),ymin/yscale&&Math.abs(ysize)<ymin/yscale&&(y2=ysize>0?y1+ymin/yscale:y1-ymin/yscale),xmin/xscale&&Math.abs(xsize)<xmin/xscale&&(x2=xsize>0?x1+xmin/xscale:x1-xmin/xscale),0>x1&&(x2-=x1,x1-=x1),0>y1&&(y2-=y1,y1-=y1),0>x2&&(x1-=x2,x2-=x2),0>y2&&(y1-=y2,y2-=y2),x2>boundx&&(delta=x2-boundx,x1-=delta,x2-=delta),y2>boundy&&(delta=y2-boundy,y1-=delta,y2-=delta),x1>boundx&&(delta=x1-boundy,y2-=delta,y1-=delta),y1>boundy&&(delta=y1-boundy,y2-=delta,y1-=delta),makeObj(flipCoords(x1,y1,x2,y2))}function makeObj(a){return{x:a[0],y:a[1],x2:a[2],y2:a[3],w:a[2]-a[0],h:a[3]-a[1]}}var ox,oy,x1=0,y1=0,x2=0,y2=0;return{flipCoords:flipCoords,setPressed:setPressed,setCurrent:setCurrent,getOffset:getOffset,moveOffset:moveOffset,getCorner:getCorner,getFixed:getFixed}}(),Shade=function(){function resizeShades(w,h){shades.left.css({height:px(h)}),shades.right.css({height:px(h)})}function updateAuto(){return updateShade(Coords.getFixed())}function updateShade(c){shades.top.css({left:px(c.x),width:px(c.w),height:px(c.y)}),shades.bottom.css({top:px(c.y2),left:px(c.x),width:px(c.w),height:px(boundy-c.y2)}),shades.right.css({left:px(c.x2),width:px(boundx-c.x2)}),shades.left.css({width:px(c.x)})}function createShade(){return $("<div />").css({position:"absolute",backgroundColor:options.shadeColor||options.bgColor}).appendTo(holder)}function enableShade(){enabled||(enabled=!0,holder.insertBefore($img),updateAuto(),Selection.setBgOpacity(1,0,1),$img2.hide(),setBgColor(options.shadeColor||options.bgColor,1),Selection.isAwake()?setOpacity(options.bgOpacity,1):setOpacity(1,1))}function setBgColor(color,now){colorChangeMacro(getShades(),color,now)}function disableShade(){enabled&&(holder.remove(),$img2.show(),enabled=!1,Selection.isAwake()?Selection.setBgOpacity(options.bgOpacity,1,1):(Selection.setBgOpacity(1,1,1),Selection.disableHandles()),colorChangeMacro($div,0,1))}function setOpacity(opacity,now){enabled&&(options.bgFade&&!now?holder.animate({opacity:1-opacity},{queue:!1,duration:options.fadeTime}):holder.css({opacity:1-opacity}))}function refreshAll(){options.shade?enableShade():disableShade(),Selection.isAwake()&&setOpacity(options.bgOpacity)}function getShades(){return holder.children()}var enabled=!1,holder=$("<div />").css({position:"absolute",zIndex:240,opacity:0}),shades={top:createShade(),left:createShade().height(boundy),right:createShade().height(boundy),bottom:createShade()};return{update:updateAuto,updateRaw:updateShade,getShades:getShades,setBgColor:setBgColor,enable:enableShade,disable:disableShade,resize:resizeShades,refresh:refreshAll,opacity:setOpacity}}(),Selection=function(){function insertBorder(type){var jq=$("<div />").css({position:"absolute",opacity:options.borderOpacity}).addClass(cssClass(type));return $img_holder.append(jq),jq}function dragDiv(ord,zi){var jq=$("<div />").mousedown(createDragger(ord)).css({cursor:ord+"-resize",position:"absolute",zIndex:zi}).addClass("ord-"+ord);return Touch.support&&jq.bind("touchstart.jcrop",Touch.createDragger(ord)),$hdl_holder.append(jq),jq}function insertHandle(ord){var hs=options.handleSize,div=dragDiv(ord,hdep++).css({opacity:options.handleOpacity}).addClass(cssClass("handle"));return hs&&div.width(hs).height(hs),div}function insertDragbar(ord){return dragDiv(ord,hdep++).addClass("jcrop-dragbar")}function createDragbars(li){var i;for(i=0;i<li.length;i++)dragbar[li[i]]=insertDragbar(li[i])}function createBorders(li){var cl,i;for(i=0;i<li.length;i++){switch(li[i]){case"n":cl="hline";break;case"s":cl="hline bottom";break;case"e":cl="vline right";break;case"w":cl="vline"}borders[li[i]]=insertBorder(cl)}}function createHandles(li){var i;for(i=0;i<li.length;i++)handle[li[i]]=insertHandle(li[i])}function moveto(x,y){options.shade||$img2.css({top:px(-y),left:px(-x)}),$sel.css({top:px(y),left:px(x)})}function resize(w,h){$sel.width(Math.round(w)).height(Math.round(h))}function refresh(){var c=Coords.getFixed();Coords.setPressed([c.x,c.y]),Coords.setCurrent([c.x2,c.y2]),updateVisible()}function updateVisible(select){return awake?update(select):void 0}function update(select){var c=Coords.getFixed();resize(c.w,c.h),moveto(c.x,c.y),options.shade&&Shade.updateRaw(c),awake||show(),select?options.onSelect.call(api,unscale(c)):options.onChange.call(api,unscale(c))}function setBgOpacity(opacity,force,now){(awake||force)&&(options.bgFade&&!now?$img.animate({opacity:opacity},{queue:!1,duration:options.fadeTime}):$img.css("opacity",opacity))}function show(){$sel.show(),options.shade?Shade.opacity(bgopacity):setBgOpacity(bgopacity,!0),awake=!0}function release(){disableHandles(),$sel.hide(),options.shade?Shade.opacity(1):setBgOpacity(1),awake=!1,options.onRelease.call(api)}function showHandles(){seehandles&&$hdl_holder.show()}function enableHandles(){return seehandles=!0,options.allowResize?($hdl_holder.show(),!0):void 0}function disableHandles(){seehandles=!1,$hdl_holder.hide()}function animMode(v){v?(animating=!0,disableHandles()):(animating=!1,enableHandles())}function done(){animMode(!1),refresh()}var awake,hdep=370,borders={},handle={},dragbar={},seehandles=!1;options.dragEdges&&$.isArray(options.createDragbars)&&createDragbars(options.createDragbars),$.isArray(options.createHandles)&&createHandles(options.createHandles),options.drawBorders&&$.isArray(options.createBorders)&&createBorders(options.createBorders),$(document).bind("touchstart.jcrop-ios",function(e){$(e.currentTarget).hasClass("jcrop-tracker")&&e.stopPropagation()});var $track=newTracker().mousedown(createDragger("move")).css({cursor:"move",position:"absolute",zIndex:360});return Touch.support&&$track.bind("touchstart.jcrop",Touch.createDragger("move")),$img_holder.append($track),disableHandles(),{updateVisible:updateVisible,update:update,release:release,refresh:refresh,isAwake:function(){return awake},setCursor:function(cursor){$track.css("cursor",cursor)},enableHandles:enableHandles,enableOnly:function(){seehandles=!0},showHandles:showHandles,disableHandles:disableHandles,animMode:animMode,setBgOpacity:setBgOpacity,done:done}}(),Tracker=function(){function toFront(touch){$trk.css({zIndex:450}),touch?$(document).bind("touchmove.jcrop",trackTouchMove).bind("touchend.jcrop",trackTouchEnd):trackDoc&&$(document).bind("mousemove.jcrop",trackMove).bind("mouseup.jcrop",trackUp)}function toBack(){$trk.css({zIndex:290}),$(document).unbind(".jcrop")}function trackMove(e){return onMove(mouseAbs(e)),!1}function trackUp(e){return e.preventDefault(),e.stopPropagation(),btndown&&(btndown=!1,onDone(mouseAbs(e)),Selection.isAwake()&&options.onSelect.call(api,unscale(Coords.getFixed())),toBack(),onMove=function(){},onDone=function(){}),!1}function activateHandlers(move,done,touch){return btndown=!0,onMove=move,onDone=done,toFront(touch),!1}function trackTouchMove(e){return onMove(mouseAbs(Touch.cfilter(e))),!1}function trackTouchEnd(e){return trackUp(Touch.cfilter(e))}function setCursor(t){$trk.css("cursor",t)}var onMove=function(){},onDone=function(){},trackDoc=options.trackDocument;return trackDoc||$trk.mousemove(trackMove).mouseup(trackUp).mouseout(trackUp),$img.before($trk),{activateHandlers:activateHandlers,setCursor:setCursor}}(),KeyManager=function(){function watchKeys(){options.keySupport&&($keymgr.show(),$keymgr.focus())}function onBlur(){$keymgr.hide()}function doNudge(e,x,y){options.allowMove&&(Coords.moveOffset([x,y]),Selection.updateVisible(!0)),e.preventDefault(),e.stopPropagation()}function parseKey(e){if(e.ctrlKey||e.metaKey)return!0;shift_down=e.shiftKey?!0:!1;var nudge=shift_down?10:1;switch(e.keyCode){case 37:doNudge(e,-nudge,0);break;case 39:doNudge(e,nudge,0);break;case 38:doNudge(e,0,-nudge);break;case 40:doNudge(e,0,nudge);break;case 27:options.allowSelect&&Selection.release();break;case 9:return!0}return!1}var $keymgr=$('<input type="radio" />').css({position:"fixed",left:"-120px",width:"12px"}).addClass("jcrop-keymgr"),$keywrap=$("<div />").css({position:"absolute",overflow:"hidden"}).append($keymgr);return options.keySupport&&($keymgr.keydown(parseKey).blur(onBlur),ie6mode||!options.fixedSupport?($keymgr.css({position:"absolute",left:"-20px"}),$keywrap.append($keymgr).insertBefore($img)):$keymgr.insertBefore($img)),{watchKeys:watchKeys}}();Touch.support&&$trk.bind("touchstart.jcrop",Touch.newSelection),$hdl_holder.hide(),interfaceUpdate(!0);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(){return[boundx*xscale,boundy*yscale]},getWidgetSize:function(){return[boundx,boundy]},getScaleFactor:function(){return[xscale,yscale]},getOptions:function(){return options},ui:{holder:$div,selection:$sel}};return is_msie&&$div.bind("selectstart",function(){return!1}),$origimg.data("Jcrop",api),api},$.fn.Jcrop=function(options,callback){var api;return this.each(function(){if($(this).data("Jcrop")){if("api"===options)return $(this).data("Jcrop");$(this).data("Jcrop").setOptions(options)}else"IMG"==this.tagName?$.Jcrop.Loader(this,function(){$(this).css({display:"block",visibility:"hidden"}),api=$.Jcrop(this,options),$.isFunction(callback)&&callback.call(api)}):($(this).css({display:"block",visibility:"hidden"}),api=$.Jcrop(this,options),$.isFunction(callback)&&callback.call(api))}),this},$.Jcrop.Loader=function(imgobj,success,error){function completeCheck(){img.complete?($img.unbind(".jcloader"),$.isFunction(success)&&success.call(img)):window.setTimeout(completeCheck,50)}var $img=$(imgobj),img=$img[0];$img.bind("load.jcloader",completeCheck).bind("error.jcloader",function(){$img.unbind(".jcloader"),$.isFunction(error)&&error.call(img)}),img.complete&&$.isFunction(success)&&($img.unbind(".jcloader"),success.call(img))},$.Jcrop.defaults={allowSelect:!0,allowMove:!0,allowResize:!0,trackDocument:!0,baseClass:"jcrop",addClass:null,bgColor:"black",bgOpacity:.6,bgFade:!1,borderOpacity:.4,handleOpacity:.5,handleSize:null,aspectRatio:0,keySupport:!0,createHandles:["n","s","e","w","nw","ne","se","sw"],createDragbars:["n","s","e","w"],createBorders:["n","s","e","w"],drawBorders:!0,dragEdges:!0,fixedSupport:!0,touchSupport:null,shade:null,boxWidth:0,boxHeight:0,boundary:2,fadeTime:400,animationDelay:20,swingSpeed:3,minSelect:[0,0],maxSize:[0,0],minSize:[0,0],onChange:function(){},onSelect:function(){},onDblClick:function(){},onRelease:function(){}}}(jQuery);
@@ -1,28 +1,2 @@
1
- /* jquery.Jcrop.min.css v0.9.10 (build:20120429) */
2
- .jcrop-holder{direction:ltr;text-align:left;}
3
- .jcrop-vline,.jcrop-hline{background:#FFF image-url('Jcrop.gif') top left repeat;font-size:0;position:absolute;}
4
- .jcrop-vline{height:100%;width:1px!important;}
5
- .jcrop-hline{height:1px!important;width:100%;}
6
- .jcrop-vline.right{right:0;}
7
- .jcrop-hline.bottom{bottom:0;}
8
- .jcrop-handle{background-color:#333;border:1px #eee solid;font-size:1px;}
9
- .jcrop-tracker{-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none;-webkit-user-select:none;height:100%;width:100%;}
10
- .jcrop-handle.ord-n{left:50%;margin-left:-4px;margin-top:-4px;top:0;}
11
- .jcrop-handle.ord-s{bottom:0;left:50%;margin-bottom:-4px;margin-left:-4px;}
12
- .jcrop-handle.ord-e{margin-right:-4px;margin-top:-4px;right:0;top:50%;}
13
- .jcrop-handle.ord-w{left:0;margin-left:-4px;margin-top:-4px;top:50%;}
14
- .jcrop-handle.ord-nw{left:0;margin-left:-4px;margin-top:-4px;top:0;}
15
- .jcrop-handle.ord-ne{margin-right:-4px;margin-top:-4px;right:0;top:0;}
16
- .jcrop-handle.ord-se{bottom:0;margin-bottom:-4px;margin-right:-4px;right:0;}
17
- .jcrop-handle.ord-sw{bottom:0;left:0;margin-bottom:-4px;margin-left:-4px;}
18
- .jcrop-dragbar.ord-n,.jcrop-dragbar.ord-s{height:7px;width:100%;}
19
- .jcrop-dragbar.ord-e,.jcrop-dragbar.ord-w{height:100%;width:7px;}
20
- .jcrop-dragbar.ord-n{margin-top:-4px;}
21
- .jcrop-dragbar.ord-s{bottom:0;margin-bottom:-4px;}
22
- .jcrop-dragbar.ord-e{margin-right:-4px;right:0;}
23
- .jcrop-dragbar.ord-w{margin-left:-4px;}
24
- .jcrop-light .jcrop-vline,.jcrop-light .jcrop-hline{background:#FFF;filter:Alpha(opacity=70)!important;opacity:.70!important;}
25
- .jcrop-light .jcrop-handle{-moz-border-radius:3px;-webkit-border-radius:3px;background-color:#000;border-color:#FFF;border-radius:3px;}
26
- .jcrop-dark .jcrop-vline,.jcrop-dark .jcrop-hline{background:#000;filter:Alpha(opacity=70)!important;opacity:.7!important;}
27
- .jcrop-dark .jcrop-handle{-moz-border-radius:3px;-webkit-border-radius:3px;background-color:#FFF;border-color:#000;border-radius:3px;}
28
- .jcrop-holder img,img.jcrop-preview{max-width:none;}
1
+ /* jquery.Jcrop.min.css v0.9.15 (build:20180819) */
2
+ .jcrop-holder{direction:ltr;text-align:left;-ms-touch-action:none}.jcrop-hline,.jcrop-vline{background:#fff image-url("Jcrop.gif");font-size:0;position:absolute}.jcrop-vline{height:100%;width:1px!important}.jcrop-vline.right{right:0}.jcrop-hline{height:1px!important;width:100%}.jcrop-hline.bottom{bottom:0}.jcrop-tracker{height:100%;width:100%;-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none;-webkit-user-select:none}.jcrop-handle{background-color:#333;border:1px #eee solid;width:7px;height:7px;font-size:1px}.jcrop-handle.ord-n{left:50%;margin-left:-4px;margin-top:-4px;top:0}.jcrop-handle.ord-s{bottom:0;left:50%;margin-bottom:-4px;margin-left:-4px}.jcrop-handle.ord-e{margin-right:-4px;margin-top:-4px;right:0;top:50%}.jcrop-handle.ord-w{left:0;margin-left:-4px;margin-top:-4px;top:50%}.jcrop-handle.ord-nw{left:0;margin-left:-4px;margin-top:-4px;top:0}.jcrop-handle.ord-ne{margin-right:-4px;margin-top:-4px;right:0;top:0}.jcrop-handle.ord-se{bottom:0;margin-bottom:-4px;margin-right:-4px;right:0}.jcrop-handle.ord-sw{bottom:0;left:0;margin-bottom:-4px;margin-left:-4px}.jcrop-dragbar.ord-n,.jcrop-dragbar.ord-s{height:7px;width:100%}.jcrop-dragbar.ord-e,.jcrop-dragbar.ord-w{height:100%;width:7px}.jcrop-dragbar.ord-n{margin-top:-4px}.jcrop-dragbar.ord-s{bottom:0;margin-bottom:-4px}.jcrop-dragbar.ord-e{margin-right:-4px;right:0}.jcrop-dragbar.ord-w{margin-left:-4px}.jcrop-light .jcrop-hline,.jcrop-light .jcrop-vline{background:#fff;filter:alpha(opacity=70)!important;opacity:.7!important}.jcrop-light .jcrop-handle{-moz-border-radius:3px;-webkit-border-radius:3px;background-color:#000;border-color:#fff;border-radius:3px}.jcrop-dark .jcrop-hline,.jcrop-dark .jcrop-vline{background:#000;filter:alpha(opacity=70)!important;opacity:.7!important}.jcrop-dark .jcrop-handle{-moz-border-radius:3px;-webkit-border-radius:3px;background-color:#fff;border-color:#000;border-radius:3px}.solid-line .jcrop-hline,.solid-line .jcrop-vline{background:#fff}.jcrop-holder img,img.jcrop-preview{max-width:none}