slickgrid-requirejs-rails 1.0.0

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 (189) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +5 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/stylesheets/slickgrid-requirejs-rails/application.css +13 -0
  5. data/app/controllers/slickgrid-requirejs-rails/application_controller.rb +4 -0
  6. data/app/helpers/slickgrid-requirejs-rails/application_helper.rb +4 -0
  7. data/app/views/layouts/slickgrid-requirejs-rails/application.html.erb +14 -0
  8. data/config/routes.rb +2 -0
  9. data/lib/slickgrid-requirejs-rails.rb +4 -0
  10. data/lib/slickgrid-requirejs-rails/engine.rb +5 -0
  11. data/lib/slickgrid-requirejs-rails/version.rb +3 -0
  12. data/lib/tasks/slickgrid-requirejs-rails_tasks.rake +35 -0
  13. data/test/dummy/README.rdoc +261 -0
  14. data/test/dummy/Rakefile +7 -0
  15. data/test/dummy/app/assets/javascripts/adapters/jquery-adapter.js +4 -0
  16. data/test/dummy/app/assets/javascripts/application.js.coffee +33 -0
  17. data/test/dummy/app/assets/javascripts/jquery.spreadsheet.js.coffee +105 -0
  18. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  19. data/test/dummy/app/assets/stylesheets/examples.css +4 -0
  20. data/test/dummy/app/controllers/application_controller.rb +3 -0
  21. data/test/dummy/app/controllers/examples_controller.rb +4 -0
  22. data/test/dummy/app/helpers/application_helper.rb +2 -0
  23. data/test/dummy/app/helpers/examples_helper.rb +2 -0
  24. data/test/dummy/app/views/examples/simple.html.erb +7 -0
  25. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  26. data/test/dummy/config.ru +4 -0
  27. data/test/dummy/config/application.rb +60 -0
  28. data/test/dummy/config/boot.rb +10 -0
  29. data/test/dummy/config/database.yml +25 -0
  30. data/test/dummy/config/environment.rb +5 -0
  31. data/test/dummy/config/environments/development.rb +37 -0
  32. data/test/dummy/config/environments/production.rb +67 -0
  33. data/test/dummy/config/environments/test.rb +37 -0
  34. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  35. data/test/dummy/config/initializers/better_errors.rb +1 -0
  36. data/test/dummy/config/initializers/inflections.rb +15 -0
  37. data/test/dummy/config/initializers/mime_types.rb +5 -0
  38. data/test/dummy/config/initializers/secret_token.rb +7 -0
  39. data/test/dummy/config/initializers/session_store.rb +8 -0
  40. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  41. data/test/dummy/config/locales/en.yml +5 -0
  42. data/test/dummy/config/requirejs.yml +13 -0
  43. data/test/dummy/config/routes.rb +8 -0
  44. data/test/dummy/db/development.sqlite3 +0 -0
  45. data/test/dummy/log/development.log +2689 -0
  46. data/test/dummy/public/404.html +26 -0
  47. data/test/dummy/public/422.html +26 -0
  48. data/test/dummy/public/500.html +25 -0
  49. data/test/dummy/public/favicon.ico +0 -0
  50. data/test/dummy/script/rails +6 -0
  51. data/test/dummy/test/functional/examples_controller_test.rb +9 -0
  52. data/test/dummy/test/unit/helpers/examples_helper_test.rb +4 -0
  53. data/test/dummy/tmp/cache/assets/C27/240/sprockets%2Fc8d5e87e720ed4622105328524983048 +0 -0
  54. data/test/dummy/tmp/cache/assets/C42/A50/sprockets%2Fd83155902707b71eb877b3e0208205a0 +0 -0
  55. data/test/dummy/tmp/cache/assets/C80/150/sprockets%2F0d3881005b0646df783d5c24683d34f5 +0 -0
  56. data/test/dummy/tmp/cache/assets/C86/850/sprockets%2F75355848fa7b7065acb91b2634b29085 +0 -0
  57. data/test/dummy/tmp/cache/assets/C94/2C0/sprockets%2Fb5279968d5df8680a33776e0b74a8216 +0 -0
  58. data/test/dummy/tmp/cache/assets/CA9/390/sprockets%2F1891532332d1ff2d2ec0c4884168be24 +0 -0
  59. data/test/dummy/tmp/cache/assets/CB0/3D0/sprockets%2F378c2bc8804c6452508a5905c47b38ca +0 -0
  60. data/test/dummy/tmp/cache/assets/CB4/7D0/sprockets%2F1dc73f77b8d81bbc4a23579054295723 +0 -0
  61. data/test/dummy/tmp/cache/assets/CB7/EB0/sprockets%2F4de19cf2920983cc7502b38a537849a3 +0 -0
  62. data/test/dummy/tmp/cache/assets/CBA/210/sprockets%2F9cb316b6777b84fc332524911d7e645e +0 -0
  63. data/test/dummy/tmp/cache/assets/CBD/8E0/sprockets%2F5b5f989386cc9495a08127dbc42b3615 +0 -0
  64. data/test/dummy/tmp/cache/assets/CCA/480/sprockets%2F6d10d00d7c82276924f3e22e6210fa0b +0 -0
  65. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  66. data/test/dummy/tmp/cache/assets/CDC/260/sprockets%2F6b925351de71c9bd9c021310669dfc70 +0 -0
  67. data/test/dummy/tmp/cache/assets/CDE/090/sprockets%2F15056f2ede4e042d8737f4801fa6b157 +0 -0
  68. data/test/dummy/tmp/cache/assets/CE4/AC0/sprockets%2Fe1db88f51455f23258896cb316e52bc1 +0 -0
  69. data/test/dummy/tmp/cache/assets/CF0/B10/sprockets%2Fb50252ad18b893dc145ef2896e38d689 +0 -0
  70. data/test/dummy/tmp/cache/assets/CF1/750/sprockets%2F8c683caf79c53642dd4e12a89c657355 +0 -0
  71. data/test/dummy/tmp/cache/assets/CF4/130/sprockets%2F2e2ec908b79eb4084c57c7c9632899a2 +0 -0
  72. data/test/dummy/tmp/cache/assets/D01/E90/sprockets%2Ffd358252a8aa0b738f61a75ea81b0134 +0 -0
  73. data/test/dummy/tmp/cache/assets/D09/F30/sprockets%2F330e6425d10d2cb797c3f45ca374b84e +0 -0
  74. data/test/dummy/tmp/cache/assets/D0B/C60/sprockets%2F24182be4c99c8f971c1596aa452a2c0a +0 -0
  75. data/test/dummy/tmp/cache/assets/D1F/5D0/sprockets%2F9dba5447e453628c0bfa9137f85df278 +0 -0
  76. data/test/dummy/tmp/cache/assets/D29/260/sprockets%2F5a18f14fa7a839360315acb05b1e3bf0 +0 -0
  77. data/test/dummy/tmp/cache/assets/D32/230/sprockets%2Fb34e03561a646fac533ce7d4b560c2b8 +0 -0
  78. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  79. data/test/dummy/tmp/cache/assets/D3F/200/sprockets%2F8acb8521e88321b224d6bbf338d398cc +0 -0
  80. data/test/dummy/tmp/cache/assets/D3F/980/sprockets%2F1e2991c760ec4319a1fe5b94bc2ef633 +0 -0
  81. data/test/dummy/tmp/cache/assets/D48/090/sprockets%2F6d95fa4274b968de1d414e21cf46ca85 +0 -0
  82. data/test/dummy/tmp/cache/assets/D4B/4D0/sprockets%2F6205d4779aae40ce1a9a086c46978fef +0 -0
  83. data/test/dummy/tmp/cache/assets/D4E/D00/sprockets%2F1a6846f0a837ae2524e2f9ec89e6ef43 +0 -0
  84. data/test/dummy/tmp/cache/assets/D54/730/sprockets%2F1202c3cd8b0271cc02327e88b0bfad5e +0 -0
  85. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  86. data/test/dummy/tmp/cache/assets/D5D/FF0/sprockets%2F9e1b9c655d94b7725c984f7ce6b8d6b3 +0 -0
  87. data/test/dummy/tmp/cache/assets/D64/0D0/sprockets%2Fbf47d6bc8fc84f8d8764c1f5955f1786 +0 -0
  88. data/test/dummy/tmp/cache/assets/D68/6C0/sprockets%2Fab07dab58b519282aeaf3ea945f46513 +0 -0
  89. data/test/dummy/tmp/cache/assets/D6A/EF0/sprockets%2F2eb65cc490ad96cc38604918b0caeb90 +0 -0
  90. data/test/dummy/tmp/cache/assets/D71/9A0/sprockets%2F8fe2ebb722d62d1fdd63068c57a6408d +0 -0
  91. data/test/dummy/tmp/cache/assets/D77/210/sprockets%2F6586fb2ab2cc992e642e53e4cc3e2e85 +0 -0
  92. data/test/dummy/tmp/cache/assets/D84/460/sprockets%2Fed41cc36973e3e16cce4f876be7297b8 +0 -0
  93. data/test/dummy/tmp/cache/assets/D86/600/sprockets%2Ff9be8df0f5835948b646a94b47cd23cf +0 -0
  94. data/test/dummy/tmp/cache/assets/D95/530/sprockets%2F0cbcab75dec40d0e637629a484beb653 +0 -0
  95. data/test/dummy/tmp/cache/assets/D98/070/sprockets%2F4c95e212d3de047f6ac4f2fe09c40de2 +0 -0
  96. data/test/dummy/tmp/cache/assets/D98/270/sprockets%2F0e7c025e3de60b80a6c5e5fcc7db6832 +0 -0
  97. data/test/dummy/tmp/cache/assets/D9C/520/sprockets%2Ffc5383ee26303f5906ad273a3fe5dcea +0 -0
  98. data/test/dummy/tmp/cache/assets/D9F/9B0/sprockets%2Ff4b8b3465acc5f71633cf0af5858c4ac +0 -0
  99. data/test/dummy/tmp/cache/assets/DA1/EB0/sprockets%2F2d2f2f5ed3c476dea3c3a3d9e2980a85 +0 -0
  100. data/test/dummy/tmp/cache/assets/DA2/890/sprockets%2F1fd7028cdd4ff7c24e4a630c1f38af88 +0 -0
  101. data/test/dummy/tmp/cache/assets/DA3/080/sprockets%2Ffb77a66783db0b5812e3fdbabe4608f6 +0 -0
  102. data/test/dummy/tmp/cache/assets/DB2/E50/sprockets%2Ff337be9ae1863f27a87c882feae9ee21 +0 -0
  103. data/test/dummy/tmp/cache/assets/DC1/E70/sprockets%2F827c6100c3adc3c91ddfe84da51fbd15 +0 -0
  104. data/test/dummy/tmp/cache/assets/DCA/380/sprockets%2Fc0ccdcba1aa3b504045ebb1b2400b9d0 +0 -0
  105. data/test/dummy/tmp/cache/assets/DCA/EA0/sprockets%2F139ab8cdba6b44b58ae3647dbeea8145 +0 -0
  106. data/test/dummy/tmp/cache/assets/DEF/8E0/sprockets%2F3b4c400d4a5c7db0cd8d02b7e3cb79df +0 -0
  107. data/test/dummy/tmp/cache/assets/E0C/530/sprockets%2F0ce78cd1a399cdb66ca6cd2f93e93f8b +0 -0
  108. data/test/dummy/tmp/cache/assets/E11/4E0/sprockets%2F86e145a39f85cceeaffdff91ebb61449 +0 -0
  109. data/test/dummy/tmp/cache/assets/E15/B80/sprockets%2F68eff298c6dad0b39ddf0d61ccd9896d +0 -0
  110. data/test/dummy/tmp/cache/assets/E22/130/sprockets%2Fbeaa50ffc31b2c6a5625ce1a85efc38e +0 -0
  111. data/test/dummy/tmp/cache/assets/E2D/B60/sprockets%2F5aa2b493bf9c5b69eafecd96aa0af066 +0 -0
  112. data/test/dummy/tmp/cache/assets/E38/8F0/sprockets%2F1cb65daaffa8b6d886108e4eaf6d9bb9 +0 -0
  113. data/test/dummy/tmp/cache/assets/E66/810/sprockets%2F5de7ae60bfff07ae5fd98d19d9b1a4da +0 -0
  114. data/test/dummy/tmp/cache/sass/a27500b667404a158ab7c09449b801b001e64ed8/all.css.scssc +0 -0
  115. data/test/dummy/tmp/cache/sass/a27500b667404a158ab7c09449b801b001e64ed8/default-theme.css.scssc +0 -0
  116. data/test/dummy/tmp/cache/sass/a27500b667404a158ab7c09449b801b001e64ed8/editors.css.scssc +0 -0
  117. data/test/dummy/tmp/cache/sass/a27500b667404a158ab7c09449b801b001e64ed8/grid.css.scssc +0 -0
  118. data/test/integration/navigation_test.rb +10 -0
  119. data/test/slickgrid-requirejs-rails_test.rb +7 -0
  120. data/test/test_helper.rb +15 -0
  121. data/vendor/assets/images/slick/actions.gif +0 -0
  122. data/vendor/assets/images/slick/ajax-loader-small.gif +0 -0
  123. data/vendor/assets/images/slick/arrow_redo.png +0 -0
  124. data/vendor/assets/images/slick/arrow_right_peppermint.png +0 -0
  125. data/vendor/assets/images/slick/arrow_right_spearmint.png +0 -0
  126. data/vendor/assets/images/slick/arrow_undo.png +0 -0
  127. data/vendor/assets/images/slick/bullet_blue.png +0 -0
  128. data/vendor/assets/images/slick/bullet_star.png +0 -0
  129. data/vendor/assets/images/slick/bullet_toggle_minus.png +0 -0
  130. data/vendor/assets/images/slick/bullet_toggle_plus.png +0 -0
  131. data/vendor/assets/images/slick/calendar.gif +0 -0
  132. data/vendor/assets/images/slick/collapse.gif +0 -0
  133. data/vendor/assets/images/slick/comment_yellow.gif +0 -0
  134. data/vendor/assets/images/slick/down.gif +0 -0
  135. data/vendor/assets/images/slick/drag-handle.png +0 -0
  136. data/vendor/assets/images/slick/editor-helper-bg.gif +0 -0
  137. data/vendor/assets/images/slick/expand.gif +0 -0
  138. data/vendor/assets/images/slick/header-bg.gif +0 -0
  139. data/vendor/assets/images/slick/header-columns-bg.gif +0 -0
  140. data/vendor/assets/images/slick/header-columns-over-bg.gif +0 -0
  141. data/vendor/assets/images/slick/help.png +0 -0
  142. data/vendor/assets/images/slick/info.gif +0 -0
  143. data/vendor/assets/images/slick/listview.gif +0 -0
  144. data/vendor/assets/images/slick/pencil.gif +0 -0
  145. data/vendor/assets/images/slick/row-over-bg.gif +0 -0
  146. data/vendor/assets/images/slick/sort-asc.gif +0 -0
  147. data/vendor/assets/images/slick/sort-asc.png +0 -0
  148. data/vendor/assets/images/slick/sort-desc.gif +0 -0
  149. data/vendor/assets/images/slick/sort-desc.png +0 -0
  150. data/vendor/assets/images/slick/stripes.png +0 -0
  151. data/vendor/assets/images/slick/tag_red.png +0 -0
  152. data/vendor/assets/images/slick/tick.png +0 -0
  153. data/vendor/assets/images/slick/user_identity.gif +0 -0
  154. data/vendor/assets/images/slick/user_identity_plus.gif +0 -0
  155. data/vendor/assets/javascripts/jquery.event/drag.js +407 -0
  156. data/vendor/assets/javascripts/jquery.event/drop.js +303 -0
  157. data/vendor/assets/javascripts/slick/controls/slick.columnpicker.js +157 -0
  158. data/vendor/assets/javascripts/slick/controls/slick.pager.js +158 -0
  159. data/vendor/assets/javascripts/slick/plugins/slick.autotooltips.js +88 -0
  160. data/vendor/assets/javascripts/slick/plugins/slick.cellcopymanager.js +93 -0
  161. data/vendor/assets/javascripts/slick/plugins/slick.cellrangedecorator.js +69 -0
  162. data/vendor/assets/javascripts/slick/plugins/slick.cellrangeselector.js +118 -0
  163. data/vendor/assets/javascripts/slick/plugins/slick.cellselectionmodel.js +160 -0
  164. data/vendor/assets/javascripts/slick/plugins/slick.checkboxselectcolumn.js +158 -0
  165. data/vendor/assets/javascripts/slick/plugins/slick.headerbuttons.js +181 -0
  166. data/vendor/assets/javascripts/slick/plugins/slick.headermenu.js +278 -0
  167. data/vendor/assets/javascripts/slick/plugins/slick.rowmovemanager.js +144 -0
  168. data/vendor/assets/javascripts/slick/plugins/slick.rowselectionmodel.js +193 -0
  169. data/vendor/assets/javascripts/slick/slick.core.js +468 -0
  170. data/vendor/assets/javascripts/slick/slick.dataview.aggregators.js +121 -0
  171. data/vendor/assets/javascripts/slick/slick.dataview.js +1061 -0
  172. data/vendor/assets/javascripts/slick/slick.editors.js +517 -0
  173. data/vendor/assets/javascripts/slick/slick.formatters.js +65 -0
  174. data/vendor/assets/javascripts/slick/slick.grid.js +3317 -0
  175. data/vendor/assets/javascripts/slick/slick.groupitemmetadataprovider.js +149 -0
  176. data/vendor/assets/javascripts/slick/slick.remotemodel.js +185 -0
  177. data/vendor/assets/stylesheets/slick/all.css.scss +3 -0
  178. data/vendor/assets/stylesheets/slick/controls/columnpicker.css.scss +30 -0
  179. data/vendor/assets/stylesheets/slick/controls/pager.css.scss +41 -0
  180. data/vendor/assets/stylesheets/slick/controls/slick.columnpicker.css +31 -0
  181. data/vendor/assets/stylesheets/slick/controls/slick.pager.css +41 -0
  182. data/vendor/assets/stylesheets/slick/default-theme.css.scss +104 -0
  183. data/vendor/assets/stylesheets/slick/editors.css.scss +100 -0
  184. data/vendor/assets/stylesheets/slick/grid.css.scss +174 -0
  185. data/vendor/assets/stylesheets/slick/plugins/slick.headerbuttons.css +39 -0
  186. data/vendor/assets/stylesheets/slick/plugins/slick.headermenu.css +59 -0
  187. data/vendor/assets/stylesheets/slick/remotemodel.css.scss +20 -0
  188. data/vendor/assets/stylesheets/slick/slick.grid.css +157 -0
  189. metadata +524 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class ExamplesControllerTest < ActionController::TestCase
4
+ test "should get simple" do
5
+ get :simple
6
+ assert_response :success
7
+ end
8
+
9
+ end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class ExamplesHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class NavigationTest < ActionDispatch::IntegrationTest
4
+ fixtures :all
5
+
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class SlickgridRequirejsRailsTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, SlickgridRequirejsRails
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
+
12
+ # Load fixtures from the engine
13
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
14
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
15
+ end
@@ -0,0 +1,407 @@
1
+ /*!
2
+ * jquery.event.drag - v 2.2
3
+ * Copyright (c) 2010 Three Dub Media - http://threedubmedia.com
4
+ * Open Source MIT License - http://threedubmedia.com/code/license
5
+ */
6
+ // Created: 2008-06-04
7
+ // Updated: 2012-05-21
8
+ // REQUIRES: jquery 1.7.x
9
+
10
+ define(['jquery'], function ($) {
11
+
12
+
13
+
14
+ // add the jquery instance method
15
+ $.fn.drag = function (str, arg, opts) {
16
+ // figure out the event type
17
+ var type = typeof str == "string" ? str : "",
18
+ // figure out the event handler...
19
+ fn = $.isFunction(str) ? str : $.isFunction(arg) ? arg : null;
20
+ // fix the event type
21
+ if (type.indexOf("drag") !== 0)
22
+ type = "drag" + type;
23
+ // were options passed
24
+ opts = ( str == fn ? arg : opts ) || {};
25
+ // trigger or bind event handler
26
+ return fn ? this.bind(type, opts, fn) : this.trigger(type);
27
+ };
28
+
29
+ // local refs (increase compression)
30
+ var $event = $.event,
31
+ $special = $event.special,
32
+ // configure the drag special event
33
+ drag = $special.drag = {
34
+
35
+ // these are the default settings
36
+ defaults: {
37
+ which: 1, // mouse button pressed to start drag sequence
38
+ distance: 0, // distance dragged before dragstart
39
+ not: ':input', // selector to suppress dragging on target elements
40
+ handle: null, // selector to match handle target elements
41
+ relative: false, // true to use "position", false to use "offset"
42
+ drop: true, // false to suppress drop events, true or selector to allow
43
+ click: false // false to suppress click events after dragend (no proxy)
44
+ },
45
+
46
+ // the key name for stored drag data
47
+ datakey: "dragdata",
48
+
49
+ // prevent bubbling for better performance
50
+ noBubble: true,
51
+
52
+ // count bound related events
53
+ add: function (obj) {
54
+ // read the interaction data
55
+ var data = $.data(this, drag.datakey),
56
+ // read any passed options
57
+ opts = obj.data || {};
58
+ // count another realted event
59
+ data.related += 1;
60
+ // extend data options bound with this event
61
+ // don't iterate "opts" in case it is a node
62
+ $.each(drag.defaults, function (key, def) {
63
+ if (opts[ key ] !== undefined)
64
+ data[ key ] = opts[ key ];
65
+ });
66
+ },
67
+
68
+ // forget unbound related events
69
+ remove: function () {
70
+ $.data(this, drag.datakey).related -= 1;
71
+ },
72
+
73
+ // configure interaction, capture settings
74
+ setup: function () {
75
+ // check for related events
76
+ if ($.data(this, drag.datakey))
77
+ return;
78
+ // initialize the drag data with copied defaults
79
+ var data = $.extend({ related: 0 }, drag.defaults);
80
+ // store the interaction data
81
+ $.data(this, drag.datakey, data);
82
+ // bind the mousedown event, which starts drag interactions
83
+ $event.add(this, "touchstart mousedown", drag.init, data);
84
+ // prevent image dragging in IE...
85
+ if (this.attachEvent)
86
+ this.attachEvent("ondragstart", drag.dontstart);
87
+ },
88
+
89
+ // destroy configured interaction
90
+ teardown: function () {
91
+ var data = $.data(this, drag.datakey) || {};
92
+ // check for related events
93
+ if (data.related)
94
+ return;
95
+ // remove the stored data
96
+ $.removeData(this, drag.datakey);
97
+ // remove the mousedown event
98
+ $event.remove(this, "touchstart mousedown", drag.init);
99
+ // enable text selection
100
+ drag.textselect(true);
101
+ // un-prevent image dragging in IE...
102
+ if (this.detachEvent)
103
+ this.detachEvent("ondragstart", drag.dontstart);
104
+ },
105
+
106
+ // initialize the interaction
107
+ init: function (event) {
108
+ // sorry, only one touch at a time
109
+ if (drag.touched)
110
+ return;
111
+ // the drag/drop interaction data
112
+ var dd = event.data, results;
113
+ // check the which directive
114
+ if (event.which != 0 && dd.which > 0 && event.which != dd.which)
115
+ return;
116
+ // check for suppressed selector
117
+ if ($(event.target).is(dd.not))
118
+ return;
119
+ // check for handle selector
120
+ if (dd.handle && !$(event.target).closest(dd.handle, event.currentTarget).length)
121
+ return;
122
+
123
+ drag.touched = event.type == 'touchstart' ? this : null;
124
+ dd.propagates = 1;
125
+ dd.mousedown = this;
126
+ dd.interactions = [ drag.interaction(this, dd) ];
127
+ dd.target = event.target;
128
+ dd.pageX = event.pageX;
129
+ dd.pageY = event.pageY;
130
+ dd.dragging = null;
131
+ // handle draginit event...
132
+ results = drag.hijack(event, "draginit", dd);
133
+ // early cancel
134
+ if (!dd.propagates)
135
+ return;
136
+ // flatten the result set
137
+ results = drag.flatten(results);
138
+ // insert new interaction elements
139
+ if (results && results.length) {
140
+ dd.interactions = [];
141
+ $.each(results, function () {
142
+ dd.interactions.push(drag.interaction(this, dd));
143
+ });
144
+ }
145
+ // remember how many interactions are propagating
146
+ dd.propagates = dd.interactions.length;
147
+ // locate and init the drop targets
148
+ if (dd.drop !== false && $special.drop)
149
+ $special.drop.handler(event, dd);
150
+ // disable text selection
151
+ drag.textselect(false);
152
+ // bind additional events...
153
+ if (drag.touched)
154
+ $event.add(drag.touched, "touchmove touchend", drag.handler, dd);
155
+ else
156
+ $event.add(document, "mousemove mouseup", drag.handler, dd);
157
+ // helps prevent text selection or scrolling
158
+ if (!drag.touched || dd.live)
159
+ return false;
160
+ },
161
+
162
+ // returns an interaction object
163
+ interaction: function (elem, dd) {
164
+ var offset = $(elem)[ dd.relative ? "position" : "offset" ]() || { top: 0, left: 0 };
165
+ return {
166
+ drag: elem,
167
+ callback: new drag.callback(),
168
+ droppable: [],
169
+ offset: offset
170
+ };
171
+ },
172
+
173
+ // handle drag-releatd DOM events
174
+ handler: function (event) {
175
+ // read the data before hijacking anything
176
+ var dd = event.data;
177
+ // handle various events
178
+ switch (event.type) {
179
+ // mousemove, check distance, start dragging
180
+ case !dd.dragging && 'touchmove':
181
+ event.preventDefault();
182
+ case !dd.dragging && 'mousemove':
183
+ // drag tolerance, x≤ + y≤ = distance≤
184
+ if (Math.pow(event.pageX - dd.pageX, 2) + Math.pow(event.pageY - dd.pageY, 2) < Math.pow(dd.distance, 2))
185
+ break; // distance tolerance not reached
186
+ event.target = dd.target; // force target from "mousedown" event (fix distance issue)
187
+ drag.hijack(event, "dragstart", dd); // trigger "dragstart"
188
+ if (dd.propagates) // "dragstart" not rejected
189
+ dd.dragging = true; // activate interaction
190
+ // mousemove, dragging
191
+ case 'touchmove':
192
+ event.preventDefault();
193
+ case 'mousemove':
194
+ if (dd.dragging) {
195
+ // trigger "drag"
196
+ drag.hijack(event, "drag", dd);
197
+ if (dd.propagates) {
198
+ // manage drop events
199
+ if (dd.drop !== false && $special.drop)
200
+ $special.drop.handler(event, dd); // "dropstart", "dropend"
201
+ break; // "drag" not rejected, stop
202
+ }
203
+ event.type = "mouseup"; // helps "drop" handler behave
204
+ }
205
+ // mouseup, stop dragging
206
+ case 'touchend':
207
+ case 'mouseup':
208
+ default:
209
+ if (drag.touched)
210
+ $event.remove(drag.touched, "touchmove touchend", drag.handler); // remove touch events
211
+ else
212
+ $event.remove(document, "mousemove mouseup", drag.handler); // remove page events
213
+ if (dd.dragging) {
214
+ if (dd.drop !== false && $special.drop)
215
+ $special.drop.handler(event, dd); // "drop"
216
+ drag.hijack(event, "dragend", dd); // trigger "dragend"
217
+ }
218
+ drag.textselect(true); // enable text selection
219
+ // if suppressing click events...
220
+ if (dd.click === false && dd.dragging)
221
+ $.data(dd.mousedown, "suppress.click", new Date().getTime() + 5);
222
+ dd.dragging = drag.touched = false; // deactivate element
223
+ break;
224
+ }
225
+ },
226
+
227
+ // re-use event object for custom events
228
+ hijack: function (event, type, dd, x, elem) {
229
+ // not configured
230
+ if (!dd)
231
+ return;
232
+ // remember the original event and type
233
+ var orig = { event: event.originalEvent, type: event.type },
234
+ // is the event drag related or drog related?
235
+ mode = type.indexOf("drop") ? "drag" : "drop",
236
+ // iteration vars
237
+ result, i = x || 0, ia, $elems, callback,
238
+ len = !isNaN(x) ? x : dd.interactions.length;
239
+ // modify the event type
240
+ event.type = type;
241
+ // remove the original event
242
+ event.originalEvent = null;
243
+ // initialize the results
244
+ dd.results = [];
245
+ // handle each interacted element
246
+ do if (ia = dd.interactions[ i ]) {
247
+ // validate the interaction
248
+ if (type !== "dragend" && ia.cancelled)
249
+ continue;
250
+ // set the dragdrop properties on the event object
251
+ callback = drag.properties(event, dd, ia);
252
+ // prepare for more results
253
+ ia.results = [];
254
+ // handle each element
255
+ $(elem || ia[ mode ] || dd.droppable).each(function (p, subject) {
256
+ // identify drag or drop targets individually
257
+ callback.target = subject;
258
+ // force propagtion of the custom event
259
+ event.isPropagationStopped = function () {
260
+ return false;
261
+ };
262
+ // handle the event
263
+ result = subject ? $event.dispatch.call(subject, event, callback) : null;
264
+ // stop the drag interaction for this element
265
+ if (result === false) {
266
+ if (mode == "drag") {
267
+ ia.cancelled = true;
268
+ dd.propagates -= 1;
269
+ }
270
+ if (type == "drop") {
271
+ ia[ mode ][p] = null;
272
+ }
273
+ }
274
+ // assign any dropinit elements
275
+ else if (type == "dropinit")
276
+ ia.droppable.push(drag.element(result) || subject);
277
+ // accept a returned proxy element
278
+ if (type == "dragstart")
279
+ ia.proxy = $(drag.element(result) || ia.drag)[0];
280
+ // remember this result
281
+ ia.results.push(result);
282
+ // forget the event result, for recycling
283
+ delete event.result;
284
+ // break on cancelled handler
285
+ if (type !== "dropinit")
286
+ return result;
287
+ });
288
+ // flatten the results
289
+ dd.results[ i ] = drag.flatten(ia.results);
290
+ // accept a set of valid drop targets
291
+ if (type == "dropinit")
292
+ ia.droppable = drag.flatten(ia.droppable);
293
+ // locate drop targets
294
+ if (type == "dragstart" && !ia.cancelled)
295
+ callback.update();
296
+ }
297
+ while (++i < len)
298
+ // restore the original event & type
299
+ event.type = orig.type;
300
+ event.originalEvent = orig.event;
301
+ // return all handler results
302
+ return drag.flatten(dd.results);
303
+ },
304
+
305
+ // extend the callback object with drag/drop properties...
306
+ properties: function (event, dd, ia) {
307
+ var obj = ia.callback;
308
+ // elements
309
+ obj.drag = ia.drag;
310
+ obj.proxy = ia.proxy || ia.drag;
311
+ // starting mouse position
312
+ obj.startX = dd.pageX;
313
+ obj.startY = dd.pageY;
314
+ // current distance dragged
315
+ obj.deltaX = event.pageX - dd.pageX;
316
+ obj.deltaY = event.pageY - dd.pageY;
317
+ // original element position
318
+ obj.originalX = ia.offset.left;
319
+ obj.originalY = ia.offset.top;
320
+ // adjusted element position
321
+ obj.offsetX = obj.originalX + obj.deltaX;
322
+ obj.offsetY = obj.originalY + obj.deltaY;
323
+ // assign the drop targets information
324
+ obj.drop = drag.flatten(( ia.drop || [] ).slice());
325
+ obj.available = drag.flatten(( ia.droppable || [] ).slice());
326
+ return obj;
327
+ },
328
+
329
+ // determine is the argument is an element or jquery instance
330
+ element: function (arg) {
331
+ if (arg && ( arg.jquery || arg.nodeType == 1 ))
332
+ return arg;
333
+ },
334
+
335
+ // flatten nested jquery objects and arrays into a single dimension array
336
+ flatten: function (arr) {
337
+ return $.map(arr, function (member) {
338
+ return member && member.jquery ? $.makeArray(member) :
339
+ member && member.length ? drag.flatten(member) : member;
340
+ });
341
+ },
342
+
343
+ // toggles text selection attributes ON (true) or OFF (false)
344
+ textselect: function (bool) {
345
+ $(document)[ bool ? "unbind" : "bind" ]("selectstart", drag.dontstart)
346
+ .css("MozUserSelect", bool ? "" : "none");
347
+ // .attr("unselectable", bool ? "off" : "on" )
348
+ document.unselectable = bool ? "off" : "on";
349
+ },
350
+
351
+ // suppress "selectstart" and "ondragstart" events
352
+ dontstart: function () {
353
+ return false;
354
+ },
355
+
356
+ // a callback instance contructor
357
+ callback: function () {
358
+ }
359
+
360
+ };
361
+
362
+ // callback methods
363
+ drag.callback.prototype = {
364
+ update: function () {
365
+ if ($special.drop && this.available.length)
366
+ $.each(this.available, function (i) {
367
+ $special.drop.locate(this, i);
368
+ });
369
+ }
370
+ };
371
+
372
+ // patch $.event.$dispatch to allow suppressing clicks
373
+ var $dispatch = $event.dispatch;
374
+ $event.dispatch = function (event) {
375
+ if ($.data(this, "suppress." + event.type) - new Date().getTime() > 0) {
376
+ $.removeData(this, "suppress." + event.type);
377
+ return;
378
+ }
379
+ return $dispatch.apply(this, arguments);
380
+ };
381
+
382
+ // event fix hooks for touch events...
383
+ var touchHooks =
384
+ $event.fixHooks.touchstart =
385
+ $event.fixHooks.touchmove =
386
+ $event.fixHooks.touchend =
387
+ $event.fixHooks.touchcancel = {
388
+ props: "clientX clientY pageX pageY screenX screenY".split(" "),
389
+ filter: function (event, orig) {
390
+ if (orig) {
391
+ var touched = ( orig.touches && orig.touches[0] )
392
+ || ( orig.changedTouches && orig.changedTouches[0] )
393
+ || null;
394
+ // iOS webkit: touchstart, touchmove, touchend
395
+ if (touched)
396
+ $.each(touchHooks.props, function (i, prop) {
397
+ event[ prop ] = touched[ prop ];
398
+ });
399
+ }
400
+ return event;
401
+ }
402
+ };
403
+
404
+ // share the same special event configuration with related events...
405
+ $special.draginit = $special.dragstart = $special.dragend = drag;
406
+
407
+ });