keppler 2.1.17 → 2.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (571) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/installer/core/.gitignore +88 -0
  4. data/installer/core/app/views/admin/layouts/_sidebar.html.haml +2 -2
  5. data/installer/core/rockets/keppler_frontend/app/controllers/keppler_frontend/app/frontend_controller.rb +0 -1
  6. data/installer/core/rockets/keppler_frontend/app/models/keppler_frontend/view.rb +1 -1
  7. data/installer/core/rockets/keppler_frontend/config/data/views.yml +1 -1
  8. data/lib/keppler/version.rb +1 -1
  9. data/testing-with-2.1.18/.gitignore +88 -0
  10. data/testing-with-2.1.18/.ruby-version +1 -0
  11. data/testing-with-2.1.18/Gemfile +149 -0
  12. data/testing-with-2.1.18/Gemfile.lock +645 -0
  13. data/testing-with-2.1.18/Guardfile +18 -0
  14. data/testing-with-2.1.18/LICENSE +674 -0
  15. data/testing-with-2.1.18/README.md +134 -0
  16. data/testing-with-2.1.18/Rakefile +6 -0
  17. data/testing-with-2.1.18/_config.yml +1 -0
  18. data/testing-with-2.1.18/app/assets/images/.keep +0 -0
  19. data/testing-with-2.1.18/app/assets/images/admin/astronauta_keppler.svg +123 -0
  20. data/testing-with-2.1.18/app/assets/images/admin/avatar_keppler.svg +100 -0
  21. data/testing-with-2.1.18/app/assets/images/admin/en.png +0 -0
  22. data/testing-with-2.1.18/app/assets/images/admin/es.png +0 -0
  23. data/testing-with-2.1.18/app/assets/images/admin/favicon.png +0 -0
  24. data/testing-with-2.1.18/app/assets/images/admin/image_default.png +0 -0
  25. data/testing-with-2.1.18/app/assets/images/admin/logo.png +0 -0
  26. data/testing-with-2.1.18/app/assets/images/admin/logo2.png +0 -0
  27. data/testing-with-2.1.18/app/assets/images/admin/profile-menu.jpg +0 -0
  28. data/testing-with-2.1.18/app/assets/images/admin/search.png +0 -0
  29. data/testing-with-2.1.18/app/assets/images/admin/slice-icon-orange.png +0 -0
  30. data/testing-with-2.1.18/app/assets/images/admin/slice-icon.png +0 -0
  31. data/testing-with-2.1.18/app/assets/images/admin/slice.png +0 -0
  32. data/testing-with-2.1.18/app/assets/images/admin/slice_white.png +0 -0
  33. data/testing-with-2.1.18/app/assets/images/app/Cohete_nubes_new.png +0 -0
  34. data/testing-with-2.1.18/app/assets/images/app/Home_Keppler.png +0 -0
  35. data/testing-with-2.1.18/app/assets/images/app/Home_Keppler2.png +0 -0
  36. data/testing-with-2.1.18/app/assets/images/app/fondo.svg +19 -0
  37. data/testing-with-2.1.18/app/assets/images/app/keppler-front.png +0 -0
  38. data/testing-with-2.1.18/app/assets/images/app/slice-front.png +0 -0
  39. data/testing-with-2.1.18/app/assets/images/app/slice.png +0 -0
  40. data/testing-with-2.1.18/app/assets/javascripts/admin/application.coffee +25 -0
  41. data/testing-with-2.1.18/app/assets/javascripts/admin/bootstrap-colorpicker.js +1322 -0
  42. data/testing-with-2.1.18/app/assets/javascripts/admin/bootstrap-file-input/fileinput.js +4463 -0
  43. data/testing-with-2.1.18/app/assets/javascripts/admin/bootstrap-file-input/locales/LANG.js +100 -0
  44. data/testing-with-2.1.18/app/assets/javascripts/admin/bootstrap-file-input/locales/es.js +100 -0
  45. data/testing-with-2.1.18/app/assets/javascripts/admin/bootstrap-file-input/plugins/piexif.js +2471 -0
  46. data/testing-with-2.1.18/app/assets/javascripts/admin/bootstrap-file-input/plugins/piexif.min.js +1 -0
  47. data/testing-with-2.1.18/app/assets/javascripts/admin/bootstrap-file-input/plugins/purify.js +812 -0
  48. data/testing-with-2.1.18/app/assets/javascripts/admin/bootstrap-file-input/plugins/purify.min.js +1 -0
  49. data/testing-with-2.1.18/app/assets/javascripts/admin/bootstrap-file-input/plugins/sortable.js +1590 -0
  50. data/testing-with-2.1.18/app/assets/javascripts/admin/bootstrap-file-input/plugins/sortable.min.js +1 -0
  51. data/testing-with-2.1.18/app/assets/javascripts/admin/code_editor.js +94 -0
  52. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/comment/comment.js +209 -0
  53. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/comment/continuecomment.js +78 -0
  54. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/dialog/dialog.css +32 -0
  55. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/dialog/dialog.js +161 -0
  56. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/display/autorefresh.js +47 -0
  57. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/display/fullscreen.css +6 -0
  58. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/display/fullscreen.js +41 -0
  59. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/display/panel.js +123 -0
  60. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/display/placeholder.js +63 -0
  61. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/display/rulers.js +51 -0
  62. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/edit/closebrackets.js +194 -0
  63. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/edit/closetag.js +175 -0
  64. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/edit/continuelist.js +89 -0
  65. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/edit/matchbrackets.js +145 -0
  66. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/edit/matchtags.js +66 -0
  67. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/edit/trailingspace.js +27 -0
  68. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/fold/brace-fold.js +105 -0
  69. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/fold/comment-fold.js +59 -0
  70. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/fold/foldcode.js +152 -0
  71. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/fold/foldgutter.css +20 -0
  72. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/fold/foldgutter.js +146 -0
  73. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/fold/indent-fold.js +48 -0
  74. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/fold/markdown-fold.js +49 -0
  75. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/fold/xml-fold.js +184 -0
  76. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/hint/anyword-hint.js +41 -0
  77. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/hint/css-hint.js +60 -0
  78. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/hint/html-hint.js +348 -0
  79. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/hint/javascript-hint.js +157 -0
  80. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/hint/show-hint.css +36 -0
  81. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/hint/show-hint.js +433 -0
  82. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/hint/sql-hint.js +299 -0
  83. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/hint/xml-hint.js +110 -0
  84. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/mode/loadmode.js +64 -0
  85. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/mode/multiplex.js +131 -0
  86. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/mode/overlay.js +90 -0
  87. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/mode/simple.js +216 -0
  88. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/scroll/annotatescrollbar.js +122 -0
  89. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/scroll/scrollpastend.js +48 -0
  90. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/scroll/simplescrollbars.css +66 -0
  91. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/scroll/simplescrollbars.js +152 -0
  92. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/search/jump-to-line.js +49 -0
  93. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/search/match-highlighter.js +165 -0
  94. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/search/matchesonscrollbar.css +8 -0
  95. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/search/matchesonscrollbar.js +97 -0
  96. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/search/search.js +252 -0
  97. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/search/searchcursor.js +293 -0
  98. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/codemirror.js +9683 -0
  99. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/keymap/sublime.js +691 -0
  100. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/css/css.js +832 -0
  101. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/css/gss.html +103 -0
  102. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/css/index.html +75 -0
  103. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/css/less.html +152 -0
  104. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/css/scss.html +157 -0
  105. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/haml/haml.js +161 -0
  106. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/haml/index.html +79 -0
  107. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/htmlembedded/htmlembedded.js +37 -0
  108. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/htmlembedded/index.html +60 -0
  109. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/htmlmixed/htmlmixed.js +152 -0
  110. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/htmlmixed/index.html +100 -0
  111. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/javascript/index.html +114 -0
  112. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/javascript/javascript.js +896 -0
  113. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/javascript/json-ld.html +72 -0
  114. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/javascript/typescript.html +61 -0
  115. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/ruby/index.html +183 -0
  116. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/ruby/ruby.js +296 -0
  117. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/vue/index.html +69 -0
  118. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/vue/vue.js +77 -0
  119. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/xml/index.html +61 -0
  120. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/xml/xml.js +402 -0
  121. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/yaml-frontmatter/index.html +121 -0
  122. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/yaml-frontmatter/yaml-frontmatter.js +68 -0
  123. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/yaml/index.html +80 -0
  124. data/testing-with-2.1.18/app/assets/javascripts/admin/codemirror/mode/yaml/yaml.js +119 -0
  125. data/testing-with-2.1.18/app/assets/javascripts/admin/file_uploader.coffee +152 -0
  126. data/testing-with-2.1.18/app/assets/javascripts/admin/img_preview.js +32 -0
  127. data/testing-with-2.1.18/app/assets/javascripts/admin/jscolor.js +1855 -0
  128. data/testing-with-2.1.18/app/assets/javascripts/admin/main.coffee +58 -0
  129. data/testing-with-2.1.18/app/assets/javascripts/admin/notification.js +14 -0
  130. data/testing-with-2.1.18/app/assets/javascripts/admin/ruby_console.js +14 -0
  131. data/testing-with-2.1.18/app/assets/javascripts/admin/sidebar.js +24 -0
  132. data/testing-with-2.1.18/app/assets/javascripts/admin/sort.coffee +8 -0
  133. data/testing-with-2.1.18/app/assets/javascripts/admin/swal.js +39 -0
  134. data/testing-with-2.1.18/app/assets/javascripts/admin/sweetalert2/delete-confirm.js +118 -0
  135. data/testing-with-2.1.18/app/assets/javascripts/admin/sweetalert2/sweetalert2.all.min.js +2 -0
  136. data/testing-with-2.1.18/app/assets/javascripts/admin/switch.js +6 -0
  137. data/testing-with-2.1.18/app/assets/javascripts/admin/tooltips.coffee +4 -0
  138. data/testing-with-2.1.18/app/assets/javascripts/admin/upload_records.coffee +8 -0
  139. data/testing-with-2.1.18/app/assets/javascripts/app/application.js.coffee +9 -0
  140. data/testing-with-2.1.18/app/assets/javascripts/app/google_analytics.js.coffee +5 -0
  141. data/testing-with-2.1.18/app/assets/javascripts/ckeditor/config.js +130 -0
  142. data/testing-with-2.1.18/app/assets/javascripts/errors/application.js.coffee +1 -0
  143. data/testing-with-2.1.18/app/assets/javascripts/errors/errors.js +113 -0
  144. data/testing-with-2.1.18/app/assets/javascripts/vue_admin/index.js +111 -0
  145. data/testing-with-2.1.18/app/assets/stylesheets/admin/application.scss +48 -0
  146. data/testing-with-2.1.18/app/assets/stylesheets/admin/bootstrap-file-input/fileinput-rtl.scss +133 -0
  147. data/testing-with-2.1.18/app/assets/stylesheets/admin/bootstrap-file-input/fileinput.scss +760 -0
  148. data/testing-with-2.1.18/app/assets/stylesheets/admin/bootstrap-file-input/themes/explorer-fa/theme.scss +213 -0
  149. data/testing-with-2.1.18/app/assets/stylesheets/admin/bootstrap-file-input/themes/explorer-fas/theme.scss +213 -0
  150. data/testing-with-2.1.18/app/assets/stylesheets/admin/bootstrap-file-input/themes/explorer/theme.scss +213 -0
  151. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/comment/comment.js +209 -0
  152. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/comment/continuecomment.js +78 -0
  153. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/dialog/dialog.css +32 -0
  154. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/dialog/dialog.js +161 -0
  155. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/display/autorefresh.js +47 -0
  156. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/display/fullscreen.css +6 -0
  157. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/display/fullscreen.js +41 -0
  158. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/display/panel.js +123 -0
  159. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/display/placeholder.js +63 -0
  160. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/display/rulers.js +51 -0
  161. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/edit/closebrackets.js +194 -0
  162. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/edit/closetag.js +175 -0
  163. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/edit/continuelist.js +89 -0
  164. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/edit/matchbrackets.js +145 -0
  165. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/edit/matchtags.js +66 -0
  166. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/edit/trailingspace.js +27 -0
  167. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/fold/brace-fold.js +105 -0
  168. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/fold/comment-fold.js +59 -0
  169. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/fold/foldcode.js +152 -0
  170. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/fold/foldgutter.css +20 -0
  171. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/fold/foldgutter.js +146 -0
  172. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/fold/indent-fold.js +48 -0
  173. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/fold/markdown-fold.js +49 -0
  174. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/fold/xml-fold.js +184 -0
  175. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/hint/anyword-hint.js +41 -0
  176. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/hint/css-hint.js +60 -0
  177. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/hint/html-hint.js +348 -0
  178. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/hint/javascript-hint.js +157 -0
  179. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/hint/show-hint.css +36 -0
  180. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/hint/show-hint.js +433 -0
  181. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/hint/sql-hint.js +299 -0
  182. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/hint/xml-hint.js +110 -0
  183. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/scroll/annotatescrollbar.js +122 -0
  184. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/scroll/scrollpastend.js +48 -0
  185. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/scroll/simplescrollbars.css +66 -0
  186. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/scroll/simplescrollbars.js +152 -0
  187. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/search/jump-to-line.js +49 -0
  188. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/search/match-highlighter.js +165 -0
  189. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/search/matchesonscrollbar.css +8 -0
  190. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/search/matchesonscrollbar.js +97 -0
  191. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/search/search.js +252 -0
  192. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/search/searchcursor.js +293 -0
  193. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/codemirror.css +366 -0
  194. data/testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/theme/monokai.css +41 -0
  195. data/testing-with-2.1.18/app/assets/stylesheets/admin/components/layouts/_footer.scss +5 -0
  196. data/testing-with-2.1.18/app/assets/stylesheets/admin/components/layouts/_settings.scss +51 -0
  197. data/testing-with-2.1.18/app/assets/stylesheets/admin/components/navigation/_navbar.scss +187 -0
  198. data/testing-with-2.1.18/app/assets/stylesheets/admin/components/navigation/_sidebar.scss +207 -0
  199. data/testing-with-2.1.18/app/assets/stylesheets/admin/components/navigation/_turbolinks.scss +4 -0
  200. data/testing-with-2.1.18/app/assets/stylesheets/admin/components/paginator/_paginator.scss +53 -0
  201. data/testing-with-2.1.18/app/assets/stylesheets/admin/fonts-and-icons/ZXuke1cDvLCKLDcimxB44_lu.woff2 +0 -0
  202. data/testing-with-2.1.18/app/assets/stylesheets/admin/fonts-and-icons/boxicons.css +2918 -0
  203. data/testing-with-2.1.18/app/assets/stylesheets/admin/fonts-and-icons/fonts.css +8 -0
  204. data/testing-with-2.1.18/app/assets/stylesheets/admin/fonts-and-icons/fonts/Simple-Line-Icons.eot +0 -0
  205. data/testing-with-2.1.18/app/assets/stylesheets/admin/fonts-and-icons/fonts/Simple-Line-Icons.ttf +0 -0
  206. data/testing-with-2.1.18/app/assets/stylesheets/admin/fonts-and-icons/fonts/Simple-Line-Icons.woff +0 -0
  207. data/testing-with-2.1.18/app/assets/stylesheets/admin/fonts-and-icons/fonts/Simple-Line-Icons.woff2 +0 -0
  208. data/testing-with-2.1.18/app/assets/stylesheets/admin/fonts-and-icons/fonts/boxicons.eot +0 -0
  209. data/testing-with-2.1.18/app/assets/stylesheets/admin/fonts-and-icons/fonts/boxicons.svg +808 -0
  210. data/testing-with-2.1.18/app/assets/stylesheets/admin/fonts-and-icons/fonts/boxicons.ttf +0 -0
  211. data/testing-with-2.1.18/app/assets/stylesheets/admin/fonts-and-icons/fonts/boxicons.woff +0 -0
  212. data/testing-with-2.1.18/app/assets/stylesheets/admin/fonts-and-icons/fonts/boxicons.woff2 +0 -0
  213. data/testing-with-2.1.18/app/assets/stylesheets/admin/fonts-and-icons/icons.css +778 -0
  214. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_appearance.scss +5 -0
  215. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_bootstrap-colorpicker.scss +269 -0
  216. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_customize.scss +22 -0
  217. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_datepicker.scss +1086 -0
  218. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_devise.scss +189 -0
  219. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_files.scss +229 -0
  220. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_form.scss +190 -0
  221. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_index.scss +466 -0
  222. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_listing.scss +40 -0
  223. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_preloader.scss +224 -0
  224. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_rockets.scss +13 -0
  225. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_roles.scss +3 -0
  226. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_search.scss +244 -0
  227. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_show.scss +23 -0
  228. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_switchs.scss +143 -0
  229. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_themes.scss +45 -0
  230. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_timepicker.scss +14 -0
  231. data/testing-with-2.1.18/app/assets/stylesheets/admin/pages/_user.scss +6 -0
  232. data/testing-with-2.1.18/app/assets/stylesheets/admin/utils/_base.scss +65 -0
  233. data/testing-with-2.1.18/app/assets/stylesheets/admin/utils/_mixins.scss +26 -0
  234. data/testing-with-2.1.18/app/assets/stylesheets/admin/utils/_theme.scss +124 -0
  235. data/testing-with-2.1.18/app/assets/stylesheets/admin/utils/_variables.scss +109 -0
  236. data/testing-with-2.1.18/app/assets/stylesheets/app/application.scss +30 -0
  237. data/testing-with-2.1.18/app/assets/stylesheets/app/base/_base_project.scss +17 -0
  238. data/testing-with-2.1.18/app/assets/stylesheets/app/base/_typography.scss +1 -0
  239. data/testing-with-2.1.18/app/assets/stylesheets/app/components/_buttons.scss +0 -0
  240. data/testing-with-2.1.18/app/assets/stylesheets/app/components/_inputs.scss +0 -0
  241. data/testing-with-2.1.18/app/assets/stylesheets/app/components/_navbar.scss +21 -0
  242. data/testing-with-2.1.18/app/assets/stylesheets/app/layout/_container.scss +0 -0
  243. data/testing-with-2.1.18/app/assets/stylesheets/app/layout/_footer.scss +15 -0
  244. data/testing-with-2.1.18/app/assets/stylesheets/app/layout/_header.scss +39 -0
  245. data/testing-with-2.1.18/app/assets/stylesheets/app/pages/_front.sass +83 -0
  246. data/testing-with-2.1.18/app/assets/stylesheets/app/plugins/_bootstrap_override.scss +37 -0
  247. data/testing-with-2.1.18/app/assets/stylesheets/app/plugins/_font_awesome.scss +2 -0
  248. data/testing-with-2.1.18/app/assets/stylesheets/app/plugins/_keppler.scss +161 -0
  249. data/testing-with-2.1.18/app/assets/stylesheets/app/plugins/_npogress.scss +2 -0
  250. data/testing-with-2.1.18/app/assets/stylesheets/app/utils/_mixins.scss +18 -0
  251. data/testing-with-2.1.18/app/assets/stylesheets/app/utils/_variables.scss +28 -0
  252. data/testing-with-2.1.18/app/assets/stylesheets/errors/application.scss +3 -0
  253. data/testing-with-2.1.18/app/assets/stylesheets/errors/errors.scss +161 -0
  254. data/testing-with-2.1.18/app/assets/stylesheets/vendor/admin-lte/_skin-blue.scss +141 -0
  255. data/testing-with-2.1.18/app/assets/stylesheets/vendor/sweetalert2/sweetalert2.scss +11 -0
  256. data/testing-with-2.1.18/app/controllers/admin/admin_controller.rb +95 -0
  257. data/testing-with-2.1.18/app/controllers/admin/meta_tags_controller.rb +118 -0
  258. data/testing-with-2.1.18/app/controllers/admin/permissions_controller.rb +55 -0
  259. data/testing-with-2.1.18/app/controllers/admin/rockets_controller.rb +95 -0
  260. data/testing-with-2.1.18/app/controllers/admin/roles_controller.rb +124 -0
  261. data/testing-with-2.1.18/app/controllers/admin/scripts_controller.rb +104 -0
  262. data/testing-with-2.1.18/app/controllers/admin/seos_controller.rb +31 -0
  263. data/testing-with-2.1.18/app/controllers/admin/settings_controller.rb +131 -0
  264. data/testing-with-2.1.18/app/controllers/admin/users_controller.rb +122 -0
  265. data/testing-with-2.1.18/app/controllers/app/app_controller.rb +38 -0
  266. data/testing-with-2.1.18/app/controllers/app/front_controller.rb +8 -0
  267. data/testing-with-2.1.18/app/controllers/application_controller.rb +151 -0
  268. data/testing-with-2.1.18/app/controllers/concerns/.keep +0 -0
  269. data/testing-with-2.1.18/app/controllers/concerns/devise_params.rb +33 -0
  270. data/testing-with-2.1.18/app/controllers/concerns/mailer_config.rb +37 -0
  271. data/testing-with-2.1.18/app/controllers/concerns/object_query.rb +50 -0
  272. data/testing-with-2.1.18/app/controllers/concerns/settings.rb +105 -0
  273. data/testing-with-2.1.18/app/controllers/devise/sessions_controller.rb +108 -0
  274. data/testing-with-2.1.18/app/controllers/errors_controller.rb +30 -0
  275. data/testing-with-2.1.18/app/helpers/admin_helper.rb +138 -0
  276. data/testing-with-2.1.18/app/helpers/application_helper.rb +33 -0
  277. data/testing-with-2.1.18/app/helpers/fronts_helper.rb +38 -0
  278. data/testing-with-2.1.18/app/helpers/rockets_helper.rb +8 -0
  279. data/testing-with-2.1.18/app/helpers/roles_helper.rb +5 -0
  280. data/testing-with-2.1.18/app/helpers/scaffolds_helper.rb +5 -0
  281. data/testing-with-2.1.18/app/inputs/keppler_boolean_input.rb +52 -0
  282. data/testing-with-2.1.18/app/inputs/keppler_file_input.rb +124 -0
  283. data/testing-with-2.1.18/app/mailers/.keep +0 -0
  284. data/testing-with-2.1.18/app/mailers/application_mailer.rb +42 -0
  285. data/testing-with-2.1.18/app/models/.keep +0 -0
  286. data/testing-with-2.1.18/app/models/appearance.rb +7 -0
  287. data/testing-with-2.1.18/app/models/application_record.rb +6 -0
  288. data/testing-with-2.1.18/app/models/concerns/.keep +0 -0
  289. data/testing-with-2.1.18/app/models/concerns/activity_history.rb +11 -0
  290. data/testing-with-2.1.18/app/models/concerns/clone_record.rb +14 -0
  291. data/testing-with-2.1.18/app/models/concerns/downloadable.rb +16 -0
  292. data/testing-with-2.1.18/app/models/concerns/searchable.rb +27 -0
  293. data/testing-with-2.1.18/app/models/concerns/sortable.rb +13 -0
  294. data/testing-with-2.1.18/app/models/concerns/uploadable.rb +13 -0
  295. data/testing-with-2.1.18/app/models/front.rb +5 -0
  296. data/testing-with-2.1.18/app/models/google_analytics_setting.rb +6 -0
  297. data/testing-with-2.1.18/app/models/meta_tag.rb +54 -0
  298. data/testing-with-2.1.18/app/models/permission.rb +6 -0
  299. data/testing-with-2.1.18/app/models/rocket.rb +105 -0
  300. data/testing-with-2.1.18/app/models/role.rb +134 -0
  301. data/testing-with-2.1.18/app/models/script.rb +21 -0
  302. data/testing-with-2.1.18/app/models/seo.rb +49 -0
  303. data/testing-with-2.1.18/app/models/setting.rb +19 -0
  304. data/testing-with-2.1.18/app/models/smtp_setting.rb +7 -0
  305. data/testing-with-2.1.18/app/models/social_account.rb +6 -0
  306. data/testing-with-2.1.18/app/models/user.rb +75 -0
  307. data/testing-with-2.1.18/app/policies/application_policy.rb +18 -0
  308. data/testing-with-2.1.18/app/policies/controller_policy.rb +59 -0
  309. data/testing-with-2.1.18/app/policies/meta_tag_policy.rb +11 -0
  310. data/testing-with-2.1.18/app/policies/permission_policy.rb +23 -0
  311. data/testing-with-2.1.18/app/policies/rocket_policy.rb +11 -0
  312. data/testing-with-2.1.18/app/policies/role_policy.rb +31 -0
  313. data/testing-with-2.1.18/app/policies/script_policy.rb +11 -0
  314. data/testing-with-2.1.18/app/policies/seo_policy.rb +23 -0
  315. data/testing-with-2.1.18/app/policies/setting_policy.rb +15 -0
  316. data/testing-with-2.1.18/app/policies/user_policy.rb +19 -0
  317. data/testing-with-2.1.18/app/services/admin/appearance_service.rb +49 -0
  318. data/testing-with-2.1.18/app/services/admin/git_handler.rb +28 -0
  319. data/testing-with-2.1.18/app/uploaders/attachment_uploader.rb +61 -0
  320. data/testing-with-2.1.18/app/uploaders/ckeditor_attachment_file_uploader.rb +38 -0
  321. data/testing-with-2.1.18/app/uploaders/ckeditor_picture_uploader.rb +49 -0
  322. data/testing-with-2.1.18/app/uploaders/template_uploader.rb +44 -0
  323. data/testing-with-2.1.18/app/views/admin/layouts/_footer.html.haml +0 -0
  324. data/testing-with-2.1.18/app/views/admin/layouts/_git_info.html.haml +13 -0
  325. data/testing-with-2.1.18/app/views/admin/layouts/_head.html.haml +7 -0
  326. data/testing-with-2.1.18/app/views/admin/layouts/_keppler_boolean_script.haml +12 -0
  327. data/testing-with-2.1.18/app/views/admin/layouts/_listing_preloader.haml +4 -0
  328. data/testing-with-2.1.18/app/views/admin/layouts/_messages.html.haml +4 -0
  329. data/testing-with-2.1.18/app/views/admin/layouts/_navigation.html.haml +59 -0
  330. data/testing-with-2.1.18/app/views/admin/layouts/_preloader.html.haml +14 -0
  331. data/testing-with-2.1.18/app/views/admin/layouts/_sidebar.html.haml +83 -0
  332. data/testing-with-2.1.18/app/views/admin/layouts/application.html.haml +23 -0
  333. data/testing-with-2.1.18/app/views/admin/layouts/index/remote_messages.js.haml +9 -0
  334. data/testing-with-2.1.18/app/views/admin/meta_tags/_description.html.haml +13 -0
  335. data/testing-with-2.1.18/app/views/admin/meta_tags/_form.html.haml +35 -0
  336. data/testing-with-2.1.18/app/views/admin/meta_tags/_listing.html.haml +40 -0
  337. data/testing-with-2.1.18/app/views/admin/meta_tags/edit.html.haml +2 -0
  338. data/testing-with-2.1.18/app/views/admin/meta_tags/index.html.haml +69 -0
  339. data/testing-with-2.1.18/app/views/admin/meta_tags/new.html.haml +2 -0
  340. data/testing-with-2.1.18/app/views/admin/meta_tags/reload.js.haml +5 -0
  341. data/testing-with-2.1.18/app/views/admin/meta_tags/show.html.haml +28 -0
  342. data/testing-with-2.1.18/app/views/admin/permissions/_switch.html.haml +13 -0
  343. data/testing-with-2.1.18/app/views/admin/permissions/add.html.haml +95 -0
  344. data/testing-with-2.1.18/app/views/admin/permissions/create.html.haml +0 -0
  345. data/testing-with-2.1.18/app/views/admin/permissions/create.js.erb +2 -0
  346. data/testing-with-2.1.18/app/views/admin/permissions/show.js.erb +2 -0
  347. data/testing-with-2.1.18/app/views/admin/permissions/toggle_permissions.js.erb +6 -0
  348. data/testing-with-2.1.18/app/views/admin/rockets/_create_rocket.haml +61 -0
  349. data/testing-with-2.1.18/app/views/admin/rockets/_install_rocket.haml +28 -0
  350. data/testing-with-2.1.18/app/views/admin/rockets/rockets.haml +54 -0
  351. data/testing-with-2.1.18/app/views/admin/roles/_description.html.haml +13 -0
  352. data/testing-with-2.1.18/app/views/admin/roles/_form.html.haml +27 -0
  353. data/testing-with-2.1.18/app/views/admin/roles/_listing.html.haml +42 -0
  354. data/testing-with-2.1.18/app/views/admin/roles/_switch.html.haml +24 -0
  355. data/testing-with-2.1.18/app/views/admin/roles/edit.html.haml +1 -0
  356. data/testing-with-2.1.18/app/views/admin/roles/index.html.haml +64 -0
  357. data/testing-with-2.1.18/app/views/admin/roles/new.html.haml +1 -0
  358. data/testing-with-2.1.18/app/views/admin/roles/reload.js.haml +5 -0
  359. data/testing-with-2.1.18/app/views/admin/roles/show.html.haml +29 -0
  360. data/testing-with-2.1.18/app/views/admin/scripts/_description.html.haml +13 -0
  361. data/testing-with-2.1.18/app/views/admin/scripts/_form.html.haml +30 -0
  362. data/testing-with-2.1.18/app/views/admin/scripts/_listing.html.haml +40 -0
  363. data/testing-with-2.1.18/app/views/admin/scripts/edit.html.haml +1 -0
  364. data/testing-with-2.1.18/app/views/admin/scripts/index.html.haml +70 -0
  365. data/testing-with-2.1.18/app/views/admin/scripts/new.html.haml +1 -0
  366. data/testing-with-2.1.18/app/views/admin/scripts/reload.js.haml +5 -0
  367. data/testing-with-2.1.18/app/views/admin/scripts/show.html.haml +28 -0
  368. data/testing-with-2.1.18/app/views/admin/seos/robots.html.haml +35 -0
  369. data/testing-with-2.1.18/app/views/admin/seos/sitemap.html.haml +36 -0
  370. data/testing-with-2.1.18/app/views/admin/settings/_form.html.haml +10 -0
  371. data/testing-with-2.1.18/app/views/admin/settings/components/_preview.html.haml +30 -0
  372. data/testing-with-2.1.18/app/views/admin/settings/edit.html.haml +4 -0
  373. data/testing-with-2.1.18/app/views/admin/settings/fields/_appearance.html.haml +64 -0
  374. data/testing-with-2.1.18/app/views/admin/settings/fields/_basic_information.html.haml +40 -0
  375. data/testing-with-2.1.18/app/views/admin/settings/fields/_email_setting.html.haml +18 -0
  376. data/testing-with-2.1.18/app/views/admin/settings/fields/_google_analytics_setting.html.haml +21 -0
  377. data/testing-with-2.1.18/app/views/admin/settings/fields/_social_accounts.html.haml +43 -0
  378. data/testing-with-2.1.18/app/views/admin/users/_description.html.haml +13 -0
  379. data/testing-with-2.1.18/app/views/admin/users/_form.html.haml +45 -0
  380. data/testing-with-2.1.18/app/views/admin/users/_listing.html.haml +47 -0
  381. data/testing-with-2.1.18/app/views/admin/users/delete_avatar.js.haml +3 -0
  382. data/testing-with-2.1.18/app/views/admin/users/edit.html.haml +1 -0
  383. data/testing-with-2.1.18/app/views/admin/users/filter_by_role.js.erb +9 -0
  384. data/testing-with-2.1.18/app/views/admin/users/index.html.haml +69 -0
  385. data/testing-with-2.1.18/app/views/admin/users/new.html.haml +1 -0
  386. data/testing-with-2.1.18/app/views/admin/users/reload.js.haml +5 -0
  387. data/testing-with-2.1.18/app/views/admin/users/show.html.haml +34 -0
  388. data/testing-with-2.1.18/app/views/app/front/index.html.haml +223 -0
  389. data/testing-with-2.1.18/app/views/app/front/message.haml +1 -0
  390. data/testing-with-2.1.18/app/views/app/layouts/_footer.html.haml +3 -0
  391. data/testing-with-2.1.18/app/views/app/layouts/_google_analytics.html.haml +13 -0
  392. data/testing-with-2.1.18/app/views/app/layouts/_head.html.haml +15 -0
  393. data/testing-with-2.1.18/app/views/app/layouts/_messages.html.haml +6 -0
  394. data/testing-with-2.1.18/app/views/app/layouts/_meta_tags.html.haml +40 -0
  395. data/testing-with-2.1.18/app/views/app/layouts/_navigation.html.haml +13 -0
  396. data/testing-with-2.1.18/app/views/app/layouts/_navigation_links.html.haml +6 -0
  397. data/testing-with-2.1.18/app/views/app/layouts/application.html.haml +10 -0
  398. data/testing-with-2.1.18/app/views/application_mailer/testing.html.haml +1 -0
  399. data/testing-with-2.1.18/app/views/devise/confirmations/new.html.erb +16 -0
  400. data/testing-with-2.1.18/app/views/devise/mailer/reset_password_instructions.html.haml +6 -0
  401. data/testing-with-2.1.18/app/views/devise/passwords/edit.html.haml +31 -0
  402. data/testing-with-2.1.18/app/views/devise/passwords/new.html.haml +27 -0
  403. data/testing-with-2.1.18/app/views/devise/registrations/edit.html.erb +48 -0
  404. data/testing-with-2.1.18/app/views/devise/registrations/new.html.erb +19 -0
  405. data/testing-with-2.1.18/app/views/devise/sessions/new.html.haml +35 -0
  406. data/testing-with-2.1.18/app/views/devise/shared/_links.html.erb +21 -0
  407. data/testing-with-2.1.18/app/views/errors/internal_server_error.html.haml +50 -0
  408. data/testing-with-2.1.18/app/views/errors/not_authorized.html.haml +76 -0
  409. data/testing-with-2.1.18/app/views/errors/not_found.html.haml +101 -0
  410. data/testing-with-2.1.18/app/views/errors/unprocessable.html.haml +50 -0
  411. data/testing-with-2.1.18/app/views/kaminari/_first_page.html.haml +11 -0
  412. data/testing-with-2.1.18/app/views/kaminari/_gap.html.haml +8 -0
  413. data/testing-with-2.1.18/app/views/kaminari/_last_page.html.haml +11 -0
  414. data/testing-with-2.1.18/app/views/kaminari/_next_page.html.haml +11 -0
  415. data/testing-with-2.1.18/app/views/kaminari/_page.html.haml +10 -0
  416. data/testing-with-2.1.18/app/views/kaminari/_paginator.html.haml +18 -0
  417. data/testing-with-2.1.18/app/views/kaminari/_prev_page.html.haml +11 -0
  418. data/testing-with-2.1.18/app/views/layouts/errors/_head.html.haml +3 -0
  419. data/testing-with-2.1.18/app/views/layouts/errors/application.html.haml +11 -0
  420. data/testing-with-2.1.18/app/views/layouts/mailers/mailer.html.haml +3 -0
  421. data/testing-with-2.1.18/app/views/layouts/mailers/mailer.text.haml +1 -0
  422. data/testing-with-2.1.18/app/views/layouts/templates/application.html.haml +1 -0
  423. data/testing-with-2.1.18/app/views/public_activity/layout/_create.html.haml +44 -0
  424. data/testing-with-2.1.18/app/views/public_activity/layout/_destroy.html.haml +15 -0
  425. data/testing-with-2.1.18/app/views/public_activity/layout/_update.html.haml +44 -0
  426. data/testing-with-2.1.18/app/views/public_activity/session/_create.html.haml +13 -0
  427. data/testing-with-2.1.18/app/views/public_activity/session/_destroy.html.haml +13 -0
  428. data/testing-with-2.1.18/app/views/templates/kaminari/_first_page.html.haml +9 -0
  429. data/testing-with-2.1.18/app/views/templates/kaminari/_gap.html.haml +8 -0
  430. data/testing-with-2.1.18/app/views/templates/kaminari/_last_page.html.haml +9 -0
  431. data/testing-with-2.1.18/app/views/templates/kaminari/_next_page.html.haml +9 -0
  432. data/testing-with-2.1.18/app/views/templates/kaminari/_page.html.haml +10 -0
  433. data/testing-with-2.1.18/app/views/templates/kaminari/_paginator.html.haml +18 -0
  434. data/testing-with-2.1.18/app/views/templates/kaminari/_prev_page.html.haml +9 -0
  435. data/testing-with-2.1.18/bin/bundle +3 -0
  436. data/testing-with-2.1.18/bin/rails +4 -0
  437. data/testing-with-2.1.18/bin/rake +4 -0
  438. data/testing-with-2.1.18/bin/setup +29 -0
  439. data/testing-with-2.1.18/bin/spring +15 -0
  440. data/testing-with-2.1.18/bin/update +31 -0
  441. data/testing-with-2.1.18/bin/yarn +11 -0
  442. data/testing-with-2.1.18/config.ru +4 -0
  443. data/testing-with-2.1.18/config/application.rb +46 -0
  444. data/testing-with-2.1.18/config/attachments.yml +24 -0
  445. data/testing-with-2.1.18/config/boot.rb +7 -0
  446. data/testing-with-2.1.18/config/circleci/db_config.yml +51 -0
  447. data/testing-with-2.1.18/config/database.yml +25 -0
  448. data/testing-with-2.1.18/config/environment.rb +10 -0
  449. data/testing-with-2.1.18/config/environments/development.rb +61 -0
  450. data/testing-with-2.1.18/config/environments/production.rb +109 -0
  451. data/testing-with-2.1.18/config/environments/test.rb +45 -0
  452. data/testing-with-2.1.18/config/gaAuth/gauth_key.p12 +0 -0
  453. data/testing-with-2.1.18/config/initializers/assets.rb +14 -0
  454. data/testing-with-2.1.18/config/initializers/carrierwave.rb +12 -0
  455. data/testing-with-2.1.18/config/initializers/compression.rb +47 -0
  456. data/testing-with-2.1.18/config/initializers/cookies_serializer.rb +3 -0
  457. data/testing-with-2.1.18/config/initializers/date_formats.rb +2 -0
  458. data/testing-with-2.1.18/config/initializers/devise.rb +259 -0
  459. data/testing-with-2.1.18/config/initializers/filter_parameter_logging.rb +5 -0
  460. data/testing-with-2.1.18/config/initializers/inflections.rb +16 -0
  461. data/testing-with-2.1.18/config/initializers/keppler_configuration.rb +9 -0
  462. data/testing-with-2.1.18/config/initializers/mime_types.rb +6 -0
  463. data/testing-with-2.1.18/config/initializers/paginate_kaminari_configuration.rb +12 -0
  464. data/testing-with-2.1.18/config/initializers/ransack.rb +7 -0
  465. data/testing-with-2.1.18/config/initializers/rolify.rb +10 -0
  466. data/testing-with-2.1.18/config/initializers/route_traslator.rb +3 -0
  467. data/testing-with-2.1.18/config/initializers/session_store.rb +5 -0
  468. data/testing-with-2.1.18/config/initializers/simple_form.rb +170 -0
  469. data/testing-with-2.1.18/config/initializers/simple_form_bootstrap.rb +174 -0
  470. data/testing-with-2.1.18/config/initializers/simple_form_components.rb +61 -0
  471. data/testing-with-2.1.18/config/initializers/time_formats.rb +2 -0
  472. data/testing-with-2.1.18/config/initializers/wrap_parameters.rb +15 -0
  473. data/testing-with-2.1.18/config/jshint.yml +21 -0
  474. data/testing-with-2.1.18/config/locales/devise.en.yml +61 -0
  475. data/testing-with-2.1.18/config/locales/devise.es.yml +62 -0
  476. data/testing-with-2.1.18/config/locales/en.yml +477 -0
  477. data/testing-with-2.1.18/config/locales/es.yml +510 -0
  478. data/testing-with-2.1.18/config/locales/routes.en.yml +4 -0
  479. data/testing-with-2.1.18/config/locales/routes.es.yml +5 -0
  480. data/testing-with-2.1.18/config/locales/simple_form.en.yml +46 -0
  481. data/testing-with-2.1.18/config/locales/simple_form.es.yml +96 -0
  482. data/testing-with-2.1.18/config/locales/social_share_button.es.yml +10 -0
  483. data/testing-with-2.1.18/config/menu.yml +58 -0
  484. data/testing-with-2.1.18/config/permissions.yml +39 -0
  485. data/testing-with-2.1.18/config/puma.rb +56 -0
  486. data/testing-with-2.1.18/config/roles.yml +2 -0
  487. data/testing-with-2.1.18/config/routes.rb +191 -0
  488. data/testing-with-2.1.18/config/settings.yml +30 -0
  489. data/testing-with-2.1.18/config/sitemap.rb +30 -0
  490. data/testing-with-2.1.18/config/spring.rb +6 -0
  491. data/testing-with-2.1.18/db/migrate/20140812203549_devise_create_users.rb +50 -0
  492. data/testing-with-2.1.18/db/migrate/20140812210925_rolify_create_roles.rb +21 -0
  493. data/testing-with-2.1.18/db/migrate/20151221173228_create_activities.rb +23 -0
  494. data/testing-with-2.1.18/db/migrate/20160122201215_create_settings.rb +15 -0
  495. data/testing-with-2.1.18/db/migrate/20160126141856_create_smtp_settings.rb +15 -0
  496. data/testing-with-2.1.18/db/migrate/20160128131802_create_scripts.rb +12 -0
  497. data/testing-with-2.1.18/db/migrate/20160128151351_create_google_analytics_settings.rb +13 -0
  498. data/testing-with-2.1.18/db/migrate/20160128193740_create_social_accounts.rb +26 -0
  499. data/testing-with-2.1.18/db/migrate/20160201134918_create_meta_tags.rb +13 -0
  500. data/testing-with-2.1.18/db/migrate/20160201210520_create_appearances.rb +14 -0
  501. data/testing-with-2.1.18/db/migrate/20171225023933_create_scaffolds.rb +10 -0
  502. data/testing-with-2.1.18/db/migrate/20180503174351_create_permissions.rb +11 -0
  503. data/testing-with-2.1.18/db/migrate/20180717160308_create_keppler_frontend_views.keppler_frontend.rb +17 -0
  504. data/testing-with-2.1.18/db/migrate/20180730194655_create_keppler_frontend_themes.rb +13 -0
  505. data/testing-with-2.1.18/db/migrate/20180802184429_create_keppler_capsules_capsules.keppler_capsules.rb +13 -0
  506. data/testing-with-2.1.18/db/migrate/20180802184430_create_keppler_capsules_capsule_fields.keppler_capsules.rb +12 -0
  507. data/testing-with-2.1.18/db/migrate/20180806192023_create_keppler_capsules_capsule_validations.keppler_capsules.rb +13 -0
  508. data/testing-with-2.1.18/db/migrate/20180806203410_create_keppler_frontend_partials.keppler_frontend.rb +13 -0
  509. data/testing-with-2.1.18/db/migrate/20180807204310_create_keppler_capsules_capsule_associations.keppler_capsules.rb +13 -0
  510. data/testing-with-2.1.18/db/migrate/20180813160624_create_keppler_languages_languages.keppler_languages.rb +14 -0
  511. data/testing-with-2.1.18/db/migrate/20180813160625_create_keppler_languages_fields.keppler_languages.rb +14 -0
  512. data/testing-with-2.1.18/db/migrate/20180818073305_create_active_storage_tables.active_storage.rb +26 -0
  513. data/testing-with-2.1.18/db/migrate/20180827120841_create_keppler_frontend_callback_functions.keppler_frontend.rb +14 -0
  514. data/testing-with-2.1.18/db/migrate/20180827154329_create_keppler_frontend_view_callbacks.keppler_frontend.rb +12 -0
  515. data/testing-with-2.1.18/db/migrate/20180827154647_add_position_to_users_table.rb +5 -0
  516. data/testing-with-2.1.18/db/migrate/20180830153221_create_keppler_frontend_functions.keppler_frontend.rb +14 -0
  517. data/testing-with-2.1.18/db/migrate/20180830153222_create_keppler_frontend_parameters.keppler_frontend.rb +13 -0
  518. data/testing-with-2.1.18/db/migrate/20180904144238_create_seos.rb +11 -0
  519. data/testing-with-2.1.18/db/seeds.rb +162 -0
  520. data/testing-with-2.1.18/docs/diagrams/keppler_core/config +0 -0
  521. data/testing-with-2.1.18/docs/diagrams/keppler_frontend/editor/resources_editor.dia +0 -0
  522. data/testing-with-2.1.18/docs/diagrams/keppler_frontend/views/create_view.dia +0 -0
  523. data/testing-with-2.1.18/docs/diagrams/keppler_frontend/views/delete_view.dia +0 -0
  524. data/testing-with-2.1.18/docs/diagrams/keppler_frontend/views/delete_view.dia.autosave +0 -0
  525. data/testing-with-2.1.18/lib/generators/install_rocket/USAGE +44 -0
  526. data/testing-with-2.1.18/lib/generators/install_rocket/install_rocket_generator.rb +107 -0
  527. data/testing-with-2.1.18/lib/generators/keppler_add_module/USAGE +5 -0
  528. data/testing-with-2.1.18/lib/generators/keppler_add_module/keppler_add_module_generator.rb +324 -0
  529. data/testing-with-2.1.18/lib/generators/keppler_add_module/templates/controllers/controller.rb +106 -0
  530. data/testing-with-2.1.18/lib/generators/keppler_add_module/templates/models/model.rb +29 -0
  531. data/testing-with-2.1.18/lib/generators/keppler_add_module/templates/policies/policy.rb +11 -0
  532. data/testing-with-2.1.18/lib/generators/keppler_add_module/templates/views/_description.haml +13 -0
  533. data/testing-with-2.1.18/lib/generators/keppler_add_module/templates/views/_form.haml +49 -0
  534. data/testing-with-2.1.18/lib/generators/keppler_add_module/templates/views/_listing.haml +58 -0
  535. data/testing-with-2.1.18/lib/generators/keppler_add_module/templates/views/edit.haml +1 -0
  536. data/testing-with-2.1.18/lib/generators/keppler_add_module/templates/views/index.haml +70 -0
  537. data/testing-with-2.1.18/lib/generators/keppler_add_module/templates/views/new.haml +1 -0
  538. data/testing-with-2.1.18/lib/generators/keppler_add_module/templates/views/reload.js.haml +5 -0
  539. data/testing-with-2.1.18/lib/generators/keppler_add_module/templates/views/show.haml +35 -0
  540. data/testing-with-2.1.18/lib/generators/keppler_delete_module/USAGE +5 -0
  541. data/testing-with-2.1.18/lib/generators/keppler_delete_module/keppler_delete_module_generator.rb +305 -0
  542. data/testing-with-2.1.18/lib/generators/keppler_front/keppler_front_generator.rb +139 -0
  543. data/testing-with-2.1.18/lib/generators/keppler_front/templates/controllers/controller.rb +17 -0
  544. data/testing-with-2.1.18/lib/generators/keppler_front/templates/views/template.html.haml +225 -0
  545. data/testing-with-2.1.18/lib/generators/keppler_relation/keppler_relation_generator.rb +219 -0
  546. data/testing-with-2.1.18/lib/generators/new_rocket/USAGE +44 -0
  547. data/testing-with-2.1.18/lib/generators/new_rocket/new_rocket_generator.rb +258 -0
  548. data/testing-with-2.1.18/lib/generators/uninstall_rocket/USAGE +32 -0
  549. data/testing-with-2.1.18/lib/generators/uninstall_rocket/uninstall_rocket_generator.rb +140 -0
  550. data/testing-with-2.1.18/lib/keppler_configuration.rb +12 -0
  551. data/testing-with-2.1.18/lib/plugins/config/locales/en.yml +16 -0
  552. data/testing-with-2.1.18/lib/plugins/config/locales/es.yml +16 -0
  553. data/testing-with-2.1.18/lib/plugins/config/menu.yml +16 -0
  554. data/testing-with-2.1.18/lib/plugins/config/permissions.yml +1 -0
  555. data/testing-with-2.1.18/lib/plugins/generators/keppler_scaffold/keppler_scaffold_generator.rb +223 -0
  556. data/testing-with-2.1.18/lib/plugins/generators/keppler_scaffold/templates/controllers/controller.rb +107 -0
  557. data/testing-with-2.1.18/lib/plugins/generators/keppler_scaffold/templates/models/model.rb +29 -0
  558. data/testing-with-2.1.18/lib/plugins/generators/keppler_scaffold/templates/policies/policy.rb +14 -0
  559. data/testing-with-2.1.18/lib/plugins/generators/keppler_scaffold/templates/views/_description.haml +13 -0
  560. data/testing-with-2.1.18/lib/plugins/generators/keppler_scaffold/templates/views/_form.haml +49 -0
  561. data/testing-with-2.1.18/lib/plugins/generators/keppler_scaffold/templates/views/_listing.haml +58 -0
  562. data/testing-with-2.1.18/lib/plugins/generators/keppler_scaffold/templates/views/edit.haml +1 -0
  563. data/testing-with-2.1.18/lib/plugins/generators/keppler_scaffold/templates/views/index.haml +69 -0
  564. data/testing-with-2.1.18/lib/plugins/generators/keppler_scaffold/templates/views/new.haml +1 -0
  565. data/testing-with-2.1.18/lib/plugins/generators/keppler_scaffold/templates/views/reload.js.haml +5 -0
  566. data/testing-with-2.1.18/lib/plugins/generators/keppler_scaffold/templates/views/show.haml +35 -0
  567. data/testing-with-2.1.18/lib/plugins/install.rb +151 -0
  568. data/testing-with-2.1.18/lib/plugins/layouts/application.html.haml +23 -0
  569. data/testing-with-2.1.18/lib/templates/haml/scaffold/_form.html.haml +10 -0
  570. metadata +564 -3
  571. data/installer/core/.sass-cache/c3e12133096533fa0f5c2d91446553934f6099d2/(__TEMPLATE__)c +0 -0
@@ -0,0 +1,4463 @@
1
+ /*!
2
+ * bootstrap-fileinput v4.4.9
3
+ * http://plugins.krajee.com/file-input
4
+ *
5
+ * Author: Kartik Visweswaran
6
+ * Copyright: 2014 - 2018, Kartik Visweswaran, Krajee.com
7
+ *
8
+ * Licensed under the BSD 3-Clause
9
+ * https://github.com/kartik-v/bootstrap-fileinput/blob/master/LICENSE.md
10
+ */
11
+ (function (factory) {
12
+ "use strict";
13
+ //noinspection JSUnresolvedVariable
14
+ if (typeof define === 'function' && define.amd) { // jshint ignore:line
15
+ // AMD. Register as an anonymous module.
16
+ define(['jquery'], factory); // jshint ignore:line
17
+ } else { // noinspection JSUnresolvedVariable
18
+ if (typeof module === 'object' && module.exports) { // jshint ignore:line
19
+ // Node/CommonJS
20
+ // noinspection JSUnresolvedVariable
21
+ module.exports = factory(require('jquery')); // jshint ignore:line
22
+ } else {
23
+ // Browser globals
24
+ factory(window.jQuery);
25
+ }
26
+ }
27
+ }(function ($) {
28
+ "use strict";
29
+
30
+ $.fn.fileinputLocales = {};
31
+ $.fn.fileinputThemes = {};
32
+
33
+ String.prototype.setTokens = function (replacePairs) {
34
+ var str = this.toString(), key, re;
35
+ for (key in replacePairs) {
36
+ if (replacePairs.hasOwnProperty(key)) {
37
+ re = new RegExp("\{" + key + "\}", "g");
38
+ str = str.replace(re, replacePairs[key]);
39
+ }
40
+ }
41
+ return str;
42
+ };
43
+
44
+ var $h, FileInput;
45
+
46
+ // fileinput helper object for all global variables and internal helper methods
47
+ //noinspection JSUnresolvedVariable
48
+ $h = {
49
+ FRAMES: '.kv-preview-thumb',
50
+ SORT_CSS: 'file-sortable',
51
+ OBJECT_PARAMS: '<param name="controller" value="true" />\n' +
52
+ '<param name="allowFullScreen" value="true" />\n' +
53
+ '<param name="allowScriptAccess" value="always" />\n' +
54
+ '<param name="autoPlay" value="false" />\n' +
55
+ '<param name="autoStart" value="false" />\n' +
56
+ '<param name="quality" value="high" />\n',
57
+ DEFAULT_PREVIEW: '<div class="file-preview-other">\n' +
58
+ '<span class="{previewFileIconClass}">{previewFileIcon}</span>\n' +
59
+ '</div>',
60
+ MODAL_ID: 'kvFileinputModal',
61
+ MODAL_EVENTS: ['show', 'shown', 'hide', 'hidden', 'loaded'],
62
+ objUrl: window.URL || window.webkitURL,
63
+ compare: function (input, str, exact) {
64
+ return input !== undefined && (exact ? input === str : input.match(str));
65
+ },
66
+ isIE: function (ver) {
67
+ // check for IE versions < 11
68
+ if (navigator.appName !== 'Microsoft Internet Explorer') {
69
+ return false;
70
+ }
71
+ if (ver === 10) {
72
+ return new RegExp('msie\\s' + ver, 'i').test(navigator.userAgent);
73
+ }
74
+ var div = document.createElement("div"), status;
75
+ div.innerHTML = "<!--[if IE " + ver + "]> <i></i> <![endif]-->";
76
+ status = div.getElementsByTagName("i").length;
77
+ document.body.appendChild(div);
78
+ div.parentNode.removeChild(div);
79
+ return status;
80
+ },
81
+ canAssignFilesToInput: function () {
82
+ var input = document.createElement('input');
83
+ try {
84
+ input.type = "file";
85
+ input.files = null;
86
+ return true;
87
+ } catch (err) {
88
+ return false;
89
+ }
90
+ },
91
+ getDragDropFolders: function (items) {
92
+ var i, item, len = items.length, folders = 0;
93
+ if (len > 0 && items[0].webkitGetAsEntry()) {
94
+ for (i = 0; i < len; i++) {
95
+ item = items[i].webkitGetAsEntry();
96
+ if (item && item.isDirectory) {
97
+ folders++;
98
+ }
99
+ }
100
+ }
101
+ return folders;
102
+ },
103
+ initModal: function ($modal) {
104
+ var $body = $('body');
105
+ if ($body.length) {
106
+ $modal.appendTo($body);
107
+ }
108
+ },
109
+ isEmpty: function (value, trim) {
110
+ return value === undefined || value === null || value.length === 0 || (trim && $.trim(value) === '');
111
+ },
112
+ isArray: function (a) {
113
+ return Array.isArray(a) || Object.prototype.toString.call(a) === '[object Array]';
114
+ },
115
+ ifSet: function (needle, haystack, def) {
116
+ def = def || '';
117
+ return (haystack && typeof haystack === 'object' && needle in haystack) ? haystack[needle] : def;
118
+ },
119
+ cleanArray: function (arr) {
120
+ if (!(arr instanceof Array)) {
121
+ arr = [];
122
+ }
123
+ return arr.filter(function (e) {
124
+ return (e !== undefined && e !== null);
125
+ });
126
+ },
127
+ spliceArray: function (arr, index, reverseOrder) {
128
+ var i, j = 0, out = [], newArr;
129
+ if (!(arr instanceof Array)) {
130
+ return [];
131
+ }
132
+ newArr = $.extend(true, [], arr);
133
+ if (reverseOrder) {
134
+ newArr.reverse();
135
+ }
136
+ for (i = 0; i < newArr.length; i++) {
137
+ if (i !== index) {
138
+ out[j] = newArr[i];
139
+ j++;
140
+ }
141
+ }
142
+ if (reverseOrder) {
143
+ out.reverse();
144
+ }
145
+ return out;
146
+ },
147
+ getNum: function (num, def) {
148
+ def = def || 0;
149
+ if (typeof num === "number") {
150
+ return num;
151
+ }
152
+ if (typeof num === "string") {
153
+ num = parseFloat(num);
154
+ }
155
+ return isNaN(num) ? def : num;
156
+ },
157
+ hasFileAPISupport: function () {
158
+ return !!(window.File && window.FileReader);
159
+ },
160
+ hasDragDropSupport: function () {
161
+ var div = document.createElement('div');
162
+ /** @namespace div.draggable */
163
+ /** @namespace div.ondragstart */
164
+ /** @namespace div.ondrop */
165
+ return !$h.isIE(9) &&
166
+ (div.draggable !== undefined || (div.ondragstart !== undefined && div.ondrop !== undefined));
167
+ },
168
+ hasFileUploadSupport: function () {
169
+ return $h.hasFileAPISupport() && window.FormData;
170
+ },
171
+ hasBlobSupport: function () {
172
+ try {
173
+ return !!window.Blob && Boolean(new Blob());
174
+ } catch (e) {
175
+ return false;
176
+ }
177
+ },
178
+ hasArrayBufferViewSupport: function () {
179
+ try {
180
+ return new Blob([new Uint8Array(100)]).size === 100;
181
+ } catch (e) {
182
+ return false;
183
+ }
184
+ },
185
+ dataURI2Blob: function (dataURI) {
186
+ //noinspection JSUnresolvedVariable
187
+ var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder ||
188
+ window.MSBlobBuilder, canBlob = $h.hasBlobSupport(), byteStr, arrayBuffer, intArray, i, mimeStr, bb,
189
+ canProceed = (canBlob || BlobBuilder) && window.atob && window.ArrayBuffer && window.Uint8Array;
190
+ if (!canProceed) {
191
+ return null;
192
+ }
193
+ if (dataURI.split(',')[0].indexOf('base64') >= 0) {
194
+ byteStr = atob(dataURI.split(',')[1]);
195
+ } else {
196
+ byteStr = decodeURIComponent(dataURI.split(',')[1]);
197
+ }
198
+ arrayBuffer = new ArrayBuffer(byteStr.length);
199
+ intArray = new Uint8Array(arrayBuffer);
200
+ for (i = 0; i < byteStr.length; i += 1) {
201
+ intArray[i] = byteStr.charCodeAt(i);
202
+ }
203
+ mimeStr = dataURI.split(',')[0].split(':')[1].split(';')[0];
204
+ if (canBlob) {
205
+ return new Blob([$h.hasArrayBufferViewSupport() ? intArray : arrayBuffer], {type: mimeStr});
206
+ }
207
+ bb = new BlobBuilder();
208
+ bb.append(arrayBuffer);
209
+ return bb.getBlob(mimeStr);
210
+ },
211
+ arrayBuffer2String: function (buffer) {
212
+ //noinspection JSUnresolvedVariable
213
+ if (window.TextDecoder) {
214
+ // noinspection JSUnresolvedFunction
215
+ return new TextDecoder("utf-8").decode(buffer);
216
+ }
217
+ var array = Array.prototype.slice.apply(new Uint8Array(buffer)), out = '', i = 0, len, c, char2, char3;
218
+ len = array.length;
219
+ while (i < len) {
220
+ c = array[i++];
221
+ switch (c >> 4) { // jshint ignore:line
222
+ case 0:
223
+ case 1:
224
+ case 2:
225
+ case 3:
226
+ case 4:
227
+ case 5:
228
+ case 6:
229
+ case 7:
230
+ // 0xxxxxxx
231
+ out += String.fromCharCode(c);
232
+ break;
233
+ case 12:
234
+ case 13:
235
+ // 110x xxxx 10xx xxxx
236
+ char2 = array[i++];
237
+ out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F)); // jshint ignore:line
238
+ break;
239
+ case 14:
240
+ // 1110 xxxx 10xx xxxx 10xx xxxx
241
+ char2 = array[i++];
242
+ char3 = array[i++];
243
+ out += String.fromCharCode(((c & 0x0F) << 12) | // jshint ignore:line
244
+ ((char2 & 0x3F) << 6) | // jshint ignore:line
245
+ ((char3 & 0x3F) << 0)); // jshint ignore:line
246
+ break;
247
+ }
248
+ }
249
+ return out;
250
+ },
251
+ isHtml: function (str) {
252
+ var a = document.createElement('div');
253
+ a.innerHTML = str;
254
+ for (var c = a.childNodes, i = c.length; i--;) {
255
+ if (c[i].nodeType === 1) {
256
+ return true;
257
+ }
258
+ }
259
+ return false;
260
+ },
261
+ isSvg: function (str) {
262
+ return str.match(/^\s*<\?xml/i) && (str.match(/<!DOCTYPE svg/i) || str.match(/<svg/i));
263
+ },
264
+ getMimeType: function (signature, contents, type) {
265
+ switch (signature) {
266
+ case "ffd8ffe0":
267
+ case "ffd8ffe1":
268
+ case "ffd8ffe2":
269
+ return 'image/jpeg';
270
+ case '89504E47':
271
+ return 'image/png';
272
+ case '47494638':
273
+ return 'image/gif';
274
+ case '49492a00':
275
+ return 'image/tiff';
276
+ case '52494646':
277
+ return 'image/webp';
278
+ case '66747970':
279
+ return 'video/3gp';
280
+ case '4f676753':
281
+ return 'video/ogg';
282
+ case '1a45dfa3':
283
+ return 'video/mkv';
284
+ case '000001ba':
285
+ case '000001b3':
286
+ return 'video/mpeg';
287
+ case '3026b275':
288
+ return 'video/wmv';
289
+ case '25504446':
290
+ return 'application/pdf';
291
+ case '25215053':
292
+ return 'application/ps';
293
+ case '504b0304':
294
+ case '504b0506':
295
+ case '504b0508':
296
+ return 'application/zip';
297
+ case '377abcaf':
298
+ return 'application/7z';
299
+ case '75737461':
300
+ return 'application/tar';
301
+ case '7801730d':
302
+ return 'application/dmg';
303
+ default:
304
+ switch (signature.substring(0, 6)) {
305
+ case '435753':
306
+ return 'application/x-shockwave-flash';
307
+ case '494433':
308
+ return 'audio/mp3';
309
+ case '425a68':
310
+ return 'application/bzip';
311
+ default:
312
+ switch (signature.substring(0, 4)) {
313
+ case '424d':
314
+ return 'image/bmp';
315
+ case 'fffb':
316
+ return 'audio/mp3';
317
+ case '4d5a':
318
+ return 'application/exe';
319
+ case '1f9d':
320
+ case '1fa0':
321
+ return 'application/zip';
322
+ case '1f8b':
323
+ return 'application/gzip';
324
+ default:
325
+ return contents && !contents.match(/[^\u0000-\u007f]/) ? 'application/text-plain' : type;
326
+ }
327
+ }
328
+ }
329
+ },
330
+ addCss: function ($el, css) {
331
+ $el.removeClass(css).addClass(css);
332
+ },
333
+ getElement: function (options, param, value) {
334
+ return ($h.isEmpty(options) || $h.isEmpty(options[param])) ? value : $(options[param]);
335
+ },
336
+ uniqId: function () {
337
+ return Math.round(new Date().getTime()) + '_' + Math.round(Math.random() * 100);
338
+ },
339
+ htmlEncode: function (str) {
340
+ return str.replace(/&/g, '&amp;')
341
+ .replace(/</g, '&lt;')
342
+ .replace(/>/g, '&gt;')
343
+ .replace(/"/g, '&quot;')
344
+ .replace(/'/g, '&apos;');
345
+ },
346
+ replaceTags: function (str, tags) {
347
+ var out = str;
348
+ if (!tags) {
349
+ return out;
350
+ }
351
+ $.each(tags, function (key, value) {
352
+ if (typeof value === "function") {
353
+ value = value();
354
+ }
355
+ out = out.split(key).join(value);
356
+ });
357
+ return out;
358
+ },
359
+ cleanMemory: function ($thumb) {
360
+ var data = $thumb.is('img') ? $thumb.attr('src') : $thumb.find('source').attr('src');
361
+ /** @namespace $h.objUrl.revokeObjectURL */
362
+ $h.objUrl.revokeObjectURL(data);
363
+ },
364
+ findFileName: function (filePath) {
365
+ var sepIndex = filePath.lastIndexOf('/');
366
+ if (sepIndex === -1) {
367
+ sepIndex = filePath.lastIndexOf('\\');
368
+ }
369
+ return filePath.split(filePath.substring(sepIndex, sepIndex + 1)).pop();
370
+ },
371
+ checkFullScreen: function () {
372
+ //noinspection JSUnresolvedVariable
373
+ return document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement ||
374
+ document.msFullscreenElement;
375
+ },
376
+ toggleFullScreen: function (maximize) {
377
+ var doc = document, de = doc.documentElement;
378
+ if (de && maximize && !$h.checkFullScreen()) {
379
+ /** @namespace document.requestFullscreen */
380
+ /** @namespace document.msRequestFullscreen */
381
+ /** @namespace document.mozRequestFullScreen */
382
+ /** @namespace document.webkitRequestFullscreen */
383
+ /** @namespace Element.ALLOW_KEYBOARD_INPUT */
384
+ if (de.requestFullscreen) {
385
+ de.requestFullscreen();
386
+ } else if (de.msRequestFullscreen) {
387
+ de.msRequestFullscreen();
388
+ } else if (de.mozRequestFullScreen) {
389
+ de.mozRequestFullScreen();
390
+ } else if (de.webkitRequestFullscreen) {
391
+ de.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
392
+ }
393
+ } else {
394
+ /** @namespace document.exitFullscreen */
395
+ /** @namespace document.msExitFullscreen */
396
+ /** @namespace document.mozCancelFullScreen */
397
+ /** @namespace document.webkitExitFullscreen */
398
+ if (doc.exitFullscreen) {
399
+ doc.exitFullscreen();
400
+ } else if (doc.msExitFullscreen) {
401
+ doc.msExitFullscreen();
402
+ } else if (doc.mozCancelFullScreen) {
403
+ doc.mozCancelFullScreen();
404
+ } else if (doc.webkitExitFullscreen) {
405
+ doc.webkitExitFullscreen();
406
+ }
407
+ }
408
+ },
409
+ moveArray: function (arr, oldIndex, newIndex, reverseOrder) {
410
+ var newArr = $.extend(true, [], arr);
411
+ if (reverseOrder) {
412
+ newArr.reverse();
413
+ }
414
+ if (newIndex >= newArr.length) {
415
+ var k = newIndex - newArr.length;
416
+ while ((k--) + 1) {
417
+ newArr.push(undefined);
418
+ }
419
+ }
420
+ newArr.splice(newIndex, 0, newArr.splice(oldIndex, 1)[0]);
421
+ if (reverseOrder) {
422
+ newArr.reverse();
423
+ }
424
+ return newArr;
425
+ },
426
+ cleanZoomCache: function ($el) {
427
+ var $cache = $el.closest('.kv-zoom-cache-theme');
428
+ if (!$cache.length) {
429
+ $cache = $el.closest('.kv-zoom-cache');
430
+ }
431
+ $cache.remove();
432
+ },
433
+ setOrientation: function (buffer, callback) {
434
+ var scanner = new DataView(buffer), idx = 0, value = 1, // Non-rotated is the default
435
+ maxBytes, uInt16, exifLength;
436
+ if (scanner.getUint16(idx) !== 0xFFD8 || buffer.length < 2) { // not a proper JPEG
437
+ if (callback) {
438
+ callback();
439
+ }
440
+ return;
441
+ }
442
+ idx += 2;
443
+ maxBytes = scanner.byteLength;
444
+ while (idx < maxBytes - 2) {
445
+ uInt16 = scanner.getUint16(idx);
446
+ idx += 2;
447
+ switch (uInt16) {
448
+ case 0xFFE1: // Start of EXIF
449
+ exifLength = scanner.getUint16(idx);
450
+ maxBytes = exifLength - idx;
451
+ idx += 2;
452
+ break;
453
+ case 0x0112: // Orientation tag
454
+ value = scanner.getUint16(idx + 6, false);
455
+ maxBytes = 0; // Stop scanning
456
+ break;
457
+ }
458
+ }
459
+ if (callback) {
460
+ callback(value);
461
+ }
462
+ },
463
+ validateOrientation: function (file, callback) {
464
+ if (!window.FileReader || !window.DataView) {
465
+ return; // skip orientation if pre-requisite libraries not supported by browser
466
+ }
467
+ var reader = new FileReader(), buffer;
468
+ reader.onloadend = function () {
469
+ buffer = reader.result;
470
+ $h.setOrientation(buffer, callback);
471
+ };
472
+ reader.readAsArrayBuffer(file);
473
+ },
474
+ adjustOrientedImage: function ($img, isZoom) {
475
+ var offsetContTop, offsetTop, newTop;
476
+ if (!$img.hasClass('is-portrait-gt4')) {
477
+ return;
478
+ }
479
+ if (isZoom) {
480
+ $img.css({width: $img.parent().height()});
481
+ return;
482
+ } else {
483
+ $img.css({height: 'auto', width: $img.height()});
484
+ }
485
+ offsetContTop = $img.parent().offset().top;
486
+ offsetTop = $img.offset().top;
487
+ newTop = offsetContTop - offsetTop;
488
+ $img.css('margin-top', newTop);
489
+ },
490
+ closeButton: function (css) {
491
+ css = css ? 'close ' + css : 'close';
492
+ return '<button type="button" class="' + css + '" aria-label="Close">\n' +
493
+ ' <span aria-hidden="true">&times;</span>\n' +
494
+ '</button>';
495
+ }
496
+ };
497
+ FileInput = function (element, options) {
498
+ var self = this;
499
+ self.$element = $(element);
500
+ self.$parent = self.$element.parent();
501
+ if (!self._validate()) {
502
+ return;
503
+ }
504
+ self.isPreviewable = $h.hasFileAPISupport();
505
+ self.isIE9 = $h.isIE(9);
506
+ self.isIE10 = $h.isIE(10);
507
+ if (self.isPreviewable || self.isIE9) {
508
+ self._init(options);
509
+ self._listen();
510
+ }
511
+ self.$element.removeClass('file-loading');
512
+ };
513
+ //noinspection JSUnusedGlobalSymbols
514
+ FileInput.prototype = {
515
+ constructor: FileInput,
516
+ _cleanup: function () {
517
+ var self = this;
518
+ self.reader = null;
519
+ self.formdata = {};
520
+ self.uploadCount = 0;
521
+ self.uploadStatus = {};
522
+ self.uploadLog = [];
523
+ self.uploadAsyncCount = 0;
524
+ self.loadedImages = [];
525
+ self.totalImagesCount = 0;
526
+ self.ajaxRequests = [];
527
+ self.clearStack();
528
+ self.fileBatchCompleted = true;
529
+ if (!self.isPreviewable) {
530
+ self.showPreview = false;
531
+ }
532
+ self.isError = false;
533
+ self.ajaxAborted = false;
534
+ self.cancelling = false;
535
+ },
536
+ _init: function (options, refreshMode) {
537
+ var self = this, f, $el = self.$element, $cont, t, tmp;
538
+ self.options = options;
539
+ $.each(options, function (key, value) {
540
+ switch (key) {
541
+ case 'minFileCount':
542
+ case 'maxFileCount':
543
+ case 'minFileSize':
544
+ case 'maxFileSize':
545
+ case 'maxFilePreviewSize':
546
+ case 'resizeImageQuality':
547
+ case 'resizeIfSizeMoreThan':
548
+ case 'progressUploadThreshold':
549
+ case 'initialPreviewCount':
550
+ case 'zoomModalHeight':
551
+ case 'minImageHeight':
552
+ case 'maxImageHeight':
553
+ case 'minImageWidth':
554
+ case 'maxImageWidth':
555
+ self[key] = $h.getNum(value);
556
+ break;
557
+ default:
558
+ self[key] = value;
559
+ break;
560
+ }
561
+ });
562
+ if (self.rtl) { // swap buttons for rtl
563
+ tmp = self.previewZoomButtonIcons.prev;
564
+ self.previewZoomButtonIcons.prev = self.previewZoomButtonIcons.next;
565
+ self.previewZoomButtonIcons.next = tmp;
566
+ }
567
+ if (!refreshMode) {
568
+ self._cleanup();
569
+ }
570
+ self.$form = $el.closest('form');
571
+ self._initTemplateDefaults();
572
+ self.uploadFileAttr = !$h.isEmpty($el.attr('name')) ? $el.attr('name') : 'file_data';
573
+ t = self._getLayoutTemplate('progress');
574
+ self.progressTemplate = t.replace('{class}', self.progressClass);
575
+ self.progressCompleteTemplate = t.replace('{class}', self.progressCompleteClass);
576
+ self.progressErrorTemplate = t.replace('{class}', self.progressErrorClass);
577
+ self.isDisabled = $el.attr('disabled') || $el.attr('readonly');
578
+ if (self.isDisabled) {
579
+ $el.attr('disabled', true);
580
+ }
581
+ self.isAjaxUpload = $h.hasFileUploadSupport() && !$h.isEmpty(self.uploadUrl);
582
+ self.dropZoneEnabled = $h.hasDragDropSupport() && self.dropZoneEnabled;
583
+ if (!self.isAjaxUpload) {
584
+ self.dropZoneEnabled = self.dropZoneEnabled && $h.canAssignFilesToInput();
585
+ }
586
+ self.isClickable = self.browseOnZoneClick && self.showPreview &&
587
+ (self.dropZoneEnabled || !$h.isEmpty(self.defaultPreviewContent));
588
+ self.slug = typeof options.slugCallback === "function" ? options.slugCallback : self._slugDefault;
589
+ self.mainTemplate = self.showCaption ? self._getLayoutTemplate('main1') : self._getLayoutTemplate('main2');
590
+ self.captionTemplate = self._getLayoutTemplate('caption');
591
+ self.previewGenericTemplate = self._getPreviewTemplate('generic');
592
+ if (!self.imageCanvas && self.resizeImage && (self.maxImageWidth || self.maxImageHeight)) {
593
+ self.imageCanvas = document.createElement('canvas');
594
+ self.imageCanvasContext = self.imageCanvas.getContext('2d');
595
+ }
596
+ if ($h.isEmpty($el.attr('id'))) {
597
+ $el.attr('id', $h.uniqId());
598
+ }
599
+ self.namespace = '.fileinput_' + $el.attr('id').replace(/-/g, '_');
600
+ if (self.$container === undefined) {
601
+ self.$container = self._createContainer();
602
+ } else {
603
+ self._refreshContainer();
604
+ }
605
+ $cont = self.$container;
606
+ self.$dropZone = $cont.find('.file-drop-zone');
607
+ self.$progress = $cont.find('.kv-upload-progress');
608
+ self.$btnUpload = $cont.find('.fileinput-upload');
609
+ self.$captionContainer = $h.getElement(options, 'elCaptionContainer', $cont.find('.file-caption'));
610
+ self.$caption = $h.getElement(options, 'elCaptionText', $cont.find('.file-caption-name'));
611
+ if (!$h.isEmpty(self.msgPlaceholder)) {
612
+ f = $el.attr('multiple') ? self.filePlural : self.fileSingle;
613
+ self.$caption.attr('placeholder', self.msgPlaceholder.replace('{files}', f));
614
+ }
615
+ self.$captionIcon = self.$captionContainer.find('.file-caption-icon');
616
+ self.$previewContainer = $h.getElement(options, 'elPreviewContainer', $cont.find('.file-preview'));
617
+ self.$preview = $h.getElement(options, 'elPreviewImage', $cont.find('.file-preview-thumbnails'));
618
+ self.$previewStatus = $h.getElement(options, 'elPreviewStatus', $cont.find('.file-preview-status'));
619
+ self.$errorContainer = $h.getElement(options, 'elErrorContainer', self.$previewContainer.find('.kv-fileinput-error'));
620
+ self._validateDisabled();
621
+ if (!$h.isEmpty(self.msgErrorClass)) {
622
+ $h.addCss(self.$errorContainer, self.msgErrorClass);
623
+ }
624
+ if (!refreshMode) {
625
+ self.$errorContainer.hide();
626
+ self.previewInitId = "preview-" + $h.uniqId();
627
+ self._initPreviewCache();
628
+ self._initPreview(true);
629
+ self._initPreviewActions();
630
+ if (self.$parent.hasClass('file-loading')) {
631
+ self.$container.insertBefore(self.$parent);
632
+ self.$parent.remove();
633
+ }
634
+ } else {
635
+ if (!self._errorsExist()) {
636
+ self.$errorContainer.hide();
637
+ }
638
+ }
639
+ self._setFileDropZoneTitle();
640
+ if ($el.attr('disabled')) {
641
+ self.disable();
642
+ }
643
+ self._initZoom();
644
+ if (self.hideThumbnailContent) {
645
+ $h.addCss(self.$preview, 'hide-content');
646
+ }
647
+ },
648
+ _initTemplateDefaults: function () {
649
+ var self = this, tMain1, tMain2, tPreview, tFileIcon, tClose, tCaption, tBtnDefault, tBtnLink, tBtnBrowse,
650
+ tModalMain, tModal, tProgress, tSize, tFooter, tActions, tActionDelete, tActionUpload, tActionDownload,
651
+ tActionZoom, tActionDrag, tIndicator, tTagBef, tTagBef1, tTagBef2, tTagAft, tGeneric, tHtml, tImage,
652
+ tText, tOffice, tGdocs, tVideo, tAudio, tFlash, tObject, tPdf, tOther, tStyle, tZoomCache, vDefaultDim;
653
+ tMain1 = '{preview}\n' +
654
+ '<div class="kv-upload-progress kv-hidden"></div><div class="clearfix"></div>\n' +
655
+ '<div class="input-group {class}">\n' +
656
+ ' {caption}\n' +
657
+ '<div class="input-group-btn input-group-append">\n' +
658
+ ' {remove}\n' +
659
+ ' {cancel}\n' +
660
+ ' {upload}\n' +
661
+ ' {browse}\n' +
662
+ ' </div>\n' +
663
+ '</div>';
664
+ tMain2 = '{preview}\n<div class="kv-upload-progress kv-hidden"></div>\n<div class="clearfix"></div>\n{remove}\n{cancel}\n{upload}\n{browse}\n';
665
+ tPreview = '<div class="file-preview {class}">\n' +
666
+ ' {close}' +
667
+ ' <div class="{dropClass}">\n' +
668
+ ' <div class="file-preview-thumbnails">\n' +
669
+ ' </div>\n' +
670
+ ' <div class="clearfix"></div>' +
671
+ ' <div class="file-preview-status text-center text-success"></div>\n' +
672
+ ' <div class="kv-fileinput-error"></div>\n' +
673
+ ' </div>\n' +
674
+ '</div>';
675
+ tClose = $h.closeButton('fileinput-remove');
676
+ tFileIcon = '<i class="glyphicon glyphicon-file"></i>';
677
+ // noinspection HtmlUnknownAttribute
678
+ tCaption = '<div class="file-caption form-control {class}" tabindex="500">\n' +
679
+ ' <span class="file-caption-icon"></span>\n' +
680
+ ' <input class="file-caption-name" onkeydown="return false;" onpaste="return false;">\n' +
681
+ '</div>';
682
+ //noinspection HtmlUnknownAttribute
683
+ tBtnDefault = '<button type="{type}" tabindex="500" title="{title}" class="{css}" ' +
684
+ '{status}>{icon} {label}</button>';
685
+ //noinspection HtmlUnknownAttribute
686
+ tBtnLink = '<a href="{href}" tabindex="500" title="{title}" class="{css}" {status}>{icon} {label}</a>';
687
+ //noinspection HtmlUnknownAttribute
688
+ tBtnBrowse = '<div tabindex="500" class="{css}" {status}>{icon} {label}</div>';
689
+ tModalMain = '<div id="' + $h.MODAL_ID + '" class="file-zoom-dialog modal fade" ' +
690
+ 'tabindex="-1" aria-labelledby="' + $h.MODAL_ID + 'Label"></div>';
691
+ tModal = '<div class="modal-dialog modal-lg{rtl}" role="document">\n' +
692
+ ' <div class="modal-content">\n' +
693
+ ' <div class="modal-header">\n' +
694
+ ' <h5 class="modal-title">{heading}</h5>\n' +
695
+ ' <span class="kv-zoom-title"></span>\n' +
696
+ ' <div class="kv-zoom-actions">{toggleheader}{fullscreen}{borderless}{close}</div>\n' +
697
+ ' </div>\n' +
698
+ ' <div class="modal-body">\n' +
699
+ ' <div class="floating-buttons"></div>\n' +
700
+ ' <div class="kv-zoom-body file-zoom-content {zoomFrameClass}"></div>\n' + '{prev} {next}\n' +
701
+ ' </div>\n' +
702
+ ' </div>\n' +
703
+ '</div>\n';
704
+ tProgress = '<div class="progress">\n' +
705
+ ' <div class="{class}" role="progressbar"' +
706
+ ' aria-valuenow="{percent}" aria-valuemin="0" aria-valuemax="100" style="width:{percent}%;">\n' +
707
+ ' {status}\n' +
708
+ ' </div>\n' +
709
+ '</div>';
710
+ tSize = ' <samp>({sizeText})</samp>';
711
+ tFooter = '<div class="file-thumbnail-footer">\n' +
712
+ ' <div class="file-footer-caption" title="{caption}">\n' +
713
+ ' <div class="file-caption-info">{caption}</div>\n' +
714
+ ' <div class="file-size-info">{size}</div>\n' +
715
+ ' </div>\n' +
716
+ ' {progress}\n{indicator}\n{actions}\n' +
717
+ '</div>';
718
+ tActions = '<div class="file-actions">\n' +
719
+ ' <div class="file-footer-buttons">\n' +
720
+ ' {download} {upload} {delete} {zoom} {other}' +
721
+ ' </div>\n' +
722
+ '</div>\n' +
723
+ '{drag}\n' +
724
+ '<div class="clearfix"></div>';
725
+ //noinspection HtmlUnknownAttribute
726
+ tActionDelete = '<button type="button" class="kv-file-remove {removeClass}" ' +
727
+ 'title="{removeTitle}" {dataUrl}{dataKey}>{removeIcon}</button>\n';
728
+ tActionUpload = '<button type="button" class="kv-file-upload {uploadClass}" title="{uploadTitle}">' +
729
+ '{uploadIcon}</button>';
730
+ tActionDownload = '<a class="kv-file-download {downloadClass}" title="{downloadTitle}" ' +
731
+ 'href="{downloadUrl}" download="{caption}" target="_blank">{downloadIcon}</a>';
732
+ tActionZoom = '<button type="button" class="kv-file-zoom {zoomClass}" ' +
733
+ 'title="{zoomTitle}">{zoomIcon}</button>';
734
+ tActionDrag = '<span class="file-drag-handle {dragClass}" title="{dragTitle}">{dragIcon}</span>';
735
+ tIndicator = '<div class="file-upload-indicator" title="{indicatorTitle}">{indicator}</div>';
736
+ tTagBef = '<div class="file-preview-frame {frameClass}" id="{previewId}" data-fileindex="{fileindex}"' +
737
+ ' data-template="{template}"';
738
+ tTagBef1 = tTagBef + '><div class="kv-file-content">\n';
739
+ tTagBef2 = tTagBef + ' title="{caption}"><div class="kv-file-content">\n';
740
+ tTagAft = '</div>{footer}\n</div>\n';
741
+ tGeneric = '{content}\n';
742
+ tStyle = ' {style}';
743
+ tHtml = '<div class="kv-preview-data file-preview-html" title="{caption}"' + tStyle + '>{data}</div>\n';
744
+ tImage = '<img src="{data}" class="file-preview-image kv-preview-data" title="{caption}" ' +
745
+ 'alt="{caption}"' + tStyle + '>\n';
746
+ tText = '<textarea class="kv-preview-data file-preview-text" title="{caption}" readonly' + tStyle + '>' +
747
+ '{data}</textarea>\n';
748
+ tOffice = '<iframe class="kv-preview-data file-preview-office" ' +
749
+ 'src="https://view.officeapps.live.com/op/embed.aspx?src={data}"' + tStyle + '></iframe>';
750
+ tGdocs = '<iframe class="kv-preview-data file-preview-gdocs" ' +
751
+ 'src="https://docs.google.com/gview?url={data}&embedded=true"' + tStyle + '></iframe>';
752
+ tVideo = '<video class="kv-preview-data file-preview-video" controls' + tStyle + '>\n' +
753
+ '<source src="{data}" type="{type}">\n' + $h.DEFAULT_PREVIEW + '\n</video>\n';
754
+ tAudio = '<!--suppress ALL --><audio class="kv-preview-data file-preview-audio" controls' + tStyle + '>\n<source src="{data}" ' +
755
+ 'type="{type}">\n' + $h.DEFAULT_PREVIEW + '\n</audio>\n';
756
+ tFlash = '<embed class="kv-preview-data file-preview-flash" src="{data}" type="application/x-shockwave-flash"' + tStyle + '>\n';
757
+ tPdf = '<embed class="kv-preview-data file-preview-pdf" src="{data}" type="application/pdf"' + tStyle + '>\n';
758
+ tObject = '<object class="kv-preview-data file-preview-object file-object {typeCss}" ' +
759
+ 'data="{data}" type="{type}"' + tStyle + '>\n' + '<param name="movie" value="{caption}" />\n' +
760
+ $h.OBJECT_PARAMS + ' ' + $h.DEFAULT_PREVIEW + '\n</object>\n';
761
+ tOther = '<div class="kv-preview-data file-preview-other-frame"' + tStyle + '>\n' + $h.DEFAULT_PREVIEW + '\n</div>\n';
762
+ tZoomCache = '<div class="kv-zoom-cache" style="display:none">{zoomContent}</div>';
763
+ vDefaultDim = {width: "100%", height: "100%", 'min-height': "480px"};
764
+ self.defaults = {
765
+ layoutTemplates: {
766
+ main1: tMain1,
767
+ main2: tMain2,
768
+ preview: tPreview,
769
+ close: tClose,
770
+ fileIcon: tFileIcon,
771
+ caption: tCaption,
772
+ modalMain: tModalMain,
773
+ modal: tModal,
774
+ progress: tProgress,
775
+ size: tSize,
776
+ footer: tFooter,
777
+ indicator: tIndicator,
778
+ actions: tActions,
779
+ actionDelete: tActionDelete,
780
+ actionUpload: tActionUpload,
781
+ actionDownload: tActionDownload,
782
+ actionZoom: tActionZoom,
783
+ actionDrag: tActionDrag,
784
+ btnDefault: tBtnDefault,
785
+ btnLink: tBtnLink,
786
+ btnBrowse: tBtnBrowse,
787
+ zoomCache: tZoomCache
788
+ },
789
+ previewMarkupTags: {
790
+ tagBefore1: tTagBef1,
791
+ tagBefore2: tTagBef2,
792
+ tagAfter: tTagAft
793
+ },
794
+ previewContentTemplates: {
795
+ generic: tGeneric,
796
+ html: tHtml,
797
+ image: tImage,
798
+ text: tText,
799
+ office: tOffice,
800
+ gdocs: tGdocs,
801
+ video: tVideo,
802
+ audio: tAudio,
803
+ flash: tFlash,
804
+ object: tObject,
805
+ pdf: tPdf,
806
+ other: tOther
807
+ },
808
+ allowedPreviewTypes: ['image', 'html', 'text', 'video', 'audio', 'flash', 'pdf', 'object'],
809
+ previewTemplates: {},
810
+ previewSettings: {
811
+ image: {width: "auto", height: "auto", 'max-width': "100%", 'max-height': "100%"},
812
+ html: {width: "213px", height: "160px"},
813
+ text: {width: "213px", height: "160px"},
814
+ office: {width: "213px", height: "160px"},
815
+ gdocs: {width: "213px", height: "160px"},
816
+ video: {width: "213px", height: "160px"},
817
+ audio: {width: "100%", height: "30px"},
818
+ flash: {width: "213px", height: "160px"},
819
+ object: {width: "213px", height: "160px"},
820
+ pdf: {width: "213px", height: "160px"},
821
+ other: {width: "213px", height: "160px"}
822
+ },
823
+ previewSettingsSmall: {
824
+ image: {width: "auto", height: "auto", 'max-width': "100%", 'max-height': "100%"},
825
+ html: {width: "100%", height: "160px"},
826
+ text: {width: "100%", height: "160px"},
827
+ office: {width: "100%", height: "160px"},
828
+ gdocs: {width: "100%", height: "160px"},
829
+ video: {width: "100%", height: "auto"},
830
+ audio: {width: "100%", height: "30px"},
831
+ flash: {width: "100%", height: "auto"},
832
+ object: {width: "100%", height: "auto"},
833
+ pdf: {width: "100%", height: "160px"},
834
+ other: {width: "100%", height: "160px"}
835
+ },
836
+ previewZoomSettings: {
837
+ image: {width: "auto", height: "auto", 'max-width': "100%", 'max-height': "100%"},
838
+ html: vDefaultDim,
839
+ text: vDefaultDim,
840
+ office: {width: "100%", height: "100%", 'max-width': "100%", 'min-height': "480px"},
841
+ gdocs: {width: "100%", height: "100%", 'max-width': "100%", 'min-height': "480px"},
842
+ video: {width: "auto", height: "100%", 'max-width': "100%"},
843
+ audio: {width: "100%", height: "30px"},
844
+ flash: {width: "auto", height: "480px"},
845
+ object: {width: "auto", height: "100%", 'max-width': "100%", 'min-height': "480px"},
846
+ pdf: vDefaultDim,
847
+ other: {width: "auto", height: "100%", 'min-height': "480px"}
848
+ },
849
+ fileTypeSettings: {
850
+ image: function (vType, vName) {
851
+ return ($h.compare(vType, 'image.*') && !$h.compare(vType, /(tiff?|wmf)$/i) ||
852
+ $h.compare(vName, /\.(gif|png|jpe?g)$/i));
853
+ },
854
+ html: function (vType, vName) {
855
+ return $h.compare(vType, 'text/html') || $h.compare(vName, /\.(htm|html)$/i);
856
+ },
857
+ office: function (vType, vName) {
858
+ return $h.compare(vType, /(word|excel|powerpoint|office)$/i) ||
859
+ $h.compare(vName, /\.(docx?|xlsx?|pptx?|pps|potx?)$/i);
860
+ },
861
+ gdocs: function (vType, vName) {
862
+ return $h.compare(vType, /(word|excel|powerpoint|office|iwork-pages|tiff?)$/i) ||
863
+ $h.compare(vName, /\.(docx?|xlsx?|pptx?|pps|potx?|rtf|ods|odt|pages|ai|dxf|ttf|tiff?|wmf|e?ps)$/i);
864
+ },
865
+ text: function (vType, vName) {
866
+ return $h.compare(vType, 'text.*') || $h.compare(vName, /\.(xml|javascript)$/i) ||
867
+ $h.compare(vName, /\.(txt|md|csv|nfo|ini|json|php|js|css)$/i);
868
+ },
869
+ video: function (vType, vName) {
870
+ return $h.compare(vType, 'video.*') && ($h.compare(vType, /(ogg|mp4|mp?g|mov|webm|3gp)$/i) ||
871
+ $h.compare(vName, /\.(og?|mp4|webm|mp?g|mov|3gp)$/i));
872
+ },
873
+ audio: function (vType, vName) {
874
+ return $h.compare(vType, 'audio.*') && ($h.compare(vName, /(ogg|mp3|mp?g|wav)$/i) ||
875
+ $h.compare(vName, /\.(og?|mp3|mp?g|wav)$/i));
876
+ },
877
+ flash: function (vType, vName) {
878
+ return $h.compare(vType, 'application/x-shockwave-flash', true) || $h.compare(vName, /\.(swf)$/i);
879
+ },
880
+ pdf: function (vType, vName) {
881
+ return $h.compare(vType, 'application/pdf', true) || $h.compare(vName, /\.(pdf)$/i);
882
+ },
883
+ object: function () {
884
+ return true;
885
+ },
886
+ other: function () {
887
+ return true;
888
+ }
889
+ },
890
+ fileActionSettings: {
891
+ showRemove: true,
892
+ showUpload: true,
893
+ showDownload: true,
894
+ showZoom: true,
895
+ showDrag: true,
896
+ removeIcon: '<i class="glyphicon glyphicon-trash"></i>',
897
+ removeClass: 'btn btn-sm btn-kv btn-default btn-outline-secondary',
898
+ removeErrorClass: 'btn btn-sm btn-kv btn-danger',
899
+ removeTitle: 'Remove file',
900
+ uploadIcon: '<i class="glyphicon glyphicon-upload"></i>',
901
+ uploadClass: 'btn btn-sm btn-kv btn-default btn-outline-secondary',
902
+ uploadTitle: 'Upload file',
903
+ uploadRetryIcon: '<i class="glyphicon glyphicon-repeat"></i>',
904
+ uploadRetryTitle: 'Retry upload',
905
+ downloadIcon: '<i class="glyphicon glyphicon-download"></i>',
906
+ downloadClass: 'btn btn-sm btn-kv btn-default btn-outline-secondary',
907
+ downloadTitle: 'Download file',
908
+ zoomIcon: '<i class="glyphicon glyphicon-zoom-in"></i>',
909
+ zoomClass: 'btn btn-sm btn-kv btn-default btn-outline-secondary',
910
+ zoomTitle: 'View Details',
911
+ dragIcon: '<i class="glyphicon glyphicon-move"></i>',
912
+ dragClass: 'text-info',
913
+ dragTitle: 'Move / Rearrange',
914
+ dragSettings: {},
915
+ indicatorNew: '<i class="glyphicon glyphicon-plus-sign text-warning"></i>',
916
+ indicatorSuccess: '<i class="glyphicon glyphicon-ok-sign text-success"></i>',
917
+ indicatorError: '<i class="glyphicon glyphicon-exclamation-sign text-danger"></i>',
918
+ indicatorLoading: '<i class="glyphicon glyphicon-hourglass text-muted"></i>',
919
+ indicatorNewTitle: 'Not uploaded yet',
920
+ indicatorSuccessTitle: 'Uploaded',
921
+ indicatorErrorTitle: 'Upload Error',
922
+ indicatorLoadingTitle: 'Uploading ...'
923
+ }
924
+ };
925
+ $.each(self.defaults, function (key, setting) {
926
+ if (key === 'allowedPreviewTypes') {
927
+ if (self.allowedPreviewTypes === undefined) {
928
+ self.allowedPreviewTypes = setting;
929
+ }
930
+ return;
931
+ }
932
+ self[key] = $.extend(true, {}, setting, self[key]);
933
+ });
934
+ self._initPreviewTemplates();
935
+ },
936
+ _initPreviewTemplates: function () {
937
+ var self = this, cfg = self.defaults, tags = self.previewMarkupTags, tagBef, tagAft = tags.tagAfter;
938
+ $.each(cfg.previewContentTemplates, function (key, value) {
939
+ if ($h.isEmpty(self.previewTemplates[key])) {
940
+ tagBef = tags.tagBefore2;
941
+ if (key === 'generic' || key === 'image' || key === 'html' || key === 'text') {
942
+ tagBef = tags.tagBefore1;
943
+ }
944
+ self.previewTemplates[key] = tagBef + value + tagAft;
945
+ }
946
+ });
947
+ },
948
+ _initPreviewCache: function () {
949
+ var self = this;
950
+ self.previewCache = {
951
+ data: {},
952
+ init: function () {
953
+ var content = self.initialPreview;
954
+ if (content.length > 0 && !$h.isArray(content)) {
955
+ content = content.split(self.initialPreviewDelimiter);
956
+ }
957
+ self.previewCache.data = {
958
+ content: content,
959
+ config: self.initialPreviewConfig,
960
+ tags: self.initialPreviewThumbTags
961
+ };
962
+ },
963
+ count: function () {
964
+ return !!self.previewCache.data && !!self.previewCache.data.content ?
965
+ self.previewCache.data.content.length : 0;
966
+ },
967
+ get: function (i, isDisabled) {
968
+ var ind = 'init_' + i, data = self.previewCache.data, config = data.config[i],
969
+ content = data.content[i], previewId = self.previewInitId + '-' + ind, out, $tmp, cat, ftr,
970
+ fname, ftype, frameClass, asData = $h.ifSet('previewAsData', config, self.initialPreviewAsData),
971
+ parseTemplate = function (cat, dat, fn, ft, id, ftr, ind, fc, t) {
972
+ fc = ' file-preview-initial ' + $h.SORT_CSS + (fc ? ' ' + fc : '');
973
+ return self._generatePreviewTemplate(cat, dat, fn, ft, id, false, null, fc, ftr, ind, t);
974
+ };
975
+ if (!content) {
976
+ return '';
977
+ }
978
+ isDisabled = isDisabled === undefined ? true : isDisabled;
979
+ cat = $h.ifSet('type', config, self.initialPreviewFileType || 'generic');
980
+ fname = $h.ifSet('filename', config, $h.ifSet('caption', config));
981
+ ftype = $h.ifSet('filetype', config, cat);
982
+ ftr = self.previewCache.footer(i, isDisabled, (config && config.size || null));
983
+ frameClass = $h.ifSet('frameClass', config);
984
+ if (asData) {
985
+ out = parseTemplate(cat, content, fname, ftype, previewId, ftr, ind, frameClass);
986
+ } else {
987
+ out = parseTemplate('generic', content, fname, ftype, previewId, ftr, ind, frameClass, cat)
988
+ .setTokens({'content': data.content[i]});
989
+ }
990
+ if (data.tags.length && data.tags[i]) {
991
+ out = $h.replaceTags(out, data.tags[i]);
992
+ }
993
+ /** @namespace config.frameAttr */
994
+ if (!$h.isEmpty(config) && !$h.isEmpty(config.frameAttr)) {
995
+ $tmp = $(document.createElement('div')).html(out);
996
+ $tmp.find('.file-preview-initial').attr(config.frameAttr);
997
+ out = $tmp.html();
998
+ $tmp.remove();
999
+ }
1000
+ return out;
1001
+ },
1002
+ add: function (content, config, tags, append) {
1003
+ var data = self.previewCache.data, index;
1004
+ if (!$h.isArray(content)) {
1005
+ content = content.split(self.initialPreviewDelimiter);
1006
+ }
1007
+ if (append) {
1008
+ index = data.content.push(content) - 1;
1009
+ data.config[index] = config;
1010
+ data.tags[index] = tags;
1011
+ } else {
1012
+ index = content.length - 1;
1013
+ data.content = content;
1014
+ data.config = config;
1015
+ data.tags = tags;
1016
+ }
1017
+ self.previewCache.data = data;
1018
+ return index;
1019
+ },
1020
+ set: function (content, config, tags, append) {
1021
+ var data = self.previewCache.data, i, chk;
1022
+ if (!content || !content.length) {
1023
+ return;
1024
+ }
1025
+ if (!$h.isArray(content)) {
1026
+ content = content.split(self.initialPreviewDelimiter);
1027
+ }
1028
+ chk = content.filter(function (n) {
1029
+ return n !== null;
1030
+ });
1031
+ if (!chk.length) {
1032
+ return;
1033
+ }
1034
+ if (data.content === undefined) {
1035
+ data.content = [];
1036
+ }
1037
+ if (data.config === undefined) {
1038
+ data.config = [];
1039
+ }
1040
+ if (data.tags === undefined) {
1041
+ data.tags = [];
1042
+ }
1043
+ if (append) {
1044
+ for (i = 0; i < content.length; i++) {
1045
+ if (content[i]) {
1046
+ data.content.push(content[i]);
1047
+ }
1048
+ }
1049
+ for (i = 0; i < config.length; i++) {
1050
+ if (config[i]) {
1051
+ data.config.push(config[i]);
1052
+ }
1053
+ }
1054
+ for (i = 0; i < tags.length; i++) {
1055
+ if (tags[i]) {
1056
+ data.tags.push(tags[i]);
1057
+ }
1058
+ }
1059
+ } else {
1060
+ data.content = content;
1061
+ data.config = config;
1062
+ data.tags = tags;
1063
+ }
1064
+ self.previewCache.data = data;
1065
+ },
1066
+ unset: function (index) {
1067
+ var chk = self.previewCache.count(), rev = self.reversePreviewOrder;
1068
+ if (!chk) {
1069
+ return;
1070
+ }
1071
+ if (chk === 1) {
1072
+ self.previewCache.data.content = [];
1073
+ self.previewCache.data.config = [];
1074
+ self.previewCache.data.tags = [];
1075
+ self.initialPreview = [];
1076
+ self.initialPreviewConfig = [];
1077
+ self.initialPreviewThumbTags = [];
1078
+ return;
1079
+ }
1080
+ self.previewCache.data.content = $h.spliceArray(self.previewCache.data.content, index, rev);
1081
+ self.previewCache.data.config = $h.spliceArray(self.previewCache.data.config, index, rev);
1082
+ self.previewCache.data.tags = $h.spliceArray(self.previewCache.data.tags, index, rev);
1083
+ },
1084
+ out: function () {
1085
+ var html = '', caption, len = self.previewCache.count(), i, content;
1086
+ if (len === 0) {
1087
+ return {content: '', caption: ''};
1088
+ }
1089
+ for (i = 0; i < len; i++) {
1090
+ content = self.previewCache.get(i);
1091
+ html = self.reversePreviewOrder ? (content + html) : (html + content);
1092
+ }
1093
+ caption = self._getMsgSelected(len);
1094
+ return {content: html, caption: caption};
1095
+ },
1096
+ footer: function (i, isDisabled, size) {
1097
+ var data = self.previewCache.data || {};
1098
+ if ($h.isEmpty(data.content)) {
1099
+ return '';
1100
+ }
1101
+ if ($h.isEmpty(data.config) || $h.isEmpty(data.config[i])) {
1102
+ data.config[i] = {};
1103
+ }
1104
+ isDisabled = isDisabled === undefined ? true : isDisabled;
1105
+ var config = data.config[i], caption = $h.ifSet('caption', config), a,
1106
+ width = $h.ifSet('width', config, 'auto'), url = $h.ifSet('url', config, false),
1107
+ key = $h.ifSet('key', config, null), fs = self.fileActionSettings,
1108
+ initPreviewShowDel = self.initialPreviewShowDelete || false,
1109
+ dUrl = config.downloadUrl || self.initialPreviewDownloadUrl || '',
1110
+ dFil = config.filename || config.caption || '',
1111
+ initPreviewShowDwl = !!(dUrl),
1112
+ sDel = $h.ifSet('showRemove', config, $h.ifSet('showRemove', fs, initPreviewShowDel)),
1113
+ sDwl = $h.ifSet('showDownload', config, $h.ifSet('showDownload', fs, initPreviewShowDwl)),
1114
+ sZm = $h.ifSet('showZoom', config, $h.ifSet('showZoom', fs, true)),
1115
+ sDrg = $h.ifSet('showDrag', config, $h.ifSet('showDrag', fs, true)),
1116
+ dis = (url === false) && isDisabled;
1117
+ sDwl = sDwl && config.downloadUrl !== false && !!dUrl;
1118
+ a = self._renderFileActions(false, sDwl, sDel, sZm, sDrg, dis, url, key, true, dUrl, dFil);
1119
+ return self._getLayoutTemplate('footer').setTokens({
1120
+ 'progress': self._renderThumbProgress(),
1121
+ 'actions': a,
1122
+ 'caption': caption,
1123
+ 'size': self._getSize(size),
1124
+ 'width': width,
1125
+ 'indicator': ''
1126
+ });
1127
+ }
1128
+ };
1129
+ self.previewCache.init();
1130
+ },
1131
+ _handler: function ($el, event, callback) {
1132
+ var self = this, ns = self.namespace, ev = event.split(' ').join(ns + ' ') + ns;
1133
+ if (!$el || !$el.length) {
1134
+ return;
1135
+ }
1136
+ $el.off(ev).on(ev, callback);
1137
+ },
1138
+ _log: function (msg) {
1139
+ var self = this, id = self.$element.attr('id');
1140
+ if (id) {
1141
+ msg = '"' + id + '": ' + msg;
1142
+ }
1143
+ if (typeof window.console.log !== "undefined") {
1144
+ window.console.log(msg);
1145
+ } else {
1146
+ window.alert(msg);
1147
+ }
1148
+ },
1149
+ _validate: function () {
1150
+ var self = this, status = self.$element.attr('class').includes('keppler-file');
1151
+ if (!status) {
1152
+ self._log('The input "type" must be set to "file" for initializing the "bootstrap-fileinput" plugin.');
1153
+ }
1154
+ return status;
1155
+ },
1156
+ _errorsExist: function () {
1157
+ var self = this, $err, $errList = self.$errorContainer.find('li');
1158
+ if ($errList.length) {
1159
+ return true;
1160
+ }
1161
+ $err = $(document.createElement('div')).html(self.$errorContainer.html());
1162
+ $err.find('.kv-error-close').remove();
1163
+ $err.find('ul').remove();
1164
+ return !!$.trim($err.text()).length;
1165
+ },
1166
+ _errorHandler: function (evt, caption) {
1167
+ var self = this, err = evt.target.error, showError = function (msg) {
1168
+ self._showError(msg.replace('{name}', caption));
1169
+ };
1170
+ /** @namespace err.NOT_FOUND_ERR */
1171
+ /** @namespace err.SECURITY_ERR */
1172
+ /** @namespace err.NOT_READABLE_ERR */
1173
+ if (err.code === err.NOT_FOUND_ERR) {
1174
+ showError(self.msgFileNotFound);
1175
+ } else if (err.code === err.SECURITY_ERR) {
1176
+ showError(self.msgFileSecured);
1177
+ } else if (err.code === err.NOT_READABLE_ERR) {
1178
+ showError(self.msgFileNotReadable);
1179
+ } else if (err.code === err.ABORT_ERR) {
1180
+ showError(self.msgFilePreviewAborted);
1181
+ } else {
1182
+ showError(self.msgFilePreviewError);
1183
+ }
1184
+ },
1185
+ _addError: function (msg) {
1186
+ var self = this, $error = self.$errorContainer;
1187
+ if (msg && $error.length) {
1188
+ $error.html(self.errorCloseButton + msg);
1189
+ self._handler($error.find('.kv-error-close'), 'click', function () {
1190
+ setTimeout(function () {
1191
+ if (self.showPreview && !self.getFrames().length) {
1192
+ self.clear();
1193
+ }
1194
+ $error.fadeOut('slow');
1195
+ }, 10);
1196
+ });
1197
+ }
1198
+ },
1199
+ _setValidationError: function (css) {
1200
+ var self = this;
1201
+ css = (css ? css + ' ' : '') + 'has-error';
1202
+ self.$container.removeClass(css).addClass('has-error');
1203
+ $h.addCss(self.$captionContainer, 'is-invalid');
1204
+ },
1205
+ _resetErrors: function (fade) {
1206
+ var self = this, $error = self.$errorContainer;
1207
+ self.isError = false;
1208
+ self.$container.removeClass('has-error');
1209
+ self.$captionContainer.removeClass('is-invalid');
1210
+ $error.html('');
1211
+ if (fade) {
1212
+ $error.fadeOut('slow');
1213
+ } else {
1214
+ $error.hide();
1215
+ }
1216
+ },
1217
+ _showFolderError: function (folders) {
1218
+ var self = this, $error = self.$errorContainer, msg;
1219
+ if (!folders) {
1220
+ return;
1221
+ }
1222
+ if (!self.isAjaxUpload) {
1223
+ self._clearFileInput();
1224
+ }
1225
+ msg = self.msgFoldersNotAllowed.replace('{n}', folders);
1226
+ self._addError(msg);
1227
+ self._setValidationError();
1228
+ $error.fadeIn(800);
1229
+ self._raise('filefoldererror', [folders, msg]);
1230
+ },
1231
+ _showUploadError: function (msg, params, event) {
1232
+ var self = this, $error = self.$errorContainer, ev = event || 'fileuploaderror', e = params && params.id ?
1233
+ '<li data-file-id="' + params.id + '">' + msg + '</li>' : '<li>' + msg + '</li>';
1234
+ if ($error.find('ul').length === 0) {
1235
+ self._addError('<ul>' + e + '</ul>');
1236
+ } else {
1237
+ $error.find('ul').append(e);
1238
+ }
1239
+ $error.fadeIn(800);
1240
+ self._raise(ev, [params, msg]);
1241
+ self._setValidationError('file-input-new');
1242
+ return true;
1243
+ },
1244
+ _showError: function (msg, params, event) {
1245
+ var self = this, $error = self.$errorContainer, ev = event || 'fileerror';
1246
+ params = params || {};
1247
+ params.reader = self.reader;
1248
+ self._addError(msg);
1249
+ $error.fadeIn(800);
1250
+ self._raise(ev, [params, msg]);
1251
+ if (!self.isAjaxUpload) {
1252
+ self._clearFileInput();
1253
+ }
1254
+ self._setValidationError('file-input-new');
1255
+ self.$btnUpload.attr('disabled', true);
1256
+ return true;
1257
+ },
1258
+ _noFilesError: function (params) {
1259
+ var self = this, label = self.minFileCount > 1 ? self.filePlural : self.fileSingle,
1260
+ msg = self.msgFilesTooLess.replace('{n}', self.minFileCount).replace('{files}', label),
1261
+ $error = self.$errorContainer;
1262
+ self._addError(msg);
1263
+ self.isError = true;
1264
+ self._updateFileDetails(0);
1265
+ $error.fadeIn(800);
1266
+ self._raise('fileerror', [params, msg]);
1267
+ self._clearFileInput();
1268
+ self._setValidationError();
1269
+ },
1270
+ _parseError: function (operation, jqXHR, errorThrown, fileName) {
1271
+ /** @namespace jqXHR.responseJSON */
1272
+ var self = this, errMsg = $.trim(errorThrown + ''), textPre,
1273
+ text = jqXHR.responseJSON !== undefined && jqXHR.responseJSON.error !== undefined ?
1274
+ jqXHR.responseJSON.error : jqXHR.responseText;
1275
+ if (self.cancelling && self.msgUploadAborted) {
1276
+ errMsg = self.msgUploadAborted;
1277
+ }
1278
+ if (self.showAjaxErrorDetails && text) {
1279
+ text = $.trim(text.replace(/\n\s*\n/g, '\n'));
1280
+ textPre = text.length ? '<pre>' + text + '</pre>' : '';
1281
+ errMsg += errMsg ? textPre : text;
1282
+ }
1283
+ if (!errMsg) {
1284
+ errMsg = self.msgAjaxError.replace('{operation}', operation);
1285
+ }
1286
+ self.cancelling = false;
1287
+ return fileName ? '<b>' + fileName + ': </b>' + errMsg : errMsg;
1288
+ },
1289
+ _parseFileType: function (type, name) {
1290
+ var self = this, isValid, vType, cat, i, types = self.allowedPreviewTypes || [];
1291
+ if (type === 'application/text-plain') {
1292
+ return 'text';
1293
+ }
1294
+ for (i = 0; i < types.length; i++) {
1295
+ cat = types[i];
1296
+ isValid = self.fileTypeSettings[cat];
1297
+ vType = isValid(type, name) ? cat : '';
1298
+ if (!$h.isEmpty(vType)) {
1299
+ return vType;
1300
+ }
1301
+ }
1302
+ return 'other';
1303
+ },
1304
+ _getPreviewIcon: function (fname) {
1305
+ var self = this, ext, out = null;
1306
+ if (fname && fname.indexOf('.') > -1) {
1307
+ ext = fname.split('.').pop();
1308
+ if (self.previewFileIconSettings) {
1309
+ out = self.previewFileIconSettings[ext] || self.previewFileIconSettings[ext.toLowerCase()] || null;
1310
+ }
1311
+ if (self.previewFileExtSettings) {
1312
+ $.each(self.previewFileExtSettings, function (key, func) {
1313
+ if (self.previewFileIconSettings[key] && func(ext)) {
1314
+ out = self.previewFileIconSettings[key];
1315
+ //noinspection UnnecessaryReturnStatementJS
1316
+ return;
1317
+ }
1318
+ });
1319
+ }
1320
+ }
1321
+ return out;
1322
+ },
1323
+ _parseFilePreviewIcon: function (content, fname) {
1324
+ var self = this, icn = self._getPreviewIcon(fname) || self.previewFileIcon, out = content;
1325
+ if (out.indexOf('{previewFileIcon}') > -1) {
1326
+ out = out.setTokens({'previewFileIconClass': self.previewFileIconClass, 'previewFileIcon': icn});
1327
+ }
1328
+ return out;
1329
+ },
1330
+ _raise: function (event, params) {
1331
+ var self = this, e = $.Event(event);
1332
+ if (params !== undefined) {
1333
+ self.$element.trigger(e, params);
1334
+ } else {
1335
+ self.$element.trigger(e);
1336
+ }
1337
+ if (e.isDefaultPrevented() || e.result === false) {
1338
+ return false;
1339
+ }
1340
+ switch (event) {
1341
+ // ignore these events
1342
+ case 'filebatchuploadcomplete':
1343
+ case 'filebatchuploadsuccess':
1344
+ case 'fileuploaded':
1345
+ case 'fileclear':
1346
+ case 'filecleared':
1347
+ case 'filereset':
1348
+ case 'fileerror':
1349
+ case 'filefoldererror':
1350
+ case 'fileuploaderror':
1351
+ case 'filebatchuploaderror':
1352
+ case 'filedeleteerror':
1353
+ case 'filecustomerror':
1354
+ case 'filesuccessremove':
1355
+ break;
1356
+ // receive data response via `filecustomerror` event`
1357
+ default:
1358
+ if (!self.ajaxAborted) {
1359
+ self.ajaxAborted = e.result;
1360
+ }
1361
+ break;
1362
+ }
1363
+ return true;
1364
+ },
1365
+ _listenFullScreen: function (isFullScreen) {
1366
+ var self = this, $modal = self.$modal, $btnFull, $btnBord;
1367
+ if (!$modal || !$modal.length) {
1368
+ return;
1369
+ }
1370
+ $btnFull = $modal && $modal.find('.btn-fullscreen');
1371
+ $btnBord = $modal && $modal.find('.btn-borderless');
1372
+ if (!$btnFull.length || !$btnBord.length) {
1373
+ return;
1374
+ }
1375
+ $btnFull.removeClass('active').attr('aria-pressed', 'false');
1376
+ $btnBord.removeClass('active').attr('aria-pressed', 'false');
1377
+ if (isFullScreen) {
1378
+ $btnFull.addClass('active').attr('aria-pressed', 'true');
1379
+ } else {
1380
+ $btnBord.addClass('active').attr('aria-pressed', 'true');
1381
+ }
1382
+ if ($modal.hasClass('file-zoom-fullscreen')) {
1383
+ self._maximizeZoomDialog();
1384
+ } else {
1385
+ if (isFullScreen) {
1386
+ self._maximizeZoomDialog();
1387
+ } else {
1388
+ $btnBord.removeClass('active').attr('aria-pressed', 'false');
1389
+ }
1390
+ }
1391
+ },
1392
+ _listen: function () {
1393
+ var self = this, $el = self.$element, $form = self.$form, $cont = self.$container, fullScreenEvents;
1394
+ self._handler($el, 'click', function(e) {
1395
+ if ($el.hasClass('file-no-browse')) {
1396
+ if ($el.data('zoneClicked')) {
1397
+ $el.data('zoneClicked', false);
1398
+ } else {
1399
+ e.preventDefault();
1400
+ }
1401
+ }
1402
+ });
1403
+ self._handler($el, 'change', $.proxy(self._change, self));
1404
+ if (self.showBrowse) {
1405
+ self._handler(self.$btnFile, 'click', $.proxy(self._browse, self));
1406
+ }
1407
+ self._handler($cont.find('.fileinput-remove:not([disabled])'), 'click', $.proxy(self.clear, self));
1408
+ self._handler($cont.find('.fileinput-cancel'), 'click', $.proxy(self.cancel, self));
1409
+ self._initDragDrop();
1410
+ self._handler($form, 'reset', $.proxy(self.clear, self));
1411
+ if (!self.isAjaxUpload) {
1412
+ self._handler($form, 'submit', $.proxy(self._submitForm, self));
1413
+ }
1414
+ self._handler(self.$container.find('.fileinput-upload'), 'click', $.proxy(self._uploadClick, self));
1415
+ self._handler($(window), 'resize', function () {
1416
+ self._listenFullScreen(screen.width === window.innerWidth && screen.height === window.innerHeight);
1417
+ });
1418
+ fullScreenEvents = 'webkitfullscreenchange mozfullscreenchange fullscreenchange MSFullscreenChange';
1419
+ self._handler($(document), fullScreenEvents, function () {
1420
+ self._listenFullScreen($h.checkFullScreen());
1421
+ });
1422
+ self._autoFitContent();
1423
+ self._initClickable();
1424
+ self._refreshPreview();
1425
+ },
1426
+ _autoFitContent: function () {
1427
+ var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
1428
+ self = this, config = width < 400 ? (self.previewSettingsSmall || self.defaults.previewSettingsSmall) :
1429
+ (self.previewSettings || self.defaults.previewSettings), sel;
1430
+ $.each(config, function (cat, settings) {
1431
+ sel = '.file-preview-frame .file-preview-' + cat;
1432
+ self.$preview.find(sel + '.kv-preview-data,' + sel + ' .kv-preview-data').css(settings);
1433
+ });
1434
+ },
1435
+ _scanDroppedItems: function (item, files, path) {
1436
+ path = path || "";
1437
+ var self = this, i, dirReader, readDir, errorHandler = function (e) {
1438
+ self._log('Error scanning dropped files!');
1439
+ self._log(e);
1440
+ };
1441
+ if (item.isFile) {
1442
+ item.file(function (file) {
1443
+ files.push(file);
1444
+ }, errorHandler);
1445
+ } else {
1446
+ if (item.isDirectory) {
1447
+ dirReader = item.createReader();
1448
+ readDir = function () {
1449
+ dirReader.readEntries(function (entries) {
1450
+ if (entries && entries.length > 0) {
1451
+ for (i = 0; i < entries.length; i++) {
1452
+ self._scanDroppedItems(entries[i], files, path + item.name + "/");
1453
+ }
1454
+ // recursively call readDir() again, since browser can only handle first 100 entries.
1455
+ readDir();
1456
+ }
1457
+ return null;
1458
+ }, errorHandler);
1459
+ };
1460
+ readDir();
1461
+ }
1462
+ }
1463
+
1464
+ },
1465
+ _initDragDrop: function () {
1466
+ var self = this, $zone = self.$dropZone;
1467
+ if (self.dropZoneEnabled && self.showPreview) {
1468
+ self._handler($zone, 'dragenter dragover', $.proxy(self._zoneDragEnter, self));
1469
+ self._handler($zone, 'dragleave', $.proxy(self._zoneDragLeave, self));
1470
+ self._handler($zone, 'drop', $.proxy(self._zoneDrop, self));
1471
+ self._handler($(document), 'dragenter dragover drop', self._zoneDragDropInit);
1472
+ }
1473
+ },
1474
+ _zoneDragDropInit: function (e) {
1475
+ e.stopPropagation();
1476
+ e.preventDefault();
1477
+ },
1478
+ _zoneDragEnter: function (e) {
1479
+ var self = this, hasFiles = $.inArray('Files', e.originalEvent.dataTransfer.types) > -1;
1480
+ self._zoneDragDropInit(e);
1481
+ if (self.isDisabled || !hasFiles) {
1482
+ e.originalEvent.dataTransfer.effectAllowed = 'none';
1483
+ e.originalEvent.dataTransfer.dropEffect = 'none';
1484
+ return;
1485
+ }
1486
+ $h.addCss(self.$dropZone, 'file-highlighted');
1487
+ },
1488
+ _zoneDragLeave: function (e) {
1489
+ var self = this;
1490
+ self._zoneDragDropInit(e);
1491
+ if (self.isDisabled) {
1492
+ return;
1493
+ }
1494
+ self.$dropZone.removeClass('file-highlighted');
1495
+ },
1496
+ _zoneDrop: function (e) {
1497
+ /** @namespace e.originalEvent.dataTransfer */
1498
+ var self = this, i, $el = self.$element, dataTransfer = e.originalEvent.dataTransfer,
1499
+ files = dataTransfer.files, items = dataTransfer.items, folders = $h.getDragDropFolders(items),
1500
+ processFiles = function () {
1501
+ if (!self.isAjaxUpload) {
1502
+ self.changeTriggered = true;
1503
+ $el.get(0).files = files;
1504
+ setTimeout(function () {
1505
+ self.changeTriggered = false;
1506
+ $el.trigger('change' + self.namespace);
1507
+ }, 10);
1508
+ } else {
1509
+ self._change(e, files);
1510
+ }
1511
+ self.$dropZone.removeClass('file-highlighted');
1512
+ };
1513
+ e.preventDefault();
1514
+ if (self.isDisabled || $h.isEmpty(files)) {
1515
+ return;
1516
+ }
1517
+ if (folders > 0) {
1518
+ if (!self.isAjaxUpload) {
1519
+ self._showFolderError(folders);
1520
+ return;
1521
+ }
1522
+ files = [];
1523
+ for (i = 0; i < items.length; i++) {
1524
+ var item = items[i].webkitGetAsEntry();
1525
+ if (item) {
1526
+ self._scanDroppedItems(item, files);
1527
+ }
1528
+ }
1529
+ setTimeout(function () {
1530
+ processFiles();
1531
+ }, 500);
1532
+ } else {
1533
+ processFiles();
1534
+ }
1535
+ },
1536
+ _uploadClick: function (e) {
1537
+ var self = this, $btn = self.$container.find('.fileinput-upload'), $form,
1538
+ isEnabled = !$btn.hasClass('disabled') && $h.isEmpty($btn.attr('disabled'));
1539
+ if (e && e.isDefaultPrevented()) {
1540
+ return;
1541
+ }
1542
+ if (!self.isAjaxUpload) {
1543
+ if (isEnabled && $btn.attr('type') !== 'submit') {
1544
+ $form = $btn.closest('form');
1545
+ // downgrade to normal form submit if possible
1546
+ if ($form.length) {
1547
+ $form.trigger('submit');
1548
+ }
1549
+ e.preventDefault();
1550
+ }
1551
+ return;
1552
+ }
1553
+ e.preventDefault();
1554
+ if (isEnabled) {
1555
+ self.upload();
1556
+ }
1557
+ },
1558
+ _submitForm: function () {
1559
+ var self = this;
1560
+ return self._isFileSelectionValid() && !self._abort({});
1561
+ },
1562
+ _clearPreview: function () {
1563
+ var self = this, $p = self.$preview,
1564
+ $thumbs = self.showUploadedThumbs ? self.getFrames(':not(.file-preview-success)') : self.getFrames();
1565
+ $thumbs.each(function () {
1566
+ var $thumb = $(this);
1567
+ $thumb.remove();
1568
+ $h.cleanZoomCache($p.find('#zoom-' + $thumb.attr('id')));
1569
+ });
1570
+ if (!self.getFrames().length || !self.showPreview) {
1571
+ self._resetUpload();
1572
+ }
1573
+ self._validateDefaultPreview();
1574
+ },
1575
+ _initSortable: function () {
1576
+ var self = this, $el = self.$preview, settings, selector = '.' + $h.SORT_CSS,
1577
+ rev = self.reversePreviewOrder;
1578
+ if (!window.KvSortable || $el.find(selector).length === 0) {
1579
+ return;
1580
+ }
1581
+ //noinspection JSUnusedGlobalSymbols
1582
+ settings = {
1583
+ handle: '.drag-handle-init',
1584
+ dataIdAttr: 'data-preview-id',
1585
+ scroll: false,
1586
+ draggable: selector,
1587
+ onSort: function (e) {
1588
+ var oldIndex = e.oldIndex, newIndex = e.newIndex, i = 0;
1589
+ self.initialPreview = $h.moveArray(self.initialPreview, oldIndex, newIndex, rev);
1590
+ self.initialPreviewConfig = $h.moveArray(self.initialPreviewConfig, oldIndex, newIndex, rev);
1591
+ self.previewCache.init();
1592
+ self.getFrames('.file-preview-initial').each(function () {
1593
+ $(this).attr('data-fileindex', 'init_' + i);
1594
+ i++;
1595
+ });
1596
+ self._raise('filesorted', {
1597
+ previewId: $(e.item).attr('id'),
1598
+ 'oldIndex': oldIndex,
1599
+ 'newIndex': newIndex,
1600
+ stack: self.initialPreviewConfig
1601
+ });
1602
+ }
1603
+ };
1604
+ if ($el.data('kvsortable')) {
1605
+ $el.kvsortable('destroy');
1606
+ }
1607
+ $.extend(true, settings, self.fileActionSettings.dragSettings);
1608
+ $el.kvsortable(settings);
1609
+ },
1610
+ _setPreviewContent: function (content) {
1611
+ var self = this;
1612
+ self.$preview.html(content);
1613
+ self._autoFitContent();
1614
+ },
1615
+ _initPreview: function (isInit) {
1616
+ var self = this, cap = self.initialCaption || '', out;
1617
+ if (!self.previewCache.count()) {
1618
+ self._clearPreview();
1619
+ if (isInit) {
1620
+ self._setCaption(cap);
1621
+ } else {
1622
+ self._initCaption();
1623
+ }
1624
+ return;
1625
+ }
1626
+ out = self.previewCache.out();
1627
+ cap = isInit && self.initialCaption ? self.initialCaption : out.caption;
1628
+ self._setPreviewContent(out.content);
1629
+ self._setInitThumbAttr();
1630
+ self._setCaption(cap);
1631
+ self._initSortable();
1632
+ if (!$h.isEmpty(out.content)) {
1633
+ self.$container.removeClass('file-input-new');
1634
+ }
1635
+ },
1636
+ _getZoomButton: function (type) {
1637
+ var self = this, label = self.previewZoomButtonIcons[type], css = self.previewZoomButtonClasses[type],
1638
+ title = ' title="' + (self.previewZoomButtonTitles[type] || '') + '" ',
1639
+ params = title + (type === 'close' ? ' data-dismiss="modal" aria-hidden="true"' : '');
1640
+ if (type === 'fullscreen' || type === 'borderless' || type === 'toggleheader') {
1641
+ params += ' data-toggle="button" aria-pressed="false" autocomplete="off"';
1642
+ }
1643
+ return '<button type="button" class="' + css + ' btn-' + type + '"' + params + '>' + label + '</button>';
1644
+ },
1645
+ _getModalContent: function () {
1646
+ var self = this;
1647
+ return self._getLayoutTemplate('modal').setTokens({
1648
+ 'rtl': self.rtl ? ' kv-rtl' : '',
1649
+ 'zoomFrameClass': self.frameClass,
1650
+ 'heading': self.msgZoomModalHeading,
1651
+ 'prev': self._getZoomButton('prev'),
1652
+ 'next': self._getZoomButton('next'),
1653
+ 'toggleheader': self._getZoomButton('toggleheader'),
1654
+ 'fullscreen': self._getZoomButton('fullscreen'),
1655
+ 'borderless': self._getZoomButton('borderless'),
1656
+ 'close': self._getZoomButton('close')
1657
+ });
1658
+ },
1659
+ _listenModalEvent: function (event) {
1660
+ var self = this, $modal = self.$modal, getParams = function (e) {
1661
+ return {
1662
+ sourceEvent: e,
1663
+ previewId: $modal.data('previewId'),
1664
+ modal: $modal
1665
+ };
1666
+ };
1667
+ $modal.on(event + '.bs.modal', function (e) {
1668
+ var $btnFull = $modal.find('.btn-fullscreen'), $btnBord = $modal.find('.btn-borderless');
1669
+ self._raise('filezoom' + event, getParams(e));
1670
+ if (event === 'shown') {
1671
+ $btnBord.removeClass('active').attr('aria-pressed', 'false');
1672
+ $btnFull.removeClass('active').attr('aria-pressed', 'false');
1673
+ if ($modal.hasClass('file-zoom-fullscreen')) {
1674
+ self._maximizeZoomDialog();
1675
+ if ($h.checkFullScreen()) {
1676
+ $btnFull.addClass('active').attr('aria-pressed', 'true');
1677
+ } else {
1678
+ $btnBord.addClass('active').attr('aria-pressed', 'true');
1679
+ }
1680
+ }
1681
+ }
1682
+ });
1683
+ },
1684
+ _initZoom: function () {
1685
+ var self = this, $dialog, modalMain = self._getLayoutTemplate('modalMain'), modalId = '#' + $h.MODAL_ID;
1686
+ if (!self.showPreview) {
1687
+ return;
1688
+ }
1689
+ self.$modal = $(modalId);
1690
+ if (!self.$modal || !self.$modal.length) {
1691
+ $dialog = $(document.createElement('div')).html(modalMain).insertAfter(self.$container);
1692
+ self.$modal = $(modalId).insertBefore($dialog);
1693
+ $dialog.remove();
1694
+ }
1695
+ $h.initModal(self.$modal);
1696
+ self.$modal.html(self._getModalContent());
1697
+ $.each($h.MODAL_EVENTS, function (key, event) {
1698
+ self._listenModalEvent(event);
1699
+ });
1700
+ },
1701
+ _initZoomButtons: function () {
1702
+ var self = this, previewId = self.$modal.data('previewId') || '', $first, $last,
1703
+ thumbs = self.getFrames().toArray(), len = thumbs.length, $prev = self.$modal.find('.btn-prev'),
1704
+ $next = self.$modal.find('.btn-next');
1705
+ if (thumbs.length < 2) {
1706
+ $prev.hide();
1707
+ $next.hide();
1708
+ return;
1709
+ } else {
1710
+ $prev.show();
1711
+ $next.show();
1712
+ }
1713
+ if (!len) {
1714
+ return;
1715
+ }
1716
+ $first = $(thumbs[0]);
1717
+ $last = $(thumbs[len - 1]);
1718
+ $prev.removeAttr('disabled');
1719
+ $next.removeAttr('disabled');
1720
+ if ($first.length && $first.attr('id') === previewId) {
1721
+ $prev.attr('disabled', true);
1722
+ }
1723
+ if ($last.length && $last.attr('id') === previewId) {
1724
+ $next.attr('disabled', true);
1725
+ }
1726
+ },
1727
+ _maximizeZoomDialog: function () {
1728
+ var self = this, $modal = self.$modal, $head = $modal.find('.modal-header:visible'),
1729
+ $foot = $modal.find('.modal-footer:visible'), $body = $modal.find('.modal-body'),
1730
+ h = $(window).height(), diff = 0;
1731
+ $modal.addClass('file-zoom-fullscreen');
1732
+ if ($head && $head.length) {
1733
+ h -= $head.outerHeight(true);
1734
+ }
1735
+ if ($foot && $foot.length) {
1736
+ h -= $foot.outerHeight(true);
1737
+ }
1738
+ if ($body && $body.length) {
1739
+ diff = $body.outerHeight(true) - $body.height();
1740
+ h -= diff;
1741
+ }
1742
+ $modal.find('.kv-zoom-body').height(h);
1743
+ },
1744
+ _resizeZoomDialog: function (fullScreen) {
1745
+ var self = this, $modal = self.$modal, $btnFull = $modal.find('.btn-fullscreen'),
1746
+ $btnBord = $modal.find('.btn-borderless');
1747
+ if ($modal.hasClass('file-zoom-fullscreen')) {
1748
+ $h.toggleFullScreen(false);
1749
+ if (!fullScreen) {
1750
+ if (!$btnFull.hasClass('active')) {
1751
+ $modal.removeClass('file-zoom-fullscreen');
1752
+ self.$modal.find('.kv-zoom-body').css('height', self.zoomModalHeight);
1753
+ } else {
1754
+ $btnFull.removeClass('active').attr('aria-pressed', 'false');
1755
+ }
1756
+ } else {
1757
+ if (!$btnFull.hasClass('active')) {
1758
+ $modal.removeClass('file-zoom-fullscreen');
1759
+ self._resizeZoomDialog(true);
1760
+ if ($btnBord.hasClass('active')) {
1761
+ $btnBord.removeClass('active').attr('aria-pressed', 'false');
1762
+ }
1763
+ }
1764
+ }
1765
+ } else {
1766
+ if (!fullScreen) {
1767
+ self._maximizeZoomDialog();
1768
+ return;
1769
+ }
1770
+ $h.toggleFullScreen(true);
1771
+ }
1772
+ $modal.focus();
1773
+ },
1774
+ _setZoomContent: function ($frame, animate) {
1775
+ var self = this, $content, tmplt, body, title, $body, $dataEl, config, pid = $frame.attr('id'),
1776
+ $modal = self.$modal, $prev = $modal.find('.btn-prev'), $next = $modal.find('.btn-next'), $tmp,
1777
+ $btnFull = $modal.find('.btn-fullscreen'), $btnBord = $modal.find('.btn-borderless'), cap, size,
1778
+ $btnTogh = $modal.find('.btn-toggleheader'), $zoomPreview = self.$preview.find('#zoom-' + pid);
1779
+ tmplt = $zoomPreview.attr('data-template') || 'generic';
1780
+ $content = $zoomPreview.find('.kv-file-content');
1781
+ body = $content.length ? $content.html() : '';
1782
+ cap = $frame.data('caption') || '';
1783
+ size = $frame.data('size') || '';
1784
+ title = cap + ' ' + size;
1785
+ $modal.find('.kv-zoom-title').attr('title', $('<div/>').html(title).text()).html(title);
1786
+ $body = $modal.find('.kv-zoom-body');
1787
+ $modal.removeClass('kv-single-content');
1788
+ if (animate) {
1789
+ $tmp = $body.addClass('file-thumb-loading').clone().insertAfter($body);
1790
+ $body.html(body).hide();
1791
+ $tmp.fadeOut('fast', function () {
1792
+ $body.fadeIn('fast', function () {
1793
+ $body.removeClass('file-thumb-loading');
1794
+ });
1795
+ $tmp.remove();
1796
+ });
1797
+ } else {
1798
+ $body.html(body);
1799
+ }
1800
+ config = self.previewZoomSettings[tmplt];
1801
+ if (config) {
1802
+ $dataEl = $body.find('.kv-preview-data');
1803
+ $h.addCss($dataEl, 'file-zoom-detail');
1804
+ $.each(config, function (key, value) {
1805
+ $dataEl.css(key, value);
1806
+ if (($dataEl.attr('width') && key === 'width') || ($dataEl.attr('height') && key === 'height')) {
1807
+ $dataEl.removeAttr(key);
1808
+ }
1809
+ });
1810
+ }
1811
+ $modal.data('previewId', pid);
1812
+ var $img = $body.find('img');
1813
+ if ($img.length) {
1814
+ $h.adjustOrientedImage($img, true);
1815
+ }
1816
+ self._handler($prev, 'click', function () {
1817
+ self._zoomSlideShow('prev', pid);
1818
+ });
1819
+ self._handler($next, 'click', function () {
1820
+ self._zoomSlideShow('next', pid);
1821
+ });
1822
+ self._handler($btnFull, 'click', function () {
1823
+ self._resizeZoomDialog(true);
1824
+ });
1825
+ self._handler($btnBord, 'click', function () {
1826
+ self._resizeZoomDialog(false);
1827
+ });
1828
+ self._handler($btnTogh, 'click', function () {
1829
+ var $header = $modal.find('.modal-header'), $floatBar = $modal.find('.modal-body .floating-buttons'),
1830
+ ht, $actions = $header.find('.kv-zoom-actions'), resize = function (height) {
1831
+ var $body = self.$modal.find('.kv-zoom-body'), h = self.zoomModalHeight;
1832
+ if ($modal.hasClass('file-zoom-fullscreen')) {
1833
+ h = $body.outerHeight(true);
1834
+ if (!height) {
1835
+ h = h - $header.outerHeight(true);
1836
+ }
1837
+ }
1838
+ $body.css('height', height ? h + height : h);
1839
+ };
1840
+ if ($header.is(':visible')) {
1841
+ ht = $header.outerHeight(true);
1842
+ $header.slideUp('slow', function () {
1843
+ $actions.find('.btn').appendTo($floatBar);
1844
+ resize(ht);
1845
+ });
1846
+ } else {
1847
+ $floatBar.find('.btn').appendTo($actions);
1848
+ $header.slideDown('slow', function () {
1849
+ resize();
1850
+ });
1851
+ }
1852
+ $modal.focus();
1853
+ });
1854
+ self._handler($modal, 'keydown', function (e) {
1855
+ var key = e.which || e.keyCode;
1856
+ if (key === 37 && !$prev.attr('disabled')) {
1857
+ self._zoomSlideShow('prev', pid);
1858
+ }
1859
+ if (key === 39 && !$next.attr('disabled')) {
1860
+ self._zoomSlideShow('next', pid);
1861
+ }
1862
+ });
1863
+ },
1864
+ _zoomPreview: function ($btn) {
1865
+ var self = this, $frame, $modal = self.$modal;
1866
+ if (!$btn.length) {
1867
+ throw 'Cannot zoom to detailed preview!';
1868
+ }
1869
+ $h.initModal($modal);
1870
+ $modal.html(self._getModalContent());
1871
+ $frame = $btn.closest($h.FRAMES);
1872
+ self._setZoomContent($frame);
1873
+ $modal.modal('show');
1874
+ self._initZoomButtons();
1875
+ },
1876
+ _zoomSlideShow: function (dir, previewId) {
1877
+ var self = this, $btn = self.$modal.find('.kv-zoom-actions .btn-' + dir), $targFrame, i,
1878
+ thumbs = self.getFrames().toArray(), len = thumbs.length, out;
1879
+ if ($btn.attr('disabled')) {
1880
+ return;
1881
+ }
1882
+ for (i = 0; i < len; i++) {
1883
+ if ($(thumbs[i]).attr('id') === previewId) {
1884
+ out = dir === 'prev' ? i - 1 : i + 1;
1885
+ break;
1886
+ }
1887
+ }
1888
+ if (out < 0 || out >= len || !thumbs[out]) {
1889
+ return;
1890
+ }
1891
+ $targFrame = $(thumbs[out]);
1892
+ if ($targFrame.length) {
1893
+ self._setZoomContent($targFrame, true);
1894
+ }
1895
+ self._initZoomButtons();
1896
+ self._raise('filezoom' + dir, {'previewId': previewId, modal: self.$modal});
1897
+ },
1898
+ _initZoomButton: function () {
1899
+ var self = this;
1900
+ self.$preview.find('.kv-file-zoom').each(function () {
1901
+ var $el = $(this);
1902
+ self._handler($el, 'click', function () {
1903
+ self._zoomPreview($el);
1904
+ });
1905
+ });
1906
+ },
1907
+ _inputFileCount: function() {
1908
+ return this.$element.get(0).files.length;
1909
+ },
1910
+ _refreshPreview: function() {
1911
+ var self = this, files;
1912
+ if (!self._inputFileCount() || !self.showPreview || !self.isPreviewable) {
1913
+ return;
1914
+ }
1915
+ if (self.isAjaxUpload) {
1916
+ files = self.getFileStack();
1917
+ self.filestack = [];
1918
+ if (files.length) {
1919
+ self._clearFileInput();
1920
+ } else {
1921
+ files = self.$element.get(0).files;
1922
+ }
1923
+ } else {
1924
+ files = self.$element.get(0).files;
1925
+ }
1926
+ if (files && files.length) {
1927
+ self.readFiles(files);
1928
+ self._setFileDropZoneTitle();
1929
+ }
1930
+ },
1931
+ _clearObjects: function ($el) {
1932
+ $el.find('video audio').each(function () {
1933
+ this.pause();
1934
+ $(this).remove();
1935
+ });
1936
+ $el.find('img object div').each(function () {
1937
+ $(this).remove();
1938
+ });
1939
+ },
1940
+ _clearFileInput: function () {
1941
+ var self = this, $el = self.$element, $srcFrm, $tmpFrm, $tmpEl;
1942
+ if (!self._inputFileCount()) {
1943
+ return;
1944
+ }
1945
+ $srcFrm = $el.closest('form');
1946
+ $tmpFrm = $(document.createElement('form'));
1947
+ $tmpEl = $(document.createElement('div'));
1948
+ $el.before($tmpEl);
1949
+ if ($srcFrm.length) {
1950
+ $srcFrm.after($tmpFrm);
1951
+ } else {
1952
+ $tmpEl.after($tmpFrm);
1953
+ }
1954
+ $tmpFrm.append($el).trigger('reset');
1955
+ $tmpEl.before($el).remove();
1956
+ $tmpFrm.remove();
1957
+ },
1958
+ _resetUpload: function () {
1959
+ var self = this;
1960
+ self.uploadCache = {content: [], config: [], tags: [], append: true};
1961
+ self.uploadCount = 0;
1962
+ self.uploadStatus = {};
1963
+ self.uploadLog = [];
1964
+ self.uploadAsyncCount = 0;
1965
+ self.loadedImages = [];
1966
+ self.totalImagesCount = 0;
1967
+ self.$btnUpload.removeAttr('disabled');
1968
+ self._setProgress(0);
1969
+ self.$progress.hide();
1970
+ self._resetErrors(false);
1971
+ self.ajaxAborted = false;
1972
+ self.ajaxRequests = [];
1973
+ self._resetCanvas();
1974
+ self.cacheInitialPreview = {};
1975
+ if (self.overwriteInitial) {
1976
+ self.initialPreview = [];
1977
+ self.initialPreviewConfig = [];
1978
+ self.initialPreviewThumbTags = [];
1979
+ self.previewCache.data = {
1980
+ content: [],
1981
+ config: [],
1982
+ tags: []
1983
+ };
1984
+ }
1985
+ },
1986
+ _resetCanvas: function () {
1987
+ var self = this;
1988
+ if (self.canvas && self.imageCanvasContext) {
1989
+ self.imageCanvasContext.clearRect(0, 0, self.canvas.width, self.canvas.height);
1990
+ }
1991
+ },
1992
+ _hasInitialPreview: function () {
1993
+ var self = this;
1994
+ return !self.overwriteInitial && self.previewCache.count();
1995
+ },
1996
+ _resetPreview: function () {
1997
+ var self = this, out, cap;
1998
+ if (self.previewCache.count()) {
1999
+ out = self.previewCache.out();
2000
+ self._setPreviewContent(out.content);
2001
+ self._setInitThumbAttr();
2002
+ cap = self.initialCaption ? self.initialCaption : out.caption;
2003
+ self._setCaption(cap);
2004
+ } else {
2005
+ self._clearPreview();
2006
+ self._initCaption();
2007
+ }
2008
+ if (self.showPreview) {
2009
+ self._initZoom();
2010
+ self._initSortable();
2011
+ }
2012
+ },
2013
+ _clearDefaultPreview: function () {
2014
+ var self = this;
2015
+ self.$preview.find('.file-default-preview').remove();
2016
+ },
2017
+ _validateDefaultPreview: function () {
2018
+ var self = this;
2019
+ if (!self.showPreview || $h.isEmpty(self.defaultPreviewContent)) {
2020
+ return;
2021
+ }
2022
+ self._setPreviewContent('<div class="file-default-preview">' + self.defaultPreviewContent + '</div>');
2023
+ self.$container.removeClass('file-input-new');
2024
+ self._initClickable();
2025
+ },
2026
+ _resetPreviewThumbs: function (isAjax) {
2027
+ var self = this, out;
2028
+ if (isAjax) {
2029
+ self._clearPreview();
2030
+ self.clearStack();
2031
+ return;
2032
+ }
2033
+ if (self._hasInitialPreview()) {
2034
+ out = self.previewCache.out();
2035
+ self._setPreviewContent(out.content);
2036
+ self._setInitThumbAttr();
2037
+ self._setCaption(out.caption);
2038
+ self._initPreviewActions();
2039
+ } else {
2040
+ self._clearPreview();
2041
+ }
2042
+ },
2043
+ _getLayoutTemplate: function (t) {
2044
+ var self = this, template = self.layoutTemplates[t];
2045
+ if ($h.isEmpty(self.customLayoutTags)) {
2046
+ return template;
2047
+ }
2048
+ return $h.replaceTags(template, self.customLayoutTags);
2049
+ },
2050
+ _getPreviewTemplate: function (t) {
2051
+ var self = this, template = self.previewTemplates[t];
2052
+ if ($h.isEmpty(self.customPreviewTags)) {
2053
+ return template;
2054
+ }
2055
+ return $h.replaceTags(template, self.customPreviewTags);
2056
+ },
2057
+ _getOutData: function (jqXHR, responseData, filesData) {
2058
+ var self = this;
2059
+ jqXHR = jqXHR || {};
2060
+ responseData = responseData || {};
2061
+ filesData = filesData || self.filestack.slice(0) || {};
2062
+ return {
2063
+ form: self.formdata,
2064
+ files: filesData,
2065
+ filenames: self.filenames,
2066
+ filescount: self.getFilesCount(),
2067
+ extra: self._getExtraData(),
2068
+ response: responseData,
2069
+ reader: self.reader,
2070
+ jqXHR: jqXHR
2071
+ };
2072
+ },
2073
+ _getMsgSelected: function (n) {
2074
+ var self = this, strFiles = n === 1 ? self.fileSingle : self.filePlural;
2075
+ return n > 0 ? self.msgSelected.replace('{n}', n).replace('{files}', strFiles) : self.msgNoFilesSelected;
2076
+ },
2077
+ _getFrame: function (id) {
2078
+ var self = this, $frame = $('#' + id);
2079
+ if (!$frame.length) {
2080
+ self._log('Invalid thumb frame with id: "' + id + '".');
2081
+ return null;
2082
+ }
2083
+ return $frame;
2084
+ },
2085
+ _getThumbs: function (css) {
2086
+ css = css || '';
2087
+ return this.getFrames(':not(.file-preview-initial)' + css);
2088
+ },
2089
+ _getExtraData: function (previewId, index) {
2090
+ var self = this, data = self.uploadExtraData;
2091
+ if (typeof self.uploadExtraData === "function") {
2092
+ data = self.uploadExtraData(previewId, index);
2093
+ }
2094
+ return data;
2095
+ },
2096
+ _initXhr: function (xhrobj, previewId, fileCount) {
2097
+ var self = this;
2098
+ if (xhrobj.upload) {
2099
+ xhrobj.upload.addEventListener('progress', function (event) {
2100
+ var pct = 0, total = event.total, position = event.loaded || event.position;
2101
+ /** @namespace event.lengthComputable */
2102
+ if (event.lengthComputable) {
2103
+ pct = Math.floor(position / total * 100);
2104
+ }
2105
+ if (previewId) {
2106
+ self._setAsyncUploadStatus(previewId, pct, fileCount);
2107
+ } else {
2108
+ self._setProgress(pct);
2109
+ }
2110
+ }, false);
2111
+ }
2112
+ return xhrobj;
2113
+ },
2114
+ _initAjaxSettings: function () {
2115
+ var self = this;
2116
+ self._ajaxSettings = $.extend(true, {}, self.ajaxSettings);
2117
+ self._ajaxDeleteSettings = $.extend(true, {}, self.ajaxDeleteSettings);
2118
+ },
2119
+ _mergeAjaxCallback: function (funcName, srcFunc, type) {
2120
+ var self = this, settings = self._ajaxSettings, flag = self.mergeAjaxCallbacks, targFunc;
2121
+ if (type === 'delete') {
2122
+ settings = self._ajaxDeleteSettings;
2123
+ flag = self.mergeAjaxDeleteCallbacks;
2124
+ }
2125
+ targFunc = settings[funcName];
2126
+ if (flag && typeof targFunc === "function") {
2127
+ if (flag === 'before') {
2128
+ settings[funcName] = function () {
2129
+ targFunc.apply(this, arguments);
2130
+ srcFunc.apply(this, arguments);
2131
+ };
2132
+ } else {
2133
+ settings[funcName] = function () {
2134
+ srcFunc.apply(this, arguments);
2135
+ targFunc.apply(this, arguments);
2136
+ };
2137
+ }
2138
+ } else {
2139
+ settings[funcName] = srcFunc;
2140
+ }
2141
+ },
2142
+ _ajaxSubmit: function (fnBefore, fnSuccess, fnComplete, fnError, previewId, index) {
2143
+ var self = this, settings;
2144
+ if (!self._raise('filepreajax', [previewId, index])) {
2145
+ return;
2146
+ }
2147
+ self._uploadExtra(previewId, index);
2148
+ self._initAjaxSettings();
2149
+ self._mergeAjaxCallback('beforeSend', fnBefore);
2150
+ self._mergeAjaxCallback('success', fnSuccess);
2151
+ self._mergeAjaxCallback('complete', fnComplete);
2152
+ self._mergeAjaxCallback('error', fnError);
2153
+ settings = $.extend(true, {}, {
2154
+ xhr: function () {
2155
+ var xhrobj = $.ajaxSettings.xhr();
2156
+ return self._initXhr(xhrobj, previewId, self.getFileStack().length);
2157
+ },
2158
+ url: index && self.uploadUrlThumb ? self.uploadUrlThumb : self.uploadUrl,
2159
+ type: 'POST',
2160
+ dataType: 'json',
2161
+ data: self.formdata,
2162
+ cache: false,
2163
+ processData: false,
2164
+ contentType: false
2165
+ }, self._ajaxSettings);
2166
+ self.ajaxRequests.push($.ajax(settings));
2167
+ },
2168
+ _mergeArray: function (prop, content) {
2169
+ var self = this, arr1 = $h.cleanArray(self[prop]), arr2 = $h.cleanArray(content);
2170
+ self[prop] = arr1.concat(arr2);
2171
+ },
2172
+ _initUploadSuccess: function (out, $thumb, allFiles) {
2173
+ var self = this, append, data, index, $div, $newCache, content, config, tags, i;
2174
+ if (!self.showPreview || typeof out !== 'object' || $.isEmptyObject(out)) {
2175
+ return;
2176
+ }
2177
+ if (out.initialPreview !== undefined && out.initialPreview.length > 0) {
2178
+ self.hasInitData = true;
2179
+ content = out.initialPreview || [];
2180
+ config = out.initialPreviewConfig || [];
2181
+ tags = out.initialPreviewThumbTags || [];
2182
+ append = out.append === undefined || out.append;
2183
+ if (content.length > 0 && !$h.isArray(content)) {
2184
+ content = content.split(self.initialPreviewDelimiter);
2185
+ }
2186
+ self._mergeArray('initialPreview', content);
2187
+ self._mergeArray('initialPreviewConfig', config);
2188
+ self._mergeArray('initialPreviewThumbTags', tags);
2189
+ if ($thumb !== undefined) {
2190
+ if (!allFiles) {
2191
+ index = self.previewCache.add(content, config[0], tags[0], append);
2192
+ data = self.previewCache.get(index, false);
2193
+ $div = $(document.createElement('div')).html(data).hide().insertAfter($thumb);
2194
+ $newCache = $div.find('.kv-zoom-cache');
2195
+ if ($newCache && $newCache.length) {
2196
+ $newCache.insertAfter($thumb);
2197
+ }
2198
+ $thumb.fadeOut('slow', function () {
2199
+ var $newThumb = $div.find('.file-preview-frame');
2200
+ if ($newThumb && $newThumb.length) {
2201
+ $newThumb.insertBefore($thumb).fadeIn('slow').css('display:inline-block');
2202
+ }
2203
+ self._initPreviewActions();
2204
+ self._clearFileInput();
2205
+ $h.cleanZoomCache(self.$preview.find('#zoom-' + $thumb.attr('id')));
2206
+ $thumb.remove();
2207
+ $div.remove();
2208
+ self._initSortable();
2209
+ });
2210
+ } else {
2211
+ i = $thumb.attr('data-fileindex');
2212
+ self.uploadCache.content[i] = content[0];
2213
+ self.uploadCache.config[i] = config[0] || [];
2214
+ self.uploadCache.tags[i] = tags[0] || [];
2215
+ self.uploadCache.append = append;
2216
+ }
2217
+ } else {
2218
+ self.previewCache.set(content, config, tags, append);
2219
+ self._initPreview();
2220
+ self._initPreviewActions();
2221
+ }
2222
+ }
2223
+ },
2224
+ _initSuccessThumbs: function () {
2225
+ var self = this;
2226
+ if (!self.showPreview) {
2227
+ return;
2228
+ }
2229
+ self._getThumbs($h.FRAMES + '.file-preview-success').each(function () {
2230
+ var $thumb = $(this), $preview = self.$preview, $remove = $thumb.find('.kv-file-remove');
2231
+ $remove.removeAttr('disabled');
2232
+ self._handler($remove, 'click', function () {
2233
+ var id = $thumb.attr('id'),
2234
+ out = self._raise('filesuccessremove', [id, $thumb.attr('data-fileindex')]);
2235
+ $h.cleanMemory($thumb);
2236
+ if (out === false) {
2237
+ return;
2238
+ }
2239
+ $thumb.fadeOut('slow', function () {
2240
+ $h.cleanZoomCache($preview.find('#zoom-' + id));
2241
+ $thumb.remove();
2242
+ if (!self.getFrames().length) {
2243
+ self.reset();
2244
+ }
2245
+ });
2246
+ });
2247
+ });
2248
+ },
2249
+ _checkAsyncComplete: function () {
2250
+ var self = this, previewId, i;
2251
+ for (i = 0; i < self.filestack.length; i++) {
2252
+ if (self.filestack[i]) {
2253
+ previewId = self.previewInitId + "-" + i;
2254
+ if ($.inArray(previewId, self.uploadLog) === -1) {
2255
+ return false;
2256
+ }
2257
+ }
2258
+ }
2259
+ return (self.uploadAsyncCount === self.uploadLog.length);
2260
+ },
2261
+ _uploadExtra: function (previewId, index) {
2262
+ var self = this, data = self._getExtraData(previewId, index);
2263
+ if (data.length === 0) {
2264
+ return;
2265
+ }
2266
+ $.each(data, function (key, value) {
2267
+ self.formdata.append(key, value);
2268
+ });
2269
+ },
2270
+ _uploadSingle: function (i, isBatch) {
2271
+ var self = this, total = self.getFileStack().length, formdata = new FormData(), outData,
2272
+ previewId = self.previewInitId + "-" + i, $thumb, chkComplete, $btnUpload, $btnDelete,
2273
+ hasPostData = self.filestack.length > 0 || !$.isEmptyObject(self.uploadExtraData), uploadFailed,
2274
+ $prog = $('#' + previewId).find('.file-thumb-progress'), fnBefore, fnSuccess, fnComplete, fnError,
2275
+ updateUploadLog, params = {id: previewId, index: i};
2276
+ self.formdata = formdata;
2277
+ if (self.showPreview) {
2278
+ $thumb = $('#' + previewId + ':not(.file-preview-initial)');
2279
+ $btnUpload = $thumb.find('.kv-file-upload');
2280
+ $btnDelete = $thumb.find('.kv-file-remove');
2281
+ $prog.show();
2282
+ }
2283
+ if (total === 0 || !hasPostData || ($btnUpload && $btnUpload.hasClass('disabled')) || self._abort(params)) {
2284
+ return;
2285
+ }
2286
+ updateUploadLog = function (i, previewId) {
2287
+ if (!uploadFailed) {
2288
+ self.updateStack(i, undefined);
2289
+ }
2290
+ self.uploadLog.push(previewId);
2291
+ if (self._checkAsyncComplete()) {
2292
+ self.fileBatchCompleted = true;
2293
+ }
2294
+ };
2295
+ chkComplete = function () {
2296
+ var u = self.uploadCache, $initThumbs, i, j, len = 0, data = self.cacheInitialPreview;
2297
+ if (!self.fileBatchCompleted) {
2298
+ return;
2299
+ }
2300
+ if (data && data.content) {
2301
+ len = data.content.length;
2302
+ }
2303
+ setTimeout(function () {
2304
+ var triggerReset = self.getFileStack(true).length === 0;
2305
+ if (self.showPreview) {
2306
+ self.previewCache.set(u.content, u.config, u.tags, u.append);
2307
+ if (len) {
2308
+ for (i = 0; i < u.content.length; i++) {
2309
+ j = i + len;
2310
+ data.content[j] = u.content[i];
2311
+ //noinspection JSUnresolvedVariable
2312
+ if (data.config.length) {
2313
+ data.config[j] = u.config[i];
2314
+ }
2315
+ if (data.tags.length) {
2316
+ data.tags[j] = u.tags[i];
2317
+ }
2318
+ }
2319
+ self.initialPreview = $h.cleanArray(data.content);
2320
+ self.initialPreviewConfig = $h.cleanArray(data.config);
2321
+ self.initialPreviewThumbTags = $h.cleanArray(data.tags);
2322
+ } else {
2323
+ self.initialPreview = u.content;
2324
+ self.initialPreviewConfig = u.config;
2325
+ self.initialPreviewThumbTags = u.tags;
2326
+ }
2327
+ self.cacheInitialPreview = {};
2328
+ if (self.hasInitData) {
2329
+ self._initPreview();
2330
+ self._initPreviewActions();
2331
+ }
2332
+ }
2333
+ self.unlock(triggerReset);
2334
+ if (triggerReset) {
2335
+ self._clearFileInput();
2336
+ }
2337
+ $initThumbs = self.$preview.find('.file-preview-initial');
2338
+ if (self.uploadAsync && $initThumbs.length) {
2339
+ $h.addCss($initThumbs, $h.SORT_CSS);
2340
+ self._initSortable();
2341
+ }
2342
+ self._raise('filebatchuploadcomplete', [self.filestack, self._getExtraData()]);
2343
+ self.uploadCount = 0;
2344
+ self.uploadStatus = {};
2345
+ self.uploadLog = [];
2346
+ self._setProgress(101);
2347
+ self.ajaxAborted = false;
2348
+ }, 100);
2349
+ };
2350
+ fnBefore = function (jqXHR) {
2351
+ outData = self._getOutData(jqXHR);
2352
+ self.fileBatchCompleted = false;
2353
+ if (!isBatch) {
2354
+ self.ajaxAborted = false;
2355
+ }
2356
+ if (self.showPreview) {
2357
+ if (!$thumb.hasClass('file-preview-success')) {
2358
+ self._setThumbStatus($thumb, 'Loading');
2359
+ $h.addCss($thumb, 'file-uploading');
2360
+ }
2361
+ $btnUpload.attr('disabled', true);
2362
+ $btnDelete.attr('disabled', true);
2363
+ }
2364
+ if (!isBatch) {
2365
+ self.lock();
2366
+ }
2367
+ self._raise('filepreupload', [outData, previewId, i]);
2368
+ $.extend(true, params, outData);
2369
+ if (self._abort(params)) {
2370
+ jqXHR.abort();
2371
+ if (!isBatch) {
2372
+ self._setThumbStatus($thumb, 'New');
2373
+ $thumb.removeClass('file-uploading');
2374
+ $btnUpload.removeAttr('disabled');
2375
+ $btnDelete.removeAttr('disabled');
2376
+ self.unlock();
2377
+ }
2378
+ self._setProgressCancelled();
2379
+ }
2380
+ };
2381
+ fnSuccess = function (data, textStatus, jqXHR) {
2382
+ var pid = self.showPreview && $thumb.attr('id') ? $thumb.attr('id') : previewId;
2383
+ outData = self._getOutData(jqXHR, data);
2384
+ $.extend(true, params, outData);
2385
+ setTimeout(function () {
2386
+ if ($h.isEmpty(data) || $h.isEmpty(data.error)) {
2387
+ if (self.showPreview) {
2388
+ self._setThumbStatus($thumb, 'Success');
2389
+ $btnUpload.hide();
2390
+ self._initUploadSuccess(data, $thumb, isBatch);
2391
+ self._setProgress(101, $prog);
2392
+ }
2393
+ self._raise('fileuploaded', [outData, pid, i]);
2394
+ if (!isBatch) {
2395
+ self.updateStack(i, undefined);
2396
+ } else {
2397
+ updateUploadLog(i, pid);
2398
+ }
2399
+ } else {
2400
+ uploadFailed = true;
2401
+ self._showUploadError(data.error, params);
2402
+ self._setPreviewError($thumb, i, self.filestack[i], self.retryErrorUploads);
2403
+ if (!self.retryErrorUploads) {
2404
+ $btnUpload.hide();
2405
+ }
2406
+ if (isBatch) {
2407
+ updateUploadLog(i, pid);
2408
+ }
2409
+ self._setProgress(101, $('#' + pid).find('.file-thumb-progress'), self.msgUploadError);
2410
+ }
2411
+ }, 100);
2412
+ };
2413
+ fnComplete = function () {
2414
+ setTimeout(function () {
2415
+ if (self.showPreview) {
2416
+ $btnUpload.removeAttr('disabled');
2417
+ $btnDelete.removeAttr('disabled');
2418
+ $thumb.removeClass('file-uploading');
2419
+ }
2420
+ if (!isBatch) {
2421
+ self.unlock(false);
2422
+ self._clearFileInput();
2423
+ } else {
2424
+ chkComplete();
2425
+ }
2426
+ self._initSuccessThumbs();
2427
+ }, 100);
2428
+ };
2429
+ fnError = function (jqXHR, textStatus, errorThrown) {
2430
+ var op = self.ajaxOperations.uploadThumb,
2431
+ errMsg = self._parseError(op, jqXHR, errorThrown, (isBatch && self.filestack[i].name ? self.filestack[i].name : null));
2432
+ uploadFailed = true;
2433
+ setTimeout(function () {
2434
+ if (isBatch) {
2435
+ updateUploadLog(i, previewId);
2436
+ }
2437
+ self.uploadStatus[previewId] = 100;
2438
+ self._setPreviewError($thumb, i, self.filestack[i], self.retryErrorUploads);
2439
+ if (!self.retryErrorUploads) {
2440
+ $btnUpload.hide();
2441
+ }
2442
+ $.extend(true, params, self._getOutData(jqXHR));
2443
+ self._setProgress(101, $prog, self.msgAjaxProgressError.replace('{operation}', op));
2444
+ self._setProgress(101, $('#' + previewId).find('.file-thumb-progress'), self.msgUploadError);
2445
+ self._showUploadError(errMsg, params);
2446
+ }, 100);
2447
+ };
2448
+ formdata.append(self.uploadFileAttr, self.filestack[i], self.filenames[i]);
2449
+ formdata.append('file_id', i);
2450
+ self._ajaxSubmit(fnBefore, fnSuccess, fnComplete, fnError, previewId, i);
2451
+ },
2452
+ _uploadBatch: function () {
2453
+ var self = this, files = self.filestack, total = files.length, params = {}, fnBefore, fnSuccess, fnError,
2454
+ fnComplete, hasPostData = self.filestack.length > 0 || !$.isEmptyObject(self.uploadExtraData),
2455
+ setAllUploaded;
2456
+ self.formdata = new FormData();
2457
+ if (total === 0 || !hasPostData || self._abort(params)) {
2458
+ return;
2459
+ }
2460
+ setAllUploaded = function () {
2461
+ $.each(files, function (key) {
2462
+ self.updateStack(key, undefined);
2463
+ });
2464
+ self._clearFileInput();
2465
+ };
2466
+ fnBefore = function (jqXHR) {
2467
+ self.lock();
2468
+ var outData = self._getOutData(jqXHR);
2469
+ self.ajaxAborted = false;
2470
+ if (self.showPreview) {
2471
+ self._getThumbs().each(function () {
2472
+ var $thumb = $(this), $btnUpload = $thumb.find('.kv-file-upload'),
2473
+ $btnDelete = $thumb.find('.kv-file-remove');
2474
+ if (!$thumb.hasClass('file-preview-success')) {
2475
+ self._setThumbStatus($thumb, 'Loading');
2476
+ $h.addCss($thumb, 'file-uploading');
2477
+ }
2478
+ $btnUpload.attr('disabled', true);
2479
+ $btnDelete.attr('disabled', true);
2480
+ });
2481
+ }
2482
+ self._raise('filebatchpreupload', [outData]);
2483
+ if (self._abort(outData)) {
2484
+ jqXHR.abort();
2485
+ self._getThumbs().each(function () {
2486
+ var $thumb = $(this), $btnUpload = $thumb.find('.kv-file-upload'),
2487
+ $btnDelete = $thumb.find('.kv-file-remove');
2488
+ if ($thumb.hasClass('file-preview-loading')) {
2489
+ self._setThumbStatus($thumb, 'New');
2490
+ $thumb.removeClass('file-uploading');
2491
+ }
2492
+ $btnUpload.removeAttr('disabled');
2493
+ $btnDelete.removeAttr('disabled');
2494
+ });
2495
+ self._setProgressCancelled();
2496
+ }
2497
+ };
2498
+ fnSuccess = function (data, textStatus, jqXHR) {
2499
+ /** @namespace data.errorkeys */
2500
+ var outData = self._getOutData(jqXHR, data), key = 0,
2501
+ $thumbs = self._getThumbs(':not(.file-preview-success)'),
2502
+ keys = $h.isEmpty(data) || $h.isEmpty(data.errorkeys) ? [] : data.errorkeys;
2503
+
2504
+ if ($h.isEmpty(data) || $h.isEmpty(data.error)) {
2505
+ self._raise('filebatchuploadsuccess', [outData]);
2506
+ setAllUploaded();
2507
+ if (self.showPreview) {
2508
+ $thumbs.each(function () {
2509
+ var $thumb = $(this);
2510
+ self._setThumbStatus($thumb, 'Success');
2511
+ $thumb.removeClass('file-uploading');
2512
+ $thumb.find('.kv-file-upload').hide().removeAttr('disabled');
2513
+ });
2514
+ self._initUploadSuccess(data);
2515
+ } else {
2516
+ self.reset();
2517
+ }
2518
+ self._setProgress(101);
2519
+ } else {
2520
+ if (self.showPreview) {
2521
+ $thumbs.each(function () {
2522
+ var $thumb = $(this), i = $thumb.attr('data-fileindex');
2523
+ $thumb.removeClass('file-uploading');
2524
+ $thumb.find('.kv-file-upload').removeAttr('disabled');
2525
+ $thumb.find('.kv-file-remove').removeAttr('disabled');
2526
+ if (keys.length === 0 || $.inArray(key, keys) !== -1) {
2527
+ self._setPreviewError($thumb, i, self.filestack[i], self.retryErrorUploads);
2528
+ if (!self.retryErrorUploads) {
2529
+ $thumb.find('.kv-file-upload').hide();
2530
+ self.updateStack(i, undefined);
2531
+ }
2532
+ } else {
2533
+ $thumb.find('.kv-file-upload').hide();
2534
+ self._setThumbStatus($thumb, 'Success');
2535
+ self.updateStack(i, undefined);
2536
+ }
2537
+ if (!$thumb.hasClass('file-preview-error') || self.retryErrorUploads) {
2538
+ key++;
2539
+ }
2540
+ });
2541
+ self._initUploadSuccess(data);
2542
+ }
2543
+ self._showUploadError(data.error, outData, 'filebatchuploaderror');
2544
+ self._setProgress(101, self.$progress, self.msgUploadError);
2545
+ }
2546
+ };
2547
+ fnComplete = function () {
2548
+ self.unlock();
2549
+ self._initSuccessThumbs();
2550
+ self._clearFileInput();
2551
+ self._raise('filebatchuploadcomplete', [self.filestack, self._getExtraData()]);
2552
+ };
2553
+ fnError = function (jqXHR, textStatus, errorThrown) {
2554
+ var outData = self._getOutData(jqXHR), op = self.ajaxOperations.uploadBatch,
2555
+ errMsg = self._parseError(op, jqXHR, errorThrown);
2556
+ self._showUploadError(errMsg, outData, 'filebatchuploaderror');
2557
+ self.uploadFileCount = total - 1;
2558
+ if (!self.showPreview) {
2559
+ return;
2560
+ }
2561
+ self._getThumbs().each(function () {
2562
+ var $thumb = $(this), key = $thumb.attr('data-fileindex');
2563
+ $thumb.removeClass('file-uploading');
2564
+ if (self.filestack[key] !== undefined) {
2565
+ self._setPreviewError($thumb);
2566
+ }
2567
+ });
2568
+ self._getThumbs().removeClass('file-uploading');
2569
+ self._getThumbs(' .kv-file-upload').removeAttr('disabled');
2570
+ self._getThumbs(' .kv-file-delete').removeAttr('disabled');
2571
+ self._setProgress(101, self.$progress, self.msgAjaxProgressError.replace('{operation}', op));
2572
+ };
2573
+ $.each(files, function (key, data) {
2574
+ if (!$h.isEmpty(files[key])) {
2575
+ self.formdata.append(self.uploadFileAttr, data, self.filenames[key]);
2576
+ }
2577
+ });
2578
+ self._ajaxSubmit(fnBefore, fnSuccess, fnComplete, fnError);
2579
+ },
2580
+ _uploadExtraOnly: function () {
2581
+ var self = this, params = {}, fnBefore, fnSuccess, fnComplete, fnError;
2582
+ self.formdata = new FormData();
2583
+ if (self._abort(params)) {
2584
+ return;
2585
+ }
2586
+ fnBefore = function (jqXHR) {
2587
+ self.lock();
2588
+ var outData = self._getOutData(jqXHR);
2589
+ self._raise('filebatchpreupload', [outData]);
2590
+ self._setProgress(50);
2591
+ params.data = outData;
2592
+ params.xhr = jqXHR;
2593
+ if (self._abort(params)) {
2594
+ jqXHR.abort();
2595
+ self._setProgressCancelled();
2596
+ }
2597
+ };
2598
+ fnSuccess = function (data, textStatus, jqXHR) {
2599
+ var outData = self._getOutData(jqXHR, data);
2600
+ if ($h.isEmpty(data) || $h.isEmpty(data.error)) {
2601
+ self._raise('filebatchuploadsuccess', [outData]);
2602
+ self._clearFileInput();
2603
+ self._initUploadSuccess(data);
2604
+ self._setProgress(101);
2605
+ } else {
2606
+ self._showUploadError(data.error, outData, 'filebatchuploaderror');
2607
+ }
2608
+ };
2609
+ fnComplete = function () {
2610
+ self.unlock();
2611
+ self._clearFileInput();
2612
+ self._raise('filebatchuploadcomplete', [self.filestack, self._getExtraData()]);
2613
+ };
2614
+ fnError = function (jqXHR, textStatus, errorThrown) {
2615
+ var outData = self._getOutData(jqXHR), op = self.ajaxOperations.uploadExtra,
2616
+ errMsg = self._parseError(op, jqXHR, errorThrown);
2617
+ params.data = outData;
2618
+ self._showUploadError(errMsg, outData, 'filebatchuploaderror');
2619
+ self._setProgress(101, self.$progress, self.msgAjaxProgressError.replace('{operation}', op));
2620
+ };
2621
+ self._ajaxSubmit(fnBefore, fnSuccess, fnComplete, fnError);
2622
+ },
2623
+ _deleteFileIndex: function ($frame) {
2624
+ var self = this, ind = $frame.attr('data-fileindex'), rev = self.reversePreviewOrder;
2625
+ if (ind.substring(0, 5) === 'init_') {
2626
+ ind = parseInt(ind.replace('init_', ''));
2627
+ self.initialPreview = $h.spliceArray(self.initialPreview, ind, rev);
2628
+ self.initialPreviewConfig = $h.spliceArray(self.initialPreviewConfig, ind, rev);
2629
+ self.initialPreviewThumbTags = $h.spliceArray(self.initialPreviewThumbTags, ind, rev);
2630
+ self.getFrames().each(function () {
2631
+ var $nFrame = $(this), nInd = $nFrame.attr('data-fileindex');
2632
+ if (nInd.substring(0, 5) === 'init_') {
2633
+ nInd = parseInt(nInd.replace('init_', ''));
2634
+ if (nInd > ind) {
2635
+ nInd--;
2636
+ $nFrame.attr('data-fileindex', 'init_' + nInd);
2637
+ }
2638
+ }
2639
+ });
2640
+ if (self.uploadAsync) {
2641
+ self.cacheInitialPreview = self.getPreview();
2642
+ }
2643
+ }
2644
+ },
2645
+ _initFileActions: function () {
2646
+ var self = this, $preview = self.$preview;
2647
+ if (!self.showPreview) {
2648
+ return;
2649
+ }
2650
+ self._initZoomButton();
2651
+ self.getFrames(' .kv-file-remove').each(function () {
2652
+ var $el = $(this), $frame = $el.closest($h.FRAMES), hasError, id = $frame.attr('id'),
2653
+ ind = $frame.attr('data-fileindex'), n, cap, status;
2654
+ self._handler($el, 'click', function () {
2655
+ status = self._raise('filepreremove', [id, ind]);
2656
+ if (status === false || !self._validateMinCount()) {
2657
+ return false;
2658
+ }
2659
+ hasError = $frame.hasClass('file-preview-error');
2660
+ $h.cleanMemory($frame);
2661
+ $frame.fadeOut('slow', function () {
2662
+ $h.cleanZoomCache($preview.find('#zoom-' + id));
2663
+ self.updateStack(ind, undefined);
2664
+ self._clearObjects($frame);
2665
+ $frame.remove();
2666
+ if (id && hasError) {
2667
+ self.$errorContainer.find('li[data-file-id="' + id + '"]').fadeOut('fast', function () {
2668
+ $(this).remove();
2669
+ if (!self._errorsExist()) {
2670
+ self._resetErrors();
2671
+ }
2672
+ });
2673
+ }
2674
+ self._clearFileInput();
2675
+ var filestack = self.getFileStack(true), chk = self.previewCache.count(),
2676
+ len = filestack.length, hasThumb = self.showPreview && self.getFrames().length;
2677
+ if (len === 0 && chk === 0 && !hasThumb) {
2678
+ self.reset();
2679
+ } else {
2680
+ n = chk + len;
2681
+ cap = n > 1 ? self._getMsgSelected(n) : (filestack[0] ? self._getFileNames()[0] : '');
2682
+ self._setCaption(cap);
2683
+ }
2684
+ self._raise('fileremoved', [id, ind]);
2685
+ });
2686
+ });
2687
+ });
2688
+ self.getFrames(' .kv-file-upload').each(function () {
2689
+ var $el = $(this);
2690
+ self._handler($el, 'click', function () {
2691
+ var $frame = $el.closest($h.FRAMES), ind = $frame.attr('data-fileindex');
2692
+ self.$progress.hide();
2693
+ if ($frame.hasClass('file-preview-error') && !self.retryErrorUploads) {
2694
+ return;
2695
+ }
2696
+ self._uploadSingle(ind, false);
2697
+ });
2698
+ });
2699
+ },
2700
+ _initPreviewActions: function () {
2701
+ var self = this, $preview = self.$preview, deleteExtraData = self.deleteExtraData || {},
2702
+ btnRemove = $h.FRAMES + ' .kv-file-remove', settings = self.fileActionSettings,
2703
+ origClass = settings.removeClass, errClass = settings.removeErrorClass,
2704
+ resetProgress = function () {
2705
+ var hasFiles = self.isAjaxUpload ? self.previewCache.count() : self._inputFileCount();
2706
+ if (!$preview.find($h.FRAMES).length && !hasFiles) {
2707
+ self._setCaption('');
2708
+ self.reset();
2709
+ self.initialCaption = '';
2710
+ }
2711
+ };
2712
+ self._initZoomButton();
2713
+ $preview.find(btnRemove).each(function () {
2714
+ var $el = $(this), vUrl = $el.data('url') || self.deleteUrl, vKey = $el.data('key'),
2715
+ fnBefore, fnSuccess, fnError;
2716
+ if ($h.isEmpty(vUrl) || vKey === undefined) {
2717
+ return;
2718
+ }
2719
+ var $frame = $el.closest($h.FRAMES), cache = self.previewCache.data,
2720
+ settings, params, index = $frame.attr('data-fileindex'), config, extraData;
2721
+ index = parseInt(index.replace('init_', ''));
2722
+ config = $h.isEmpty(cache.config) && $h.isEmpty(cache.config[index]) ? null : cache.config[index];
2723
+ extraData = $h.isEmpty(config) || $h.isEmpty(config.extra) ? deleteExtraData : config.extra;
2724
+ if (typeof extraData === "function") {
2725
+ extraData = extraData();
2726
+ }
2727
+ params = {id: $el.attr('id'), key: vKey, extra: extraData};
2728
+ fnBefore = function (jqXHR) {
2729
+ self.ajaxAborted = false;
2730
+ self._raise('filepredelete', [vKey, jqXHR, extraData]);
2731
+ if (self._abort()) {
2732
+ jqXHR.abort();
2733
+ } else {
2734
+ $el.removeClass(errClass);
2735
+ $h.addCss($frame, 'file-uploading');
2736
+ $h.addCss($el, 'disabled ' + origClass);
2737
+ }
2738
+ };
2739
+ fnSuccess = function (data, textStatus, jqXHR) {
2740
+ var n, cap;
2741
+ if (!$h.isEmpty(data) && !$h.isEmpty(data.error)) {
2742
+ params.jqXHR = jqXHR;
2743
+ params.response = data;
2744
+ self._showError(data.error, params, 'filedeleteerror');
2745
+ $frame.removeClass('file-uploading');
2746
+ $el.removeClass('disabled ' + origClass).addClass(errClass);
2747
+ resetProgress();
2748
+ return;
2749
+ }
2750
+ $frame.removeClass('file-uploading').addClass('file-deleted');
2751
+ $frame.fadeOut('slow', function () {
2752
+ index = parseInt(($frame.attr('data-fileindex')).replace('init_', ''));
2753
+ self.previewCache.unset(index);
2754
+ self._deleteFileIndex($frame);
2755
+ n = self.previewCache.count();
2756
+ cap = n > 0 ? self._getMsgSelected(n) : '';
2757
+ self._setCaption(cap);
2758
+ self._raise('filedeleted', [vKey, jqXHR, extraData]);
2759
+ $h.cleanZoomCache($preview.find('#zoom-' + $frame.attr('id')));
2760
+ self._clearObjects($frame);
2761
+ $frame.remove();
2762
+ resetProgress();
2763
+ });
2764
+ };
2765
+ fnError = function (jqXHR, textStatus, errorThrown) {
2766
+ var op = self.ajaxOperations.deleteThumb, errMsg = self._parseError(op, jqXHR, errorThrown);
2767
+ params.jqXHR = jqXHR;
2768
+ params.response = {};
2769
+ self._showError(errMsg, params, 'filedeleteerror');
2770
+ $frame.removeClass('file-uploading');
2771
+ $el.removeClass('disabled ' + origClass).addClass(errClass);
2772
+ resetProgress();
2773
+ };
2774
+ self._initAjaxSettings();
2775
+ self._mergeAjaxCallback('beforeSend', fnBefore, 'delete');
2776
+ self._mergeAjaxCallback('success', fnSuccess, 'delete');
2777
+ self._mergeAjaxCallback('error', fnError, 'delete');
2778
+ settings = $.extend(true, {}, {
2779
+ url: vUrl,
2780
+ type: 'POST',
2781
+ dataType: 'json',
2782
+ data: $.extend(true, {}, {key: vKey}, extraData)
2783
+ }, self._ajaxDeleteSettings);
2784
+ self._handler($el, 'click', function () {
2785
+ if (!self._validateMinCount()) {
2786
+ return false;
2787
+ }
2788
+ self.ajaxAborted = false;
2789
+ self._raise('filebeforedelete', [vKey, extraData]);
2790
+ //noinspection JSUnresolvedVariable,JSHint
2791
+ if (self.ajaxAborted instanceof Promise) {
2792
+ self.ajaxAborted.then(function (result) {
2793
+ if (!result) {
2794
+ $.ajax(settings);
2795
+ }
2796
+ });
2797
+ } else {
2798
+ if (!self.ajaxAborted) {
2799
+ $.ajax(settings);
2800
+ }
2801
+ }
2802
+ });
2803
+ });
2804
+ },
2805
+ _hideFileIcon: function () {
2806
+ var self = this;
2807
+ if (self.overwriteInitial) {
2808
+ self.$captionContainer.removeClass('icon-visible');
2809
+ }
2810
+ },
2811
+ _showFileIcon: function () {
2812
+ var self = this;
2813
+ $h.addCss(self.$captionContainer, 'icon-visible');
2814
+ },
2815
+ _getSize: function (bytes) {
2816
+ var self = this, size = parseFloat(bytes), i, func = self.fileSizeGetter, sizes, out;
2817
+ if (!$.isNumeric(bytes) || !$.isNumeric(size)) {
2818
+ return '';
2819
+ }
2820
+ if (typeof func === 'function') {
2821
+ out = func(size);
2822
+ } else {
2823
+ if (size === 0) {
2824
+ out = '0.00 B';
2825
+ } else {
2826
+ i = Math.floor(Math.log(size) / Math.log(1024));
2827
+ sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
2828
+ out = (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + sizes[i];
2829
+ }
2830
+ }
2831
+ return self._getLayoutTemplate('size').replace('{sizeText}', out);
2832
+ },
2833
+ _generatePreviewTemplate: function (cat, data, fname, ftype, previewId, isError, size, frameClass, foot, ind, templ) {
2834
+ var self = this, caption = self.slug(fname), prevContent, zoomContent = '', styleAttribs = '',
2835
+ screenW = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
2836
+ config = screenW < 400 ? (self.previewSettingsSmall[cat] || self.defaults.previewSettingsSmall[cat]) :
2837
+ (self.previewSettings[cat] || self.defaults.previewSettings[cat]),
2838
+ footer = foot || self._renderFileFooter(caption, size, 'auto', isError),
2839
+ hasIconSetting = self._getPreviewIcon(fname), typeCss = 'type-default',
2840
+ forcePrevIcon = hasIconSetting && self.preferIconicPreview,
2841
+ forceZoomIcon = hasIconSetting && self.preferIconicZoomPreview, getContent;
2842
+ if (config) {
2843
+ $.each(config, function (key, val) {
2844
+ styleAttribs += key + ':' + val + ';';
2845
+ });
2846
+ }
2847
+ getContent = function (c, d, zoom, frameCss) {
2848
+ var id = zoom ? 'zoom-' + previewId : previewId, tmplt = self._getPreviewTemplate(c),
2849
+ css = (frameClass || '') + ' ' + frameCss;
2850
+ if (self.frameClass) {
2851
+ css = self.frameClass + ' ' + css;
2852
+ }
2853
+ if (zoom) {
2854
+ css = css.replace(' ' + $h.SORT_CSS, '');
2855
+ }
2856
+ tmplt = self._parseFilePreviewIcon(tmplt, fname);
2857
+ if (c === 'text') {
2858
+ d = $h.htmlEncode(d);
2859
+ }
2860
+ if (cat === 'object' && !ftype) {
2861
+ $.each(self.defaults.fileTypeSettings, function (key, func) {
2862
+ if (key === 'object' || key === 'other') {
2863
+ return;
2864
+ }
2865
+ if (func(fname, ftype)) {
2866
+ typeCss = 'type-' + key;
2867
+ }
2868
+ });
2869
+ }
2870
+ return tmplt.setTokens({
2871
+ 'previewId': id,
2872
+ 'caption': caption,
2873
+ 'frameClass': css,
2874
+ 'type': ftype,
2875
+ 'fileindex': ind,
2876
+ 'typeCss': typeCss,
2877
+ 'footer': footer,
2878
+ 'data': d,
2879
+ 'template': templ || cat,
2880
+ 'style': styleAttribs ? 'style="' + styleAttribs + '"' : ''
2881
+ });
2882
+ };
2883
+ ind = ind || previewId.slice(previewId.lastIndexOf('-') + 1);
2884
+ if (self.fileActionSettings.showZoom) {
2885
+ zoomContent = getContent((forceZoomIcon ? 'other' : cat), data, true, 'kv-zoom-thumb');
2886
+ }
2887
+ zoomContent = '\n' + self._getLayoutTemplate('zoomCache').replace('{zoomContent}', zoomContent);
2888
+ prevContent = getContent((forcePrevIcon ? 'other' : cat), data, false, 'kv-preview-thumb');
2889
+ return prevContent + zoomContent;
2890
+ },
2891
+ _addToPreview: function ($preview, content) {
2892
+ var self = this;
2893
+ return self.reversePreviewOrder ? $preview.prepend(content) : $preview.append(content);
2894
+ },
2895
+ _previewDefault: function (file, previewId, isDisabled) {
2896
+ var self = this, $preview = self.$preview;
2897
+ if (!self.showPreview) {
2898
+ return;
2899
+ }
2900
+ var fname = file ? file.name : '', ftype = file ? file.type : '', content, size = file.size || 0,
2901
+ caption = self.slug(fname), isError = isDisabled === true && !self.isAjaxUpload,
2902
+ data = $h.objUrl.createObjectURL(file);
2903
+ self._clearDefaultPreview();
2904
+ content = self._generatePreviewTemplate('other', data, fname, ftype, previewId, isError, size);
2905
+ self._addToPreview($preview, content);
2906
+ self._setThumbAttr(previewId, caption, size);
2907
+ if (isDisabled === true && self.isAjaxUpload) {
2908
+ self._setThumbStatus($('#' + previewId), 'Error');
2909
+ }
2910
+ },
2911
+ _previewFile: function (i, file, theFile, previewId, data, fileInfo) {
2912
+ if (!this.showPreview) {
2913
+ return;
2914
+ }
2915
+ var self = this, fname = file ? file.name : '', ftype = fileInfo.type, caption = fileInfo.name,
2916
+ cat = self._parseFileType(ftype, fname), types = self.allowedPreviewTypes, content,
2917
+ mimes = self.allowedPreviewMimeTypes, $preview = self.$preview, fsize = file.size || 0,
2918
+ chkTypes = types && types.indexOf(cat) >= 0, chkMimes = mimes && mimes.indexOf(ftype) !== -1,
2919
+ iData = (cat === 'text' || cat === 'html' || cat === 'image') ? theFile.target.result : data;
2920
+ /** @namespace window.DOMPurify */
2921
+ if (cat === 'html' && self.purifyHtml && window.DOMPurify) {
2922
+ iData = window.DOMPurify.sanitize(iData);
2923
+ }
2924
+ if (chkTypes || chkMimes) {
2925
+ content = self._generatePreviewTemplate(cat, iData, fname, ftype, previewId, false, fsize);
2926
+ self._clearDefaultPreview();
2927
+ self._addToPreview($preview, content);
2928
+ var $img = $preview.find('#' + previewId + ' img');
2929
+ if ($img.length && self.autoOrientImage) {
2930
+ $h.validateOrientation(file, function (value) {
2931
+ if (!value) {
2932
+ self._validateImage(previewId, caption, ftype, fsize, iData);
2933
+ return;
2934
+ }
2935
+ var $zoomImg = $preview.find('#zoom-' + previewId + ' img'), css = 'rotate-' + value;
2936
+ if (value > 4) {
2937
+ css += ($img.width() > $img.height() ? ' is-portrait-gt4' : ' is-landscape-gt4');
2938
+ }
2939
+ $h.addCss($img, css);
2940
+ $h.addCss($zoomImg, css);
2941
+ self._raise('fileimageoriented', {'$img': $img, 'file': file});
2942
+ self._validateImage(previewId, caption, ftype, fsize, iData);
2943
+ $h.adjustOrientedImage($img);
2944
+ });
2945
+ } else {
2946
+ self._validateImage(previewId, caption, ftype, fsize, iData);
2947
+ }
2948
+ } else {
2949
+ self._previewDefault(file, previewId);
2950
+ }
2951
+ self._setThumbAttr(previewId, caption, fsize);
2952
+ self._initSortable();
2953
+ },
2954
+ _setThumbAttr: function (id, caption, size) {
2955
+ var self = this, $frame = $('#' + id);
2956
+ if ($frame.length) {
2957
+ size = size && size > 0 ? self._getSize(size) : '';
2958
+ $frame.data({'caption': caption, 'size': size});
2959
+ }
2960
+ },
2961
+ _setInitThumbAttr: function () {
2962
+ var self = this, data = self.previewCache.data, len = self.previewCache.count(), config,
2963
+ caption, size, previewId;
2964
+ if (len === 0) {
2965
+ return;
2966
+ }
2967
+ for (var i = 0; i < len; i++) {
2968
+ config = data.config[i];
2969
+ previewId = self.previewInitId + '-' + 'init_' + i;
2970
+ caption = $h.ifSet('caption', config, $h.ifSet('filename', config));
2971
+ size = $h.ifSet('size', config);
2972
+ self._setThumbAttr(previewId, caption, size);
2973
+ }
2974
+ },
2975
+ _slugDefault: function (text) {
2976
+ return $h.isEmpty(text) ? '' : String(text).replace(/[\[\]\/\{}:;#%=\(\)\*\+\?\\\^\$\|<>&"']/g, '_');
2977
+ },
2978
+ _updateFileDetails: function (numFiles) {
2979
+ var self = this, $el = self.$element, fileStack = self.getFileStack(),
2980
+ name = ($h.isIE(9) && $h.findFileName($el.val())) ||
2981
+ ($el[0].files[0] && $el[0].files[0].name) || (fileStack.length && fileStack[0].name) || '',
2982
+ label = self.slug(name), n = self.isAjaxUpload ? fileStack.length : numFiles,
2983
+ nFiles = self.previewCache.count() + n, log = n === 1 ? label : self._getMsgSelected(nFiles);
2984
+ if (self.isError) {
2985
+ self.$previewContainer.removeClass('file-thumb-loading');
2986
+ self.$previewStatus.html('');
2987
+ self.$captionContainer.removeClass('icon-visible');
2988
+ } else {
2989
+ self._showFileIcon();
2990
+ }
2991
+ self._setCaption(log, self.isError);
2992
+ self.$container.removeClass('file-input-new file-input-ajax-new');
2993
+ if (arguments.length === 1) {
2994
+ self._raise('fileselect', [numFiles, label]);
2995
+ }
2996
+ if (self.previewCache.count()) {
2997
+ self._initPreviewActions();
2998
+ }
2999
+ },
3000
+ _setThumbStatus: function ($thumb, status) {
3001
+ var self = this;
3002
+ if (!self.showPreview) {
3003
+ return;
3004
+ }
3005
+ var icon = 'indicator' + status, msg = icon + 'Title',
3006
+ css = 'file-preview-' + status.toLowerCase(),
3007
+ $indicator = $thumb.find('.file-upload-indicator'),
3008
+ config = self.fileActionSettings;
3009
+ $thumb.removeClass('file-preview-success file-preview-error file-preview-loading');
3010
+ if (status === 'Success') {
3011
+ $thumb.find('.file-drag-handle').remove();
3012
+ }
3013
+ $indicator.html(config[icon]);
3014
+ $indicator.attr('title', config[msg]);
3015
+ $thumb.addClass(css);
3016
+ if (status === 'Error' && !self.retryErrorUploads) {
3017
+ $thumb.find('.kv-file-upload').attr('disabled', true);
3018
+ }
3019
+ },
3020
+ _setProgressCancelled: function () {
3021
+ var self = this;
3022
+ self._setProgress(101, self.$progress, self.msgCancelled);
3023
+ },
3024
+ _setProgress: function (p, $el, error) {
3025
+ var self = this, pct = Math.min(p, 100), out, pctLimit = self.progressUploadThreshold,
3026
+ t = p <= 100 ? self.progressTemplate : self.progressCompleteTemplate,
3027
+ template = pct < 100 ? self.progressTemplate : (error ? self.progressErrorTemplate : t);
3028
+ $el = $el || self.$progress;
3029
+ if (!$h.isEmpty(template)) {
3030
+ if (pctLimit && pct > pctLimit && p <= 100) {
3031
+ out = template.setTokens({'percent': pctLimit, 'status': self.msgUploadThreshold});
3032
+ } else {
3033
+ out = template.setTokens({'percent': pct, 'status': (p > 100 ? self.msgUploadEnd : pct + '%')});
3034
+ }
3035
+ $el.html(out);
3036
+ if (error) {
3037
+ $el.find('[role="progressbar"]').html(error);
3038
+ }
3039
+ }
3040
+ },
3041
+ _setFileDropZoneTitle: function () {
3042
+ var self = this, $zone = self.$container.find('.file-drop-zone'), title = self.dropZoneTitle, strFiles;
3043
+ if (self.isClickable) {
3044
+ strFiles = $h.isEmpty(self.$element.attr('multiple')) ? self.fileSingle : self.filePlural;
3045
+ title += self.dropZoneClickTitle.replace('{files}', strFiles);
3046
+ }
3047
+ $zone.find('.' + self.dropZoneTitleClass).remove();
3048
+ if (!self.showPreview || $zone.length === 0 || self.getFileStack().length > 0 || !self.dropZoneEnabled ||
3049
+ (!self.isAjaxUpload && self.$element.files)) {
3050
+ return;
3051
+ }
3052
+ if ($zone.find($h.FRAMES).length === 0 && $h.isEmpty(self.defaultPreviewContent)) {
3053
+ $zone.prepend('<div class="' + self.dropZoneTitleClass + '">' + title + '</div>');
3054
+ }
3055
+ self.$container.removeClass('file-input-new');
3056
+ $h.addCss(self.$container, 'file-input-ajax-new');
3057
+ },
3058
+ _setAsyncUploadStatus: function (previewId, pct, total) {
3059
+ var self = this, sum = 0;
3060
+ self._setProgress(pct, $('#' + previewId).find('.file-thumb-progress'));
3061
+ self.uploadStatus[previewId] = pct;
3062
+ $.each(self.uploadStatus, function (key, value) {
3063
+ sum += value;
3064
+ });
3065
+ self._setProgress(Math.floor(sum / total));
3066
+ },
3067
+ _validateMinCount: function () {
3068
+ var self = this, len = self.isAjaxUpload ? self.getFileStack().length : self._inputFileCount();
3069
+ if (self.validateInitialCount && self.minFileCount > 0 && self._getFileCount(len - 1) < self.minFileCount) {
3070
+ self._noFilesError({});
3071
+ return false;
3072
+ }
3073
+ return true;
3074
+ },
3075
+ _getFileCount: function (fileCount) {
3076
+ var self = this, addCount = 0;
3077
+ if (self.validateInitialCount && !self.overwriteInitial) {
3078
+ addCount = self.previewCache.count();
3079
+ fileCount += addCount;
3080
+ }
3081
+ return fileCount;
3082
+ },
3083
+ _getFileId: function (file) {
3084
+ var self = this, custom = self.generateFileId, relativePath;
3085
+ if (typeof custom === 'function') {
3086
+ return custom(file, event);
3087
+ }
3088
+ if (!file) {
3089
+ return null;
3090
+ }
3091
+ /** @namespace file.webkitRelativePath */
3092
+ relativePath = String(file.webkitRelativePath || file.fileName || file.name || null);
3093
+ if (!relativePath) {
3094
+ return null;
3095
+ }
3096
+ return (file.size + '-' + relativePath.replace(/[^0-9a-zA-Z_-]/img, ''));
3097
+ },
3098
+ _getFileName: function (file) {
3099
+ return file && file.name ? this.slug(file.name) : undefined;
3100
+ },
3101
+ _getFileIds: function (skipNull) {
3102
+ var self = this;
3103
+ return self.fileids.filter(function (n) {
3104
+ return (skipNull ? n !== undefined : n !== undefined && n !== null);
3105
+ });
3106
+ },
3107
+ _getFileNames: function (skipNull) {
3108
+ var self = this;
3109
+ return self.filenames.filter(function (n) {
3110
+ return (skipNull ? n !== undefined : n !== undefined && n !== null);
3111
+ });
3112
+ },
3113
+ _setPreviewError: function ($thumb, i, val, repeat) {
3114
+ var self = this;
3115
+ if (i !== undefined) {
3116
+ self.updateStack(i, val);
3117
+ }
3118
+ if (!self.showPreview) {
3119
+ return;
3120
+ }
3121
+ if (self.removeFromPreviewOnError && !repeat) {
3122
+ $thumb.remove();
3123
+ return;
3124
+ } else {
3125
+ self._setThumbStatus($thumb, 'Error');
3126
+ }
3127
+ self._refreshUploadButton($thumb, repeat);
3128
+ },
3129
+ _refreshUploadButton: function ($thumb, repeat) {
3130
+ var self = this, $btn = $thumb.find('.kv-file-upload'), cfg = self.fileActionSettings,
3131
+ icon = cfg.uploadIcon, title = cfg.uploadTitle;
3132
+ if (!$btn.length) {
3133
+ return;
3134
+ }
3135
+ if (repeat) {
3136
+ icon = cfg.uploadRetryIcon;
3137
+ title = cfg.uploadRetryTitle;
3138
+ }
3139
+ $btn.attr('title', title).html(icon);
3140
+ },
3141
+ _checkDimensions: function (i, chk, $img, $thumb, fname, type, params) {
3142
+ var self = this, msg, dim, tag = chk === 'Small' ? 'min' : 'max', limit = self[tag + 'Image' + type],
3143
+ $imgEl, isValid;
3144
+ if ($h.isEmpty(limit) || !$img.length) {
3145
+ return;
3146
+ }
3147
+ $imgEl = $img[0];
3148
+ dim = (type === 'Width') ? $imgEl.naturalWidth || $imgEl.width : $imgEl.naturalHeight || $imgEl.height;
3149
+ isValid = chk === 'Small' ? dim >= limit : dim <= limit;
3150
+ if (isValid) {
3151
+ return;
3152
+ }
3153
+ msg = self['msgImage' + type + chk].setTokens({'name': fname, 'size': limit});
3154
+ self._showUploadError(msg, params);
3155
+ self._setPreviewError($thumb, i, null);
3156
+ },
3157
+ _validateImage: function (previewId, fname, ftype, fsize, iData) {
3158
+ var self = this, $preview = self.$preview, params, w1, w2, $thumb = $preview.find("#" + previewId),
3159
+ i = $thumb.attr('data-fileindex'), $img = $thumb.find('img'), exifObject;
3160
+ fname = fname || 'Untitled';
3161
+ $img.one('load', function () {
3162
+ w1 = $thumb.width();
3163
+ w2 = $preview.width();
3164
+ if (w1 > w2) {
3165
+ $img.css('width', '100%');
3166
+ }
3167
+ params = {ind: i, id: previewId};
3168
+ self._checkDimensions(i, 'Small', $img, $thumb, fname, 'Width', params);
3169
+ self._checkDimensions(i, 'Small', $img, $thumb, fname, 'Height', params);
3170
+ if (!self.resizeImage) {
3171
+ self._checkDimensions(i, 'Large', $img, $thumb, fname, 'Width', params);
3172
+ self._checkDimensions(i, 'Large', $img, $thumb, fname, 'Height', params);
3173
+ }
3174
+ self._raise('fileimageloaded', [previewId]);
3175
+ try {
3176
+ exifObject = window.piexif ? window.piexif.load(iData) : null;
3177
+ } catch (err) {
3178
+ exifObject = null;
3179
+ }
3180
+ self.loadedImages.push({
3181
+ ind: i,
3182
+ img: $img,
3183
+ thumb: $thumb,
3184
+ pid: previewId,
3185
+ typ: ftype,
3186
+ siz: fsize,
3187
+ validated: false,
3188
+ imgData: iData,
3189
+ exifObj: exifObject
3190
+ });
3191
+ $thumb.data('exif', exifObject);
3192
+ self._validateAllImages();
3193
+ }).one('error', function () {
3194
+ self._raise('fileimageloaderror', [previewId]);
3195
+ }).each(function () {
3196
+ if (this.complete) {
3197
+ $(this).trigger('load');
3198
+ } else {
3199
+ if (this.error) {
3200
+ $(this).trigger('error');
3201
+ }
3202
+ }
3203
+ });
3204
+ },
3205
+ _validateAllImages: function () {
3206
+ var self = this, i, counter = {val: 0}, numImgs = self.loadedImages.length, config,
3207
+ fsize, minSize = self.resizeIfSizeMoreThan;
3208
+ if (numImgs !== self.totalImagesCount) {
3209
+ return;
3210
+ }
3211
+ self._raise('fileimagesloaded');
3212
+ if (!self.resizeImage) {
3213
+ return;
3214
+ }
3215
+ for (i = 0; i < self.loadedImages.length; i++) {
3216
+ config = self.loadedImages[i];
3217
+ if (config.validated) {
3218
+ continue;
3219
+ }
3220
+ fsize = config.siz;
3221
+ if (fsize && fsize > minSize * 1000) {
3222
+ self._getResizedImage(config, counter, numImgs);
3223
+ }
3224
+ self.loadedImages[i].validated = true;
3225
+ }
3226
+ },
3227
+ _getResizedImage: function (config, counter, numImgs) {
3228
+ var self = this, img = $(config.img)[0], width = img.naturalWidth, height = img.naturalHeight, blob,
3229
+ ratio = 1, maxWidth = self.maxImageWidth || width, maxHeight = self.maxImageHeight || height,
3230
+ isValidImage = !!(width && height), chkWidth, chkHeight, canvas = self.imageCanvas, dataURI,
3231
+ context = self.imageCanvasContext, type = config.typ, pid = config.pid, ind = config.ind,
3232
+ $thumb = config.thumb, throwError, msg, exifObj = config.exifObj, exifStr;
3233
+ throwError = function (msg, params, ev) {
3234
+ if (self.isAjaxUpload) {
3235
+ self._showUploadError(msg, params, ev);
3236
+ } else {
3237
+ self._showError(msg, params, ev);
3238
+ }
3239
+ self._setPreviewError($thumb, ind);
3240
+ };
3241
+ if (!self.filestack[ind] || !isValidImage || (width <= maxWidth && height <= maxHeight)) {
3242
+ if (isValidImage && self.filestack[ind]) {
3243
+ self._raise('fileimageresized', [pid, ind]);
3244
+ }
3245
+ counter.val++;
3246
+ if (counter.val === numImgs) {
3247
+ self._raise('fileimagesresized');
3248
+ }
3249
+ if (!isValidImage) {
3250
+ throwError(self.msgImageResizeError, {id: pid, 'index': ind}, 'fileimageresizeerror');
3251
+ return;
3252
+ }
3253
+ }
3254
+ type = type || self.resizeDefaultImageType;
3255
+ chkWidth = width > maxWidth;
3256
+ chkHeight = height > maxHeight;
3257
+ if (self.resizePreference === 'width') {
3258
+ ratio = chkWidth ? maxWidth / width : (chkHeight ? maxHeight / height : 1);
3259
+ } else {
3260
+ ratio = chkHeight ? maxHeight / height : (chkWidth ? maxWidth / width : 1);
3261
+ }
3262
+ self._resetCanvas();
3263
+ width *= ratio;
3264
+ height *= ratio;
3265
+ canvas.width = width;
3266
+ canvas.height = height;
3267
+ try {
3268
+ context.drawImage(img, 0, 0, width, height);
3269
+ dataURI = canvas.toDataURL(type, self.resizeQuality);
3270
+ if (exifObj) {
3271
+ exifStr = window.piexif.dump(exifObj);
3272
+ dataURI = window.piexif.insert(exifStr, dataURI);
3273
+ }
3274
+ blob = $h.dataURI2Blob(dataURI);
3275
+ self.filestack[ind] = blob;
3276
+ self._raise('fileimageresized', [pid, ind]);
3277
+ counter.val++;
3278
+ if (counter.val === numImgs) {
3279
+ self._raise('fileimagesresized', [undefined, undefined]);
3280
+ }
3281
+ if (!(blob instanceof Blob)) {
3282
+ throwError(self.msgImageResizeError, {id: pid, 'index': ind}, 'fileimageresizeerror');
3283
+ }
3284
+ }
3285
+ catch (err) {
3286
+ counter.val++;
3287
+ if (counter.val === numImgs) {
3288
+ self._raise('fileimagesresized', [undefined, undefined]);
3289
+ }
3290
+ msg = self.msgImageResizeException.replace('{errors}', err.message);
3291
+ throwError(msg, {id: pid, 'index': ind}, 'fileimageresizeexception');
3292
+ }
3293
+ },
3294
+ _initBrowse: function ($container) {
3295
+ var self = this, $el = self.$element;
3296
+ if (self.showBrowse) {
3297
+ self.$btnFile = $container.find('.btn-file').append($el);
3298
+ } else {
3299
+ $el.appendTo($container).attr('tabindex', -1);
3300
+ $h.addCss($el, 'file-no-browse');
3301
+ }
3302
+ },
3303
+ _initClickable: function () {
3304
+ var self = this, $zone;
3305
+ if (!self.isClickable) {
3306
+ return;
3307
+ }
3308
+ $zone = self.isAjaxUpload ? self.$dropZone : self.$preview.find('.file-default-preview');
3309
+ $h.addCss($zone, 'clickable');
3310
+ $zone.attr('tabindex', -1);
3311
+ self._handler($zone, 'click', function (e) {
3312
+ var $tar = $(e.target), $el = self.$element;
3313
+ if (!$(self.elErrorContainer + ':visible').length &&
3314
+ (!$tar.parents('.file-preview-thumbnails').length || $tar.parents('.file-default-preview').length)) {
3315
+ self.$element.data('zoneClicked', true).trigger('click');
3316
+ $zone.blur();
3317
+ }
3318
+ });
3319
+ },
3320
+ _initCaption: function () {
3321
+ var self = this, cap = self.initialCaption || '';
3322
+ if (self.overwriteInitial || $h.isEmpty(cap)) {
3323
+ self.$caption.val('');
3324
+ return false;
3325
+ }
3326
+ self._setCaption(cap);
3327
+ return true;
3328
+ },
3329
+ _setCaption: function (content, isError) {
3330
+ var self = this, title, out, icon, n, cap, stack = self.getFileStack();
3331
+ if (!self.$caption.length) {
3332
+ return;
3333
+ }
3334
+ self.$captionContainer.removeClass('icon-visible');
3335
+ if (isError) {
3336
+ title = $('<div>' + self.msgValidationError + '</div>').text();
3337
+ n = stack.length;
3338
+ if (n) {
3339
+ cap = n === 1 && stack[0] ? self._getFileNames()[0] : self._getMsgSelected(n);
3340
+ } else {
3341
+ cap = self._getMsgSelected(self.msgNo);
3342
+ }
3343
+ out = $h.isEmpty(content) ? cap : content;
3344
+ icon = '<span class="' + self.msgValidationErrorClass + '">' + self.msgValidationErrorIcon + '</span>';
3345
+ } else {
3346
+ if ($h.isEmpty(content)) {
3347
+ return;
3348
+ }
3349
+ title = $('<div>' + content + '</div>').text();
3350
+ out = title;
3351
+ icon = self._getLayoutTemplate('fileIcon');
3352
+ }
3353
+ self.$captionContainer.addClass('icon-visible');
3354
+ self.$caption.attr('title', title).val(out);
3355
+ self.$captionIcon.html(icon);
3356
+ },
3357
+ _createContainer: function () {
3358
+ var self = this, attribs = {"class": 'file-input file-input-new' + (self.rtl ? ' kv-rtl' : '')},
3359
+ $container = $(document.createElement("div")).attr(attribs).html(self._renderMain());
3360
+ $container.insertBefore(self.$element);
3361
+ self._initBrowse($container);
3362
+ if (self.theme) {
3363
+ $container.addClass('theme-' + self.theme);
3364
+ }
3365
+ return $container;
3366
+ },
3367
+ _refreshContainer: function () {
3368
+ var self = this, $container = self.$container, $el = self.$element;
3369
+ $el.insertAfter($container);
3370
+ $container.html(self._renderMain());
3371
+ self._initBrowse($container);
3372
+ self._validateDisabled();
3373
+ },
3374
+ _validateDisabled: function () {
3375
+ var self = this;
3376
+ self.$caption.attr({readonly: self.isDisabled});
3377
+ },
3378
+ _renderMain: function () {
3379
+ var self = this,
3380
+ dropCss = self.dropZoneEnabled ? ' file-drop-zone' : 'file-drop-disabled',
3381
+ close = !self.showClose ? '' : self._getLayoutTemplate('close'),
3382
+ preview = !self.showPreview ? '' : self._getLayoutTemplate('preview')
3383
+ .setTokens({'class': self.previewClass, 'dropClass': dropCss}),
3384
+ css = self.isDisabled ? self.captionClass + ' file-caption-disabled' : self.captionClass,
3385
+ caption = self.captionTemplate.setTokens({'class': css + ' kv-fileinput-caption'});
3386
+ return self.mainTemplate.setTokens({
3387
+ 'class': self.mainClass + (!self.showBrowse && self.showCaption ? ' no-browse' : ''),
3388
+ 'preview': preview,
3389
+ 'close': close,
3390
+ 'caption': caption,
3391
+ 'upload': self._renderButton('upload'),
3392
+ 'remove': self._renderButton('remove'),
3393
+ 'cancel': self._renderButton('cancel'),
3394
+ 'browse': self._renderButton('browse')
3395
+ });
3396
+
3397
+ },
3398
+ _renderButton: function (type) {
3399
+ var self = this, tmplt = self._getLayoutTemplate('btnDefault'), css = self[type + 'Class'],
3400
+ title = self[type + 'Title'], icon = self[type + 'Icon'], label = self[type + 'Label'],
3401
+ status = self.isDisabled ? ' disabled' : '', btnType = 'button';
3402
+ switch (type) {
3403
+ case 'remove':
3404
+ if (!self.showRemove) {
3405
+ return '';
3406
+ }
3407
+ break;
3408
+ case 'cancel':
3409
+ if (!self.showCancel) {
3410
+ return '';
3411
+ }
3412
+ css += ' kv-hidden';
3413
+ break;
3414
+ case 'upload':
3415
+ if (!self.showUpload) {
3416
+ return '';
3417
+ }
3418
+ if (self.isAjaxUpload && !self.isDisabled) {
3419
+ tmplt = self._getLayoutTemplate('btnLink').replace('{href}', self.uploadUrl);
3420
+ } else {
3421
+ btnType = 'submit';
3422
+ }
3423
+ break;
3424
+ case 'browse':
3425
+ if (!self.showBrowse) {
3426
+ return '';
3427
+ }
3428
+ tmplt = self._getLayoutTemplate('btnBrowse');
3429
+ break;
3430
+ default:
3431
+ return '';
3432
+ }
3433
+
3434
+ css += type === 'browse' ? ' btn-file' : ' fileinput-' + type + ' fileinput-' + type + '-button';
3435
+ if (!$h.isEmpty(label)) {
3436
+ label = ' <span class="' + self.buttonLabelClass + '">' + label + '</span>';
3437
+ }
3438
+ return tmplt.setTokens({
3439
+ 'type': btnType, 'css': css, 'title': title, 'status': status, 'icon': icon, 'label': label
3440
+ });
3441
+ },
3442
+ _renderThumbProgress: function () {
3443
+ var self = this;
3444
+ return '<div class="file-thumb-progress kv-hidden">' +
3445
+ self.progressTemplate.setTokens({'percent': '0', 'status': self.msgUploadBegin}) +
3446
+ '</div>';
3447
+ },
3448
+ _renderFileFooter: function (caption, size, width, isError) {
3449
+ var self = this, config = self.fileActionSettings, rem = config.showRemove, drg = config.showDrag,
3450
+ upl = config.showUpload, zoom = config.showZoom, out,
3451
+ template = self._getLayoutTemplate('footer'), tInd = self._getLayoutTemplate('indicator'),
3452
+ ind = isError ? config.indicatorError : config.indicatorNew,
3453
+ title = isError ? config.indicatorErrorTitle : config.indicatorNewTitle,
3454
+ indicator = tInd.setTokens({'indicator': ind, 'indicatorTitle': title});
3455
+ size = self._getSize(size);
3456
+ if (self.isAjaxUpload) {
3457
+ out = template.setTokens({
3458
+ 'actions': self._renderFileActions(upl, false, rem, zoom, drg, false, false, false),
3459
+ 'caption': caption,
3460
+ 'size': size,
3461
+ 'width': width,
3462
+ 'progress': self._renderThumbProgress(),
3463
+ 'indicator': indicator
3464
+ });
3465
+ } else {
3466
+ out = template.setTokens({
3467
+ 'actions': self._renderFileActions(false, false, false, zoom, drg, false, false, false),
3468
+ 'caption': caption,
3469
+ 'size': size,
3470
+ 'width': width,
3471
+ 'progress': '',
3472
+ 'indicator': indicator
3473
+ });
3474
+ }
3475
+ out = $h.replaceTags(out, self.previewThumbTags);
3476
+ return out;
3477
+ },
3478
+ _renderFileActions: function (showUpl, showDwn, showDel, showZoom, showDrag, disabled, url, key, isInit, dUrl, dFile) {
3479
+ if (!showUpl && !showDwn && !showDel && !showZoom && !showDrag) {
3480
+ return '';
3481
+ }
3482
+ var self = this, vUrl = url === false ? '' : ' data-url="' + url + '"',
3483
+ vKey = key === false ? '' : ' data-key="' + key + '"', btnDelete = '', btnUpload = '', btnDownload = '',
3484
+ btnZoom = '', btnDrag = '', css, template = self._getLayoutTemplate('actions'),
3485
+ config = self.fileActionSettings,
3486
+ otherButtons = self.otherActionButtons.setTokens({'dataKey': vKey, 'key': key}),
3487
+ removeClass = disabled ? config.removeClass + ' disabled' : config.removeClass;
3488
+ if (showDel) {
3489
+ btnDelete = self._getLayoutTemplate('actionDelete').setTokens({
3490
+ 'removeClass': removeClass,
3491
+ 'removeIcon': config.removeIcon,
3492
+ 'removeTitle': config.removeTitle,
3493
+ 'dataUrl': vUrl,
3494
+ 'dataKey': vKey,
3495
+ 'key': key
3496
+ });
3497
+ }
3498
+ if (showUpl) {
3499
+ btnUpload = self._getLayoutTemplate('actionUpload').setTokens({
3500
+ 'uploadClass': config.uploadClass,
3501
+ 'uploadIcon': config.uploadIcon,
3502
+ 'uploadTitle': config.uploadTitle
3503
+ });
3504
+ }
3505
+ if (showDwn) {
3506
+ btnDownload = self._getLayoutTemplate('actionDownload').setTokens({
3507
+ 'downloadClass': config.downloadClass,
3508
+ 'downloadIcon': config.downloadIcon,
3509
+ 'downloadTitle': config.downloadTitle,
3510
+ 'downloadUrl': dUrl || self.initialPreviewDownloadUrl
3511
+ });
3512
+ btnDownload = btnDownload.setTokens({'filename': dFile, 'key': key});
3513
+ }
3514
+ if (showZoom) {
3515
+ btnZoom = self._getLayoutTemplate('actionZoom').setTokens({
3516
+ 'zoomClass': config.zoomClass,
3517
+ 'zoomIcon': config.zoomIcon,
3518
+ 'zoomTitle': config.zoomTitle
3519
+ });
3520
+ }
3521
+ if (showDrag && isInit) {
3522
+ css = 'drag-handle-init ' + config.dragClass;
3523
+ btnDrag = self._getLayoutTemplate('actionDrag').setTokens({
3524
+ 'dragClass': css,
3525
+ 'dragTitle': config.dragTitle,
3526
+ 'dragIcon': config.dragIcon
3527
+ });
3528
+ }
3529
+ return template.setTokens({
3530
+ 'delete': btnDelete,
3531
+ 'upload': btnUpload,
3532
+ 'download': btnDownload,
3533
+ 'zoom': btnZoom,
3534
+ 'drag': btnDrag,
3535
+ 'other': otherButtons
3536
+ });
3537
+ },
3538
+ _browse: function (e) {
3539
+ var self = this;
3540
+ self._raise('filebrowse');
3541
+ if (e && e.isDefaultPrevented()) {
3542
+ return;
3543
+ }
3544
+ if (self.isError && !self.isAjaxUpload) {
3545
+ self.clear();
3546
+ }
3547
+ self.$captionContainer.focus();
3548
+ },
3549
+ _filterDuplicate: function (file, files, fileIds) {
3550
+ var self = this, fileId = self._getFileId(file);
3551
+
3552
+ if (fileId && fileIds && fileIds.indexOf(fileId) > -1) {
3553
+ return;
3554
+ }
3555
+ if (!fileIds) {
3556
+ fileIds = [];
3557
+ }
3558
+ files.push(file);
3559
+ fileIds.push(fileId);
3560
+ },
3561
+ _change: function (e) {
3562
+ var self = this;
3563
+ if (self.changeTriggered) {
3564
+ return;
3565
+ }
3566
+ var $el = self.$element, isDragDrop = arguments.length > 1, isAjaxUpload = self.isAjaxUpload,
3567
+ tfiles = [], files = isDragDrop ? arguments[1] : $el.get(0).files, total,
3568
+ maxCount = !isAjaxUpload && $h.isEmpty($el.attr('multiple')) ? 1 : self.maxFileCount,
3569
+ len, ctr = self.filestack.length, isSingleUpload = $h.isEmpty($el.attr('multiple')),
3570
+ flagSingle = (isSingleUpload && ctr > 0), fileIds = self._getFileIds(),
3571
+ throwError = function (mesg, file, previewId, index) {
3572
+ var p1 = $.extend(true, {}, self._getOutData({}, {}, files), {id: previewId, index: index}),
3573
+ p2 = {id: previewId, index: index, file: file, files: files};
3574
+ return isAjaxUpload ? self._showUploadError(mesg, p1) : self._showError(mesg, p2);
3575
+ },
3576
+ maxCountCheck = function (n, m) {
3577
+ var msg = self.msgFilesTooMany.replace('{m}', m).replace('{n}', n);
3578
+ self.isError = throwError(msg, null, null, null);
3579
+ self.$captionContainer.removeClass('icon-visible');
3580
+ self._setCaption('', true);
3581
+ self.$container.removeClass('file-input-new file-input-ajax-new');
3582
+ };
3583
+ self.reader = null;
3584
+ self._resetUpload();
3585
+ self._hideFileIcon();
3586
+ if (self.dropZoneEnabled) {
3587
+ self.$container.find('.file-drop-zone .' + self.dropZoneTitleClass).remove();
3588
+ }
3589
+ if (isAjaxUpload) {
3590
+ $.each(files, function (vKey, vFile) {
3591
+ self._filterDuplicate(vFile, tfiles, fileIds);
3592
+ });
3593
+ } else {
3594
+ if (e.target && e.target.files === undefined) {
3595
+ files = e.target.value ? [{name: e.target.value.replace(/^.+\\/, '')}] : [];
3596
+ } else {
3597
+ files = e.target.files || {};
3598
+ }
3599
+ tfiles = files;
3600
+ }
3601
+ if ($h.isEmpty(tfiles) || tfiles.length === 0) {
3602
+ if (!isAjaxUpload) {
3603
+ self.clear();
3604
+ }
3605
+ self._raise('fileselectnone');
3606
+ return;
3607
+ }
3608
+ self._resetErrors();
3609
+ len = tfiles.length;
3610
+ total = self._getFileCount(isAjaxUpload ? (self.getFileStack().length + len) : len);
3611
+ if (maxCount > 0 && total > maxCount) {
3612
+ if (!self.autoReplace || len > maxCount) {
3613
+ maxCountCheck((self.autoReplace && len > maxCount ? len : total), maxCount);
3614
+ return;
3615
+ }
3616
+ if (total > maxCount) {
3617
+ self._resetPreviewThumbs(isAjaxUpload);
3618
+ }
3619
+ } else {
3620
+ if (!isAjaxUpload || flagSingle) {
3621
+ self._resetPreviewThumbs(false);
3622
+ if (flagSingle) {
3623
+ self.clearStack();
3624
+ }
3625
+ } else {
3626
+ if (isAjaxUpload && ctr === 0 && (!self.previewCache.count() || self.overwriteInitial)) {
3627
+ self._resetPreviewThumbs(true);
3628
+ }
3629
+ }
3630
+ }
3631
+ if (self.isPreviewable) {
3632
+ self.readFiles(tfiles);
3633
+ } else {
3634
+ self._updateFileDetails(1);
3635
+ }
3636
+ },
3637
+ _abort: function (params) {
3638
+ var self = this, data;
3639
+ if (self.ajaxAborted && typeof self.ajaxAborted === "object" && self.ajaxAborted.message !== undefined) {
3640
+ data = $.extend(true, {}, self._getOutData(), params);
3641
+ data.abortData = self.ajaxAborted.data || {};
3642
+ data.abortMessage = self.ajaxAborted.message;
3643
+ self._setProgress(101, self.$progress, self.msgCancelled);
3644
+ self._showUploadError(self.ajaxAborted.message, data, 'filecustomerror');
3645
+ self.cancel();
3646
+ return true;
3647
+ }
3648
+ return !!self.ajaxAborted;
3649
+ },
3650
+ _resetFileStack: function () {
3651
+ var self = this, i = 0, newstack = [], newnames = [], newids = [];
3652
+ self._getThumbs().each(function () {
3653
+ var $thumb = $(this), ind = $thumb.attr('data-fileindex'), file = self.filestack[ind],
3654
+ pid = $thumb.attr('id');
3655
+ if (ind === '-1' || ind === -1) {
3656
+ return;
3657
+ }
3658
+ if (file !== undefined) {
3659
+ newstack[i] = file;
3660
+ newnames[i] = self._getFileName(file);
3661
+ newids[i] = self._getFileId(file);
3662
+ $thumb.attr({'id': self.previewInitId + '-' + i, 'data-fileindex': i});
3663
+ i++;
3664
+ } else {
3665
+ $thumb.attr({'id': 'uploaded-' + $h.uniqId(), 'data-fileindex': '-1'});
3666
+ }
3667
+ self.$preview.find('#zoom-' + pid).attr({
3668
+ 'id': 'zoom-' + $thumb.attr('id'),
3669
+ 'data-fileindex': $thumb.attr('data-fileindex')
3670
+ });
3671
+ });
3672
+ self.filestack = newstack;
3673
+ self.filenames = newnames;
3674
+ self.fileids = newids;
3675
+ },
3676
+ _isFileSelectionValid: function (cnt) {
3677
+ var self = this;
3678
+ cnt = cnt || 0;
3679
+ if (self.required && !self.getFilesCount()) {
3680
+ self.$errorContainer.html('');
3681
+ self._showUploadError(self.msgFileRequired);
3682
+ return false;
3683
+ }
3684
+ if (self.minFileCount > 0 && self._getFileCount(cnt) < self.minFileCount) {
3685
+ self._noFilesError({});
3686
+ return false;
3687
+ }
3688
+ return true;
3689
+ },
3690
+ clearStack: function () {
3691
+ var self = this;
3692
+ self.filestack = [];
3693
+ self.filenames = [];
3694
+ self.fileids = [];
3695
+ return self.$element;
3696
+ },
3697
+ updateStack: function (i, file) {
3698
+ var self = this;
3699
+ self.filestack[i] = file;
3700
+ self.filenames[i] = self._getFileName(file);
3701
+ self.fileids[i] = file && self._getFileId(file) || null;
3702
+ return self.$element;
3703
+ },
3704
+ addToStack: function (file) {
3705
+ var self = this;
3706
+ self.filestack.push(file);
3707
+ self.filenames.push(self._getFileName(file));
3708
+ self.fileids.push(self._getFileId(file));
3709
+ return self.$element;
3710
+ },
3711
+ getFileStack: function (skipNull) {
3712
+ var self = this;
3713
+ return self.filestack.filter(function (n) {
3714
+ return (skipNull ? n !== undefined : n !== undefined && n !== null);
3715
+ });
3716
+ },
3717
+ getFilesCount: function () {
3718
+ var self = this, len = self.isAjaxUpload ? self.getFileStack().length : self._inputFileCount();
3719
+ return self._getFileCount(len);
3720
+ },
3721
+ readFiles: function (files) {
3722
+ this.reader = new FileReader();
3723
+ var self = this, $el = self.$element, $preview = self.$preview, reader = self.reader,
3724
+ $container = self.$previewContainer, $status = self.$previewStatus, msgLoading = self.msgLoading,
3725
+ msgProgress = self.msgProgress, previewInitId = self.previewInitId, numFiles = files.length,
3726
+ settings = self.fileTypeSettings, ctr = self.filestack.length, readFile,
3727
+ fileTypes = self.allowedFileTypes, typLen = fileTypes ? fileTypes.length : 0,
3728
+ fileExt = self.allowedFileExtensions, strExt = $h.isEmpty(fileExt) ? '' : fileExt.join(', '),
3729
+ maxPreviewSize = self.maxFilePreviewSize && parseFloat(self.maxFilePreviewSize),
3730
+ canPreview = $preview.length && (!maxPreviewSize || isNaN(maxPreviewSize)),
3731
+ throwError = function (msg, file, previewId, index) {
3732
+ var p1 = $.extend(true, {}, self._getOutData({}, {}, files), {id: previewId, index: index}),
3733
+ p2 = {id: previewId, index: index, file: file, files: files}, $thumb;
3734
+ self._previewDefault(file, previewId, true);
3735
+ if (self.isAjaxUpload) {
3736
+ self.addToStack(undefined);
3737
+ setTimeout(function () {
3738
+ readFile(index + 1);
3739
+ }, 100);
3740
+ } else {
3741
+ numFiles = 0;
3742
+ }
3743
+ self._initFileActions();
3744
+ $thumb = $('#' + previewId);
3745
+ $thumb.find('.kv-file-upload').hide();
3746
+ if (self.removeFromPreviewOnError) {
3747
+ $thumb.remove();
3748
+ }
3749
+ self.isError = self.isAjaxUpload ? self._showUploadError(msg, p1) : self._showError(msg, p2);
3750
+ self._updateFileDetails(numFiles);
3751
+ };
3752
+
3753
+ self.loadedImages = [];
3754
+ self.totalImagesCount = 0;
3755
+
3756
+ $.each(files, function (key, file) {
3757
+ var func = self.fileTypeSettings.image;
3758
+ if (func && func(file.type)) {
3759
+ self.totalImagesCount++;
3760
+ }
3761
+ });
3762
+ readFile = function (i) {
3763
+ if ($h.isEmpty($el.attr('multiple'))) {
3764
+ numFiles = 1;
3765
+ }
3766
+ if (i >= numFiles) {
3767
+ if (self.isAjaxUpload && self.filestack.length > 0) {
3768
+ self._raise('filebatchselected', [self.getFileStack()]);
3769
+ } else {
3770
+ self._raise('filebatchselected', [files]);
3771
+ }
3772
+ $container.removeClass('file-thumb-loading');
3773
+ $status.html('');
3774
+ return;
3775
+ }
3776
+ var node = ctr + i, previewId = previewInitId + "-" + node, file = files[i], fSizeKB, j, msg,
3777
+ fnText = settings.text, fnImage = settings.image, fnHtml = settings.html, typ, chk, typ1, typ2,
3778
+ caption = file && file.name ? self.slug(file.name) : '', fileSize = (file && file.size || 0) / 1000,
3779
+ fileExtExpr = '', previewData = file ? $h.objUrl.createObjectURL(file) : null, fileCount = 0, strTypes = '',
3780
+ func, knownTypes = 0, isText, isHtml, isImage, txtFlag, processFileLoaded = function () {
3781
+ var msg = msgProgress.setTokens({
3782
+ 'index': i + 1,
3783
+ 'files': numFiles,
3784
+ 'percent': 50,
3785
+ 'name': caption
3786
+ });
3787
+ setTimeout(function () {
3788
+ $status.html(msg);
3789
+ self._updateFileDetails(numFiles);
3790
+ readFile(i + 1);
3791
+ }, 100);
3792
+ self._raise('fileloaded', [file, previewId, i, reader]);
3793
+ };
3794
+ if (!file) {
3795
+ return;
3796
+ }
3797
+ if (typLen > 0) {
3798
+ for (j = 0; j < typLen; j++) {
3799
+ typ1 = fileTypes[j];
3800
+ typ2 = self.msgFileTypes[typ1] || typ1;
3801
+ strTypes += j === 0 ? typ2 : ', ' + typ2;
3802
+ }
3803
+ }
3804
+ if (caption === false) {
3805
+ readFile(i + 1);
3806
+ return;
3807
+ }
3808
+ if (caption.length === 0) {
3809
+ msg = self.msgInvalidFileName.replace('{name}', $h.htmlEncode(file.name));
3810
+ throwError(msg, file, previewId, i);
3811
+ return;
3812
+ }
3813
+ if (!$h.isEmpty(fileExt)) {
3814
+ fileExtExpr = new RegExp('\\.(' + fileExt.join('|') + ')$', 'i');
3815
+ }
3816
+ fSizeKB = fileSize.toFixed(2);
3817
+ if (self.maxFileSize > 0 && fileSize > self.maxFileSize) {
3818
+ msg = self.msgSizeTooLarge.setTokens({
3819
+ 'name': caption,
3820
+ 'size': fSizeKB,
3821
+ 'maxSize': self.maxFileSize
3822
+ });
3823
+ throwError(msg, file, previewId, i);
3824
+ return;
3825
+ }
3826
+ if (self.minFileSize !== null && fileSize <= $h.getNum(self.minFileSize)) {
3827
+ msg = self.msgSizeTooSmall.setTokens({
3828
+ 'name': caption,
3829
+ 'size': fSizeKB,
3830
+ 'minSize': self.minFileSize
3831
+ });
3832
+ throwError(msg, file, previewId, i);
3833
+ return;
3834
+ }
3835
+ if (!$h.isEmpty(fileTypes) && $h.isArray(fileTypes)) {
3836
+ for (j = 0; j < fileTypes.length; j += 1) {
3837
+ typ = fileTypes[j];
3838
+ func = settings[typ];
3839
+ fileCount += !func || (typeof func !== 'function') ? 0 : (func(file.type, file.name) ? 1 : 0);
3840
+ }
3841
+ if (fileCount === 0) {
3842
+ msg = self.msgInvalidFileType.setTokens({'name': caption, 'types': strTypes});
3843
+ throwError(msg, file, previewId, i);
3844
+ return;
3845
+ }
3846
+ }
3847
+ if (fileCount === 0 && !$h.isEmpty(fileExt) && $h.isArray(fileExt) && !$h.isEmpty(fileExtExpr)) {
3848
+ chk = $h.compare(caption, fileExtExpr);
3849
+ fileCount += $h.isEmpty(chk) ? 0 : chk.length;
3850
+ if (fileCount === 0) {
3851
+ msg = self.msgInvalidFileExtension.setTokens({'name': caption, 'extensions': strExt});
3852
+ throwError(msg, file, previewId, i);
3853
+ return;
3854
+ }
3855
+ }
3856
+ if (!self.showPreview) {
3857
+ if (self.isAjaxUpload) {
3858
+ self.addToStack(file);
3859
+ }
3860
+ setTimeout(function () {
3861
+ readFile(i + 1);
3862
+ self._updateFileDetails(numFiles);
3863
+ }, 100);
3864
+ self._raise('fileloaded', [file, previewId, i, reader]);
3865
+ return;
3866
+ }
3867
+ if (!canPreview && fileSize > maxPreviewSize) {
3868
+ self.addToStack(file);
3869
+ $container.addClass('file-thumb-loading');
3870
+ self._previewDefault(file, previewId);
3871
+ self._initFileActions();
3872
+ self._updateFileDetails(numFiles);
3873
+ readFile(i + 1);
3874
+ return;
3875
+ }
3876
+ if ($preview.length && FileReader !== undefined) {
3877
+ isText = fnText(file.type, caption);
3878
+ isHtml = fnHtml(file.type, caption);
3879
+ isImage = fnImage(file.type, caption);
3880
+ $status.html(msgLoading.replace('{index}', i + 1).replace('{files}', numFiles));
3881
+ $container.addClass('file-thumb-loading');
3882
+ reader.onerror = function (evt) {
3883
+ self._errorHandler(evt, caption);
3884
+ };
3885
+ reader.onload = function (theFile) {
3886
+ var hex, fileInfo, uint, byte, bytes = [], contents, mime, readTextImage = function (textFlag) {
3887
+ var newReader = new FileReader();
3888
+ newReader.onerror = function (theFileNew) {
3889
+ self._errorHandler(theFileNew, caption);
3890
+ };
3891
+ newReader.onload = function (theFileNew) {
3892
+ self._previewFile(i, file, theFileNew, previewId, previewData, fileInfo);
3893
+ self._initFileActions();
3894
+ processFileLoaded();
3895
+ };
3896
+ if (textFlag) {
3897
+ newReader.readAsText(file, self.textEncoding);
3898
+ } else {
3899
+ newReader.readAsDataURL(file);
3900
+ }
3901
+ };
3902
+ fileInfo = {'name': caption, 'type': file.type};
3903
+ $.each(settings, function (key, func) {
3904
+ if (key !== 'object' && key !== 'other' && func(file.type, caption)) {
3905
+ knownTypes++;
3906
+ }
3907
+ });
3908
+ if (knownTypes === 0) {// auto detect mime types from content if no known file types detected
3909
+ uint = new Uint8Array(theFile.target.result);
3910
+ for (j = 0; j < uint.length; j++) {
3911
+ byte = uint[j].toString(16);
3912
+ bytes.push(byte);
3913
+ }
3914
+ hex = bytes.join('').toLowerCase().substring(0, 8);
3915
+ mime = $h.getMimeType(hex, '', '');
3916
+ if ($h.isEmpty(mime)) { // look for ascii text content
3917
+ contents = $h.arrayBuffer2String(reader.result);
3918
+ mime = $h.isSvg(contents) ? 'image/svg+xml' : $h.getMimeType(hex, contents, file.type);
3919
+ }
3920
+ fileInfo = {'name': caption, 'type': mime};
3921
+ isText = fnText(mime, '');
3922
+ isHtml = fnHtml(mime, '');
3923
+ isImage = fnImage(mime, '');
3924
+ txtFlag = isText || isHtml;
3925
+ if (txtFlag || isImage) {
3926
+ readTextImage(txtFlag);
3927
+ return;
3928
+ }
3929
+ }
3930
+ self._previewFile(i, file, theFile, previewId, previewData, fileInfo);
3931
+ self._initFileActions();
3932
+ processFileLoaded();
3933
+ };
3934
+ reader.onprogress = function (data) {
3935
+ if (data.lengthComputable) {
3936
+ var fact = (data.loaded / data.total) * 100, progress = Math.ceil(fact);
3937
+ msg = msgProgress.setTokens({
3938
+ 'index': i + 1,
3939
+ 'files': numFiles,
3940
+ 'percent': progress,
3941
+ 'name': caption
3942
+ });
3943
+ setTimeout(function () {
3944
+ $status.html(msg);
3945
+ }, 100);
3946
+ }
3947
+ };
3948
+
3949
+ if (isText || isHtml) {
3950
+ reader.readAsText(file, self.textEncoding);
3951
+ } else {
3952
+ if (isImage) {
3953
+ reader.readAsDataURL(file);
3954
+ } else {
3955
+ reader.readAsArrayBuffer(file);
3956
+ }
3957
+ }
3958
+ } else {
3959
+ self._previewDefault(file, previewId);
3960
+ setTimeout(function () {
3961
+ readFile(i + 1);
3962
+ self._updateFileDetails(numFiles);
3963
+ }, 100);
3964
+ self._raise('fileloaded', [file, previewId, i, reader]);
3965
+ }
3966
+ self.addToStack(file);
3967
+ };
3968
+
3969
+ readFile(0);
3970
+ self._updateFileDetails(numFiles, false);
3971
+ },
3972
+ lock: function () {
3973
+ var self = this;
3974
+ self._resetErrors();
3975
+ self.disable();
3976
+ if (self.showRemove) {
3977
+ self.$container.find('.fileinput-remove').hide();
3978
+ }
3979
+ if (self.showCancel) {
3980
+ self.$container.find('.fileinput-cancel').show();
3981
+ }
3982
+ self._raise('filelock', [self.filestack, self._getExtraData()]);
3983
+ return self.$element;
3984
+ },
3985
+ unlock: function (reset) {
3986
+ var self = this;
3987
+ if (reset === undefined) {
3988
+ reset = true;
3989
+ }
3990
+ self.enable();
3991
+ if (self.showCancel) {
3992
+ self.$container.find('.fileinput-cancel').hide();
3993
+ }
3994
+ if (self.showRemove) {
3995
+ self.$container.find('.fileinput-remove').show();
3996
+ }
3997
+ if (reset) {
3998
+ self._resetFileStack();
3999
+ }
4000
+ self._raise('fileunlock', [self.filestack, self._getExtraData()]);
4001
+ return self.$element;
4002
+ },
4003
+ cancel: function () {
4004
+ var self = this, xhr = self.ajaxRequests, len = xhr.length, i;
4005
+ if (len > 0) {
4006
+ for (i = 0; i < len; i += 1) {
4007
+ self.cancelling = true;
4008
+ xhr[i].abort();
4009
+ }
4010
+ }
4011
+ self._setProgressCancelled();
4012
+ self._getThumbs().each(function () {
4013
+ var $thumb = $(this), ind = $thumb.attr('data-fileindex');
4014
+ $thumb.removeClass('file-uploading');
4015
+ if (self.filestack[ind] !== undefined) {
4016
+ $thumb.find('.kv-file-upload').removeClass('disabled').removeAttr('disabled');
4017
+ $thumb.find('.kv-file-remove').removeClass('disabled').removeAttr('disabled');
4018
+ }
4019
+ self.unlock();
4020
+ });
4021
+ return self.$element;
4022
+ },
4023
+ clear: function () {
4024
+ var self = this, cap;
4025
+ if (!self._raise('fileclear')) {
4026
+ return;
4027
+ }
4028
+ self.$btnUpload.removeAttr('disabled');
4029
+ self._getThumbs().find('video,audio,img').each(function () {
4030
+ $h.cleanMemory($(this));
4031
+ });
4032
+ self._clearFileInput();
4033
+ self._resetUpload();
4034
+ self.clearStack();
4035
+ self._resetErrors(true);
4036
+ if (self._hasInitialPreview()) {
4037
+ self._showFileIcon();
4038
+ self._resetPreview();
4039
+ self._initPreviewActions();
4040
+ self.$container.removeClass('file-input-new');
4041
+ } else {
4042
+ self._getThumbs().each(function () {
4043
+ self._clearObjects($(this));
4044
+ });
4045
+ if (self.isAjaxUpload) {
4046
+ self.previewCache.data = {};
4047
+ }
4048
+ self.$preview.html('');
4049
+ cap = (!self.overwriteInitial && self.initialCaption.length > 0) ? self.initialCaption : '';
4050
+ self.$caption.attr('title', '').val(cap);
4051
+ $h.addCss(self.$container, 'file-input-new');
4052
+ self._validateDefaultPreview();
4053
+ }
4054
+ if (self.$container.find($h.FRAMES).length === 0) {
4055
+ if (!self._initCaption()) {
4056
+ self.$captionContainer.removeClass('icon-visible');
4057
+ }
4058
+ }
4059
+ self._hideFileIcon();
4060
+ self._raise('filecleared');
4061
+ self.$captionContainer.focus();
4062
+ self._setFileDropZoneTitle();
4063
+ return self.$element;
4064
+ },
4065
+ reset: function () {
4066
+ var self = this;
4067
+ if (!self._raise('filereset')) {
4068
+ return;
4069
+ }
4070
+ self._resetPreview();
4071
+ self.$container.find('.fileinput-filename').text('');
4072
+ $h.addCss(self.$container, 'file-input-new');
4073
+ if (self.getFrames().length || self.dropZoneEnabled) {
4074
+ self.$container.removeClass('file-input-new');
4075
+ }
4076
+ self.clearStack();
4077
+ self.formdata = {};
4078
+ self._setFileDropZoneTitle();
4079
+ return self.$element;
4080
+ },
4081
+ disable: function () {
4082
+ var self = this;
4083
+ self.isDisabled = true;
4084
+ self._raise('filedisabled');
4085
+ self.$element.attr('disabled', 'disabled');
4086
+ self.$container.find(".kv-fileinput-caption").addClass("file-caption-disabled");
4087
+ self.$container.find(".fileinput-remove, .fileinput-upload, .file-preview-frame button")
4088
+ .attr("disabled", true);
4089
+ $h.addCss(self.$container.find('.btn-file'), 'disabled');
4090
+ self._initDragDrop();
4091
+ return self.$element;
4092
+ },
4093
+ enable: function () {
4094
+ var self = this;
4095
+ self.isDisabled = false;
4096
+ self._raise('fileenabled');
4097
+ self.$element.removeAttr('disabled');
4098
+ self.$container.find(".kv-fileinput-caption").removeClass("file-caption-disabled");
4099
+ self.$container.find(".fileinput-remove, .fileinput-upload, .file-preview-frame button")
4100
+ .removeAttr("disabled");
4101
+ self.$container.find('.btn-file').removeClass('disabled');
4102
+ self._initDragDrop();
4103
+ return self.$element;
4104
+ },
4105
+ upload: function () {
4106
+ var self = this, totLen = self.getFileStack().length, i, outData, len,
4107
+ hasExtraData = !$.isEmptyObject(self._getExtraData());
4108
+ if (!self.isAjaxUpload || self.isDisabled || !self._isFileSelectionValid(totLen)) {
4109
+ return;
4110
+ }
4111
+ self._resetUpload();
4112
+ if (totLen === 0 && !hasExtraData) {
4113
+ self._showUploadError(self.msgUploadEmpty);
4114
+ return;
4115
+ }
4116
+ self.$progress.show();
4117
+ self.uploadCount = 0;
4118
+ self.uploadStatus = {};
4119
+ self.uploadLog = [];
4120
+ self.lock();
4121
+ self._setProgress(2);
4122
+ if (totLen === 0 && hasExtraData) {
4123
+ self._uploadExtraOnly();
4124
+ return;
4125
+ }
4126
+ len = self.filestack.length;
4127
+ self.hasInitData = false;
4128
+ if (self.uploadAsync) {
4129
+ outData = self._getOutData();
4130
+ self._raise('filebatchpreupload', [outData]);
4131
+ self.fileBatchCompleted = false;
4132
+ self.uploadCache = {content: [], config: [], tags: [], append: true};
4133
+ self.uploadAsyncCount = self.getFileStack().length;
4134
+ for (i = 0; i < len; i++) {
4135
+ self.uploadCache.content[i] = null;
4136
+ self.uploadCache.config[i] = null;
4137
+ self.uploadCache.tags[i] = null;
4138
+ }
4139
+ self.$preview.find('.file-preview-initial').removeClass($h.SORT_CSS);
4140
+ self._initSortable();
4141
+ self.cacheInitialPreview = self.getPreview();
4142
+
4143
+ for (i = 0; i < len; i++) {
4144
+ if (self.filestack[i]) {
4145
+ self._uploadSingle(i, true);
4146
+ }
4147
+ }
4148
+ return;
4149
+ }
4150
+ self._uploadBatch();
4151
+ return self.$element;
4152
+ },
4153
+ destroy: function () {
4154
+ var self = this, $form = self.$form, $cont = self.$container, $el = self.$element, ns = self.namespace;
4155
+ $(document).off(ns);
4156
+ $(window).off(ns);
4157
+ if ($form && $form.length) {
4158
+ $form.off(ns);
4159
+ }
4160
+ if (self.isAjaxUpload) {
4161
+ self._clearFileInput();
4162
+ }
4163
+ self._cleanup();
4164
+ self._initPreviewCache();
4165
+ $el.insertBefore($cont).off(ns).removeData();
4166
+ $cont.off().remove();
4167
+ return $el;
4168
+ },
4169
+ refresh: function (options) {
4170
+ var self = this, $el = self.$element;
4171
+ if (typeof options !== 'object' || $h.isEmpty(options)) {
4172
+ options = self.options;
4173
+ } else {
4174
+ options = $.extend(true, {}, self.options, options);
4175
+ }
4176
+ self._init(options, true);
4177
+ self._listen();
4178
+ return $el;
4179
+ },
4180
+ zoom: function (frameId) {
4181
+ var self = this, $frame = self._getFrame(frameId), $modal = self.$modal;
4182
+ if (!$frame) {
4183
+ return;
4184
+ }
4185
+ $h.initModal($modal);
4186
+ $modal.html(self._getModalContent());
4187
+ self._setZoomContent($frame);
4188
+ $modal.modal('show');
4189
+ self._initZoomButtons();
4190
+ },
4191
+ getExif: function (frameId) {
4192
+ var self = this, $frame = self._getFrame(frameId);
4193
+ return $frame && $frame.data('exif') || null;
4194
+ },
4195
+ getFrames: function (cssFilter) {
4196
+ var self = this, $frames;
4197
+ cssFilter = cssFilter || '';
4198
+ $frames = self.$preview.find($h.FRAMES + cssFilter);
4199
+ if (self.reversePreviewOrder) {
4200
+ $frames = $($frames.get().reverse());
4201
+ }
4202
+ return $frames;
4203
+ },
4204
+ getPreview: function () {
4205
+ var self = this;
4206
+ return {
4207
+ content: self.initialPreview,
4208
+ config: self.initialPreviewConfig,
4209
+ tags: self.initialPreviewThumbTags
4210
+ };
4211
+ }
4212
+ };
4213
+
4214
+ $.fn.fileinput = function (option) {
4215
+ if (!$h.hasFileAPISupport() && !$h.isIE(9)) {
4216
+ return;
4217
+ }
4218
+ var args = Array.apply(null, arguments), retvals = [];
4219
+ args.shift();
4220
+ this.each(function () {
4221
+ var self = $(this), data = self.data('fileinput'), options = typeof option === 'object' && option,
4222
+ theme = options.theme || self.data('theme'), l = {}, t = {},
4223
+ lang = options.language || self.data('language') || $.fn.fileinput.defaults.language || 'en', opt;
4224
+ if (!data) {
4225
+ if (theme) {
4226
+ t = $.fn.fileinputThemes[theme] || {};
4227
+ }
4228
+ if (lang !== 'en' && !$h.isEmpty($.fn.fileinputLocales[lang])) {
4229
+ l = $.fn.fileinputLocales[lang] || {};
4230
+ }
4231
+ opt = $.extend(true, {}, $.fn.fileinput.defaults, t, $.fn.fileinputLocales.en, l, options, self.data());
4232
+ data = new FileInput(this, opt);
4233
+ self.data('fileinput', data);
4234
+ }
4235
+
4236
+ if (typeof option === 'string') {
4237
+ retvals.push(data[option].apply(data, args));
4238
+ }
4239
+ });
4240
+ switch (retvals.length) {
4241
+ case 0:
4242
+ return this;
4243
+ case 1:
4244
+ return retvals[0];
4245
+ default:
4246
+ return retvals;
4247
+ }
4248
+ };
4249
+
4250
+ $.fn.fileinput.defaults = {
4251
+ language: 'en',
4252
+ showCaption: true,
4253
+ showBrowse: true,
4254
+ showPreview: true,
4255
+ showRemove: true,
4256
+ showUpload: true,
4257
+ showCancel: true,
4258
+ showClose: true,
4259
+ showUploadedThumbs: true,
4260
+ browseOnZoneClick: false,
4261
+ autoReplace: false,
4262
+ autoOrientImage: true, // for JPEG images based on EXIF orientation tag
4263
+ required: false,
4264
+ rtl: false,
4265
+ hideThumbnailContent: false,
4266
+ generateFileId: null,
4267
+ previewClass: '',
4268
+ captionClass: '',
4269
+ frameClass: 'krajee-default',
4270
+ mainClass: 'file-caption-main',
4271
+ mainTemplate: null,
4272
+ purifyHtml: true,
4273
+ fileSizeGetter: null,
4274
+ initialCaption: '',
4275
+ initialPreview: [],
4276
+ initialPreviewDelimiter: '*$$*',
4277
+ initialPreviewAsData: false,
4278
+ initialPreviewFileType: 'image',
4279
+ initialPreviewConfig: [],
4280
+ initialPreviewThumbTags: [],
4281
+ previewThumbTags: {},
4282
+ initialPreviewShowDelete: true,
4283
+ initialPreviewDownloadUrl: '',
4284
+ removeFromPreviewOnError: false,
4285
+ deleteUrl: '',
4286
+ deleteExtraData: {},
4287
+ overwriteInitial: true,
4288
+ previewZoomButtonIcons: {
4289
+ prev: '<i class="glyphicon glyphicon-triangle-left"></i>',
4290
+ next: '<i class="glyphicon glyphicon-triangle-right"></i>',
4291
+ toggleheader: '<i class="glyphicon glyphicon-resize-vertical"></i>',
4292
+ fullscreen: '<i class="glyphicon glyphicon-fullscreen"></i>',
4293
+ borderless: '<i class="glyphicon glyphicon-resize-full"></i>',
4294
+ close: '<i class="glyphicon glyphicon-remove"></i>'
4295
+ },
4296
+ previewZoomButtonClasses: {
4297
+ prev: 'btn btn-navigate',
4298
+ next: 'btn btn-navigate',
4299
+ toggleheader: 'btn btn-sm btn-kv btn-default btn-outline-secondary',
4300
+ fullscreen: 'btn btn-sm btn-kv btn-default btn-outline-secondary',
4301
+ borderless: 'btn btn-sm btn-kv btn-default btn-outline-secondary',
4302
+ close: 'btn btn-sm btn-kv btn-default btn-outline-secondary'
4303
+ },
4304
+ preferIconicPreview: false,
4305
+ preferIconicZoomPreview: false,
4306
+ allowedPreviewTypes: undefined,
4307
+ allowedPreviewMimeTypes: null,
4308
+ allowedFileTypes: null,
4309
+ allowedFileExtensions: null,
4310
+ defaultPreviewContent: null,
4311
+ customLayoutTags: {},
4312
+ customPreviewTags: {},
4313
+ previewFileIcon: '<i class="glyphicon glyphicon-file"></i>',
4314
+ previewFileIconClass: 'file-other-icon',
4315
+ previewFileIconSettings: {},
4316
+ previewFileExtSettings: {},
4317
+ buttonLabelClass: 'hidden-xs',
4318
+ browseIcon: '<i class="glyphicon glyphicon-folder-open"></i>&nbsp;',
4319
+ browseClass: 'btn btn-primary',
4320
+ removeIcon: '<i class="glyphicon glyphicon-trash"></i>',
4321
+ removeClass: 'btn btn-default btn-secondary',
4322
+ cancelIcon: '<i class="glyphicon glyphicon-ban-circle"></i>',
4323
+ cancelClass: 'btn btn-default btn-secondary',
4324
+ uploadIcon: '<i class="glyphicon glyphicon-upload"></i>',
4325
+ uploadClass: 'btn btn-default btn-secondary',
4326
+ uploadUrl: null,
4327
+ uploadUrlThumb: null,
4328
+ uploadAsync: true,
4329
+ uploadExtraData: {},
4330
+ zoomModalHeight: 480,
4331
+ minImageWidth: null,
4332
+ minImageHeight: null,
4333
+ maxImageWidth: null,
4334
+ maxImageHeight: null,
4335
+ resizeImage: false,
4336
+ resizePreference: 'width',
4337
+ resizeQuality: 0.92,
4338
+ resizeDefaultImageType: 'image/jpeg',
4339
+ resizeIfSizeMoreThan: 0, // in KB
4340
+ minFileSize: 0,
4341
+ maxFileSize: 0,
4342
+ maxFilePreviewSize: 25600, // 25 MB
4343
+ minFileCount: 0,
4344
+ maxFileCount: 0,
4345
+ validateInitialCount: false,
4346
+ msgValidationErrorClass: 'text-danger',
4347
+ msgValidationErrorIcon: '<i class="glyphicon glyphicon-exclamation-sign"></i> ',
4348
+ msgErrorClass: 'file-error-message',
4349
+ progressThumbClass: "progress-bar bg-success progress-bar-success progress-bar-striped active",
4350
+ progressClass: "progress-bar bg-success progress-bar-success progress-bar-striped active",
4351
+ progressCompleteClass: "progress-bar bg-success progress-bar-success",
4352
+ progressErrorClass: "progress-bar bg-danger progress-bar-danger",
4353
+ progressUploadThreshold: 99,
4354
+ previewFileType: 'image',
4355
+ elCaptionContainer: null,
4356
+ elCaptionText: null,
4357
+ elPreviewContainer: null,
4358
+ elPreviewImage: null,
4359
+ elPreviewStatus: null,
4360
+ elErrorContainer: null,
4361
+ errorCloseButton: $h.closeButton('kv-error-close'),
4362
+ slugCallback: null,
4363
+ dropZoneEnabled: true,
4364
+ dropZoneTitleClass: 'file-drop-zone-title',
4365
+ fileActionSettings: {},
4366
+ otherActionButtons: '',
4367
+ textEncoding: 'UTF-8',
4368
+ ajaxSettings: {},
4369
+ ajaxDeleteSettings: {},
4370
+ showAjaxErrorDetails: true,
4371
+ mergeAjaxCallbacks: false,
4372
+ mergeAjaxDeleteCallbacks: false,
4373
+ retryErrorUploads: true,
4374
+ reversePreviewOrder: false
4375
+ };
4376
+
4377
+ $.fn.fileinputLocales.en = {
4378
+ fileSingle: 'file',
4379
+ filePlural: 'files',
4380
+ browseLabel: 'Browse &hellip;',
4381
+ removeLabel: 'Remove',
4382
+ removeTitle: 'Clear selected files',
4383
+ cancelLabel: 'Cancel',
4384
+ cancelTitle: 'Abort ongoing upload',
4385
+ uploadLabel: 'Upload',
4386
+ uploadTitle: 'Upload selected files',
4387
+ msgNo: 'No',
4388
+ msgNoFilesSelected: 'No files selected',
4389
+ msgCancelled: 'Cancelled',
4390
+ msgPlaceholder: 'Select {files}...',
4391
+ msgZoomModalHeading: 'Detailed Preview',
4392
+ msgFileRequired: 'You must select a file to upload.',
4393
+ msgSizeTooSmall: 'File "{name}" (<b>{size} KB</b>) is too small and must be larger than <b>{minSize} KB</b>.',
4394
+ msgSizeTooLarge: 'File "{name}" (<b>{size} KB</b>) exceeds maximum allowed upload size of <b>{maxSize} KB</b>.',
4395
+ msgFilesTooLess: 'You must select at least <b>{n}</b> {files} to upload.',
4396
+ msgFilesTooMany: 'Number of files selected for upload <b>({n})</b> exceeds maximum allowed limit of <b>{m}</b>.',
4397
+ msgFileNotFound: 'File "{name}" not found!',
4398
+ msgFileSecured: 'Security restrictions prevent reading the file "{name}".',
4399
+ msgFileNotReadable: 'File "{name}" is not readable.',
4400
+ msgFilePreviewAborted: 'File preview aborted for "{name}".',
4401
+ msgFilePreviewError: 'An error occurred while reading the file "{name}".',
4402
+ msgInvalidFileName: 'Invalid or unsupported characters in file name "{name}".',
4403
+ msgInvalidFileType: 'Invalid type for file "{name}". Only "{types}" files are supported.',
4404
+ msgInvalidFileExtension: 'Invalid extension for file "{name}". Only "{extensions}" files are supported.',
4405
+ msgFileTypes: {
4406
+ 'image': 'image',
4407
+ 'html': 'HTML',
4408
+ 'text': 'text',
4409
+ 'video': 'video',
4410
+ 'audio': 'audio',
4411
+ 'flash': 'flash',
4412
+ 'pdf': 'PDF',
4413
+ 'object': 'object'
4414
+ },
4415
+ msgUploadAborted: 'The file upload was aborted',
4416
+ msgUploadThreshold: 'Processing...',
4417
+ msgUploadBegin: 'Initializing...',
4418
+ msgUploadEnd: 'Done',
4419
+ msgUploadEmpty: 'No valid data available for upload.',
4420
+ msgUploadError: 'Error',
4421
+ msgValidationError: 'Validation Error',
4422
+ msgLoading: 'Loading file {index} of {files} &hellip;',
4423
+ msgProgress: 'Loading file {index} of {files} - {name} - {percent}% completed.',
4424
+ msgSelected: '{n} {files} selected',
4425
+ msgFoldersNotAllowed: 'Drag & drop files only! {n} folder(s) dropped were skipped.',
4426
+ msgImageWidthSmall: 'Width of image file "{name}" must be at least {size} px.',
4427
+ msgImageHeightSmall: 'Height of image file "{name}" must be at least {size} px.',
4428
+ msgImageWidthLarge: 'Width of image file "{name}" cannot exceed {size} px.',
4429
+ msgImageHeightLarge: 'Height of image file "{name}" cannot exceed {size} px.',
4430
+ msgImageResizeError: 'Could not get the image dimensions to resize.',
4431
+ msgImageResizeException: 'Error while resizing the image.<pre>{errors}</pre>',
4432
+ msgAjaxError: 'Something went wrong with the {operation} operation. Please try again later!',
4433
+ msgAjaxProgressError: '{operation} failed',
4434
+ ajaxOperations: {
4435
+ deleteThumb: 'file delete',
4436
+ uploadThumb: 'file upload',
4437
+ uploadBatch: 'batch file upload',
4438
+ uploadExtra: 'form data upload'
4439
+ },
4440
+ dropZoneTitle: 'Drag & drop files here &hellip;',
4441
+ dropZoneClickTitle: '<br>(or click to select {files})',
4442
+ previewZoomButtonTitles: {
4443
+ prev: 'View previous file',
4444
+ next: 'View next file',
4445
+ toggleheader: 'Toggle header',
4446
+ fullscreen: 'Toggle full screen',
4447
+ borderless: 'Toggle borderless mode',
4448
+ close: 'Close detailed preview'
4449
+ }
4450
+ };
4451
+
4452
+ $.fn.fileinput.Constructor = FileInput;
4453
+
4454
+ /**
4455
+ * Convert automatically file inputs with class 'file' into a bootstrap fileinput control.
4456
+ */
4457
+ $(document).ready(function () {
4458
+ var $input = $('input.file[type=file]');
4459
+ if ($input.length) {
4460
+ $input.fileinput();
4461
+ }
4462
+ });
4463
+ }));