angular-dragdrop-rails 1.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 49ff666560c16a5bb4ece0cb026c4777fa10f57c
4
+ data.tar.gz: ebefc97e51951aec470e9963f8e8847739cdc6a2
5
+ SHA512:
6
+ metadata.gz: a1fbca4066c09cde76a303bfcb71264cabf27a7c046d806045541c7870ca494090a96d6c1b9763dbdea7e1b4fd8e42b48dfd4cf9470119f0cf71b71111ed3358
7
+ data.tar.gz: e03487b68ff6110537891bcee0f89637fa978b81c77a57bbe063ccf8328e3086dce8ff11de1e844f6a2fdab79e88ac936cec34575844f63a4d0e3f9811cf730b
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in angular-leaflet-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dariusz Gertych
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # angular-dragdrop-rails
2
+
3
+ [angular-dragdrop](https://github.com/codef0rmer/angular-dragdrop) packaged for Rails assets pipeline.
4
+
5
+ ## Usage
6
+
7
+ Add the following to your gemfile:
8
+
9
+ ```ruby
10
+ gem "angular-dragdrop-rails"
11
+ ```
12
+
13
+ Add the following directive to your Javascript manifest file (application.js):
14
+
15
+ ```js
16
+ //= require angular-dragdrop
17
+ ```
18
+
19
+
20
+ ## Contributing
21
+
22
+ 1. Fork it
23
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
24
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
25
+ 4. Push to the branch (`git push origin my-new-feature`)
26
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Fetch new version from https://github.com/codef0rmer/angular-dragdrop"
4
+ task :fetch do
5
+ source = "https://raw.github.com/codef0rmer/angular-dragdrop/master/src/angular-dragdrop.js"
6
+ target = "vendor/assets/javascripts/angular-dragdrop-original.js"
7
+ sh "curl #{source} > #{target}"
8
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'angular-dragdrop-rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "angular-dragdrop-rails"
8
+ spec.version = AngularDragdrop::Rails::VERSION
9
+ spec.authors = ["Dariusz Gertych"]
10
+ spec.email = ["chytreg@gmail.com"]
11
+ spec.description = %q{angular-dragdrop-directive packaged for Rails assets pipeline}
12
+ spec.summary = %q{angular-dragdrop-directive packaged for Rails assets pipeline}
13
+ spec.homepage = "http://github.com/rails-assets/angular-dragdrop-rails"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "jquery-rails"
22
+ spec.add_dependency "jquery-ui-rails"
23
+ spec.add_dependency "angularjs-rails"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ end
@@ -0,0 +1,12 @@
1
+ require "angular-dragdrop-rails/version"
2
+ require "angularjs-rails"
3
+ require "jquery-rails"
4
+ require "jquery-ui-rails"
5
+
6
+ module AngularDragdrop
7
+ module Rails
8
+ class Engine < ::Rails::Engine
9
+ # Rails -> use vendor directory.
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module AngularDragdrop
2
+ module Rails
3
+ VERSION = "1.0.1"
4
+ end
5
+ end
@@ -0,0 +1,260 @@
1
+ /**
2
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
3
+ * of this software and associated documentation files (the "Software"), to
4
+ * deal in the Software without restriction, including without limitation the
5
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6
+ * sell copies of the Software, and to permit persons to whom the Software is
7
+ * furnished to do so, subject to the following conditions:
8
+ *
9
+ * The above copyright notice and this permission notice shall be included in
10
+ * all copies or substantial portions of the Software.
11
+ *
12
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
18
+ * IN THE SOFTWARE.
19
+ */
20
+
21
+ /**
22
+ * Implementing Drag and Drop functionality in AngularJS is easier than ever.
23
+ * Demo: http://codef0rmer.github.com/angular-dragdrop/
24
+ *
25
+ * @version 1.0.1
26
+ *
27
+ * (c) 2013 Amit Gharat a.k.a codef0rmer <amit.2006.it@gmail.com> - amitgharat.wordpress.com
28
+ */
29
+
30
+ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$timeout', '$parse', function($timeout, $parse) {
31
+ this.callEventCallback = function (scope, callbackName, event, ui) {
32
+ if (!callbackName) {
33
+ return;
34
+ }
35
+ var args = [event, ui];
36
+ var match = callbackName.match(/^(.+)\((.+)\)$/);
37
+ if (match !== null) {
38
+ callbackName = match[1];
39
+ values = eval('[' + match[0].replace(/^(.+)\(/, '').replace(/\)/, '') + ']');
40
+ args.push.apply(args, values);
41
+ }
42
+ scope[callbackName].apply(scope, args);
43
+ };
44
+
45
+ this.invokeDrop = function ($draggable, $droppable, event, ui) {
46
+ var dragModel = '',
47
+ dropModel = '',
48
+ dragSettings = {},
49
+ dropSettings = {},
50
+ jqyoui_pos = null,
51
+ dragItem = {},
52
+ dropItem = {},
53
+ dragModelValue,
54
+ dropModelValue,
55
+ $droppableDraggable = null,
56
+ droppableScope = $droppable.scope(),
57
+ draggableScope = $draggable.scope();
58
+
59
+ dragModel = $draggable.attr('ng-model');
60
+ dropModel = $droppable.attr('ng-model');
61
+ dragModelValue = draggableScope.$eval(dragModel);
62
+ dropModelValue = droppableScope.$eval(dropModel);
63
+
64
+ $droppableDraggable = $droppable.find('[jqyoui-draggable]:last');
65
+ dropSettings = droppableScope.$eval($droppable.attr('jqyoui-droppable')) || [];
66
+ dragSettings = draggableScope.$eval($draggable.attr('jqyoui-draggable')) || [];
67
+
68
+ jqyoui_pos = angular.isArray(dragModelValue) ? dragSettings.index : null;
69
+ dragItem = angular.isArray(dragModelValue) ? dragModelValue[jqyoui_pos] : dragModelValue;
70
+
71
+ if (angular.isArray(dropModelValue) && dropSettings && dropSettings.index !== undefined) {
72
+ dropItem = dropModelValue[dropSettings.index];
73
+ } else if (!angular.isArray(dropModelValue)) {
74
+ dropItem = dropModelValue;
75
+ } else {
76
+ dropItem = {};
77
+ }
78
+
79
+ if (dragSettings.animate === true) {
80
+ this.move($draggable, $droppableDraggable.length > 0 ? $droppableDraggable : $droppable, null, 'fast', dropSettings, null);
81
+ this.move($droppableDraggable.length > 0 && !dropSettings.multiple ? $droppableDraggable : [], $draggable.parent('[jqyoui-droppable]'), jqyoui.startXY, 'fast', dropSettings, function() {
82
+ $timeout(function() {
83
+ // Do not move this into move() to avoid flickering issue
84
+ $draggable.css({'position': 'relative', 'left': '', 'top': ''});
85
+ $droppableDraggable.css({'position': 'relative', 'left': '', 'top': ''});
86
+
87
+ this.mutateDraggable(draggableScope, dropSettings, dragSettings, dragModel, dropModel, dropItem, $draggable);
88
+ this.mutateDroppable(droppableScope, dropSettings, dragSettings, dropModel, dragItem, jqyoui_pos);
89
+ this.callEventCallback(droppableScope, dropSettings.onDrop, event, ui);
90
+ }.bind(this));
91
+ }.bind(this));
92
+ } else {
93
+ $timeout(function() {
94
+ this.mutateDraggable(draggableScope, dropSettings, dragSettings, dragModel, dropModel, dropItem, $draggable);
95
+ this.mutateDroppable(droppableScope, dropSettings, dragSettings, dropModel, dragItem, jqyoui_pos);
96
+ this.callEventCallback(droppableScope, dropSettings.onDrop, event, ui);
97
+ }.bind(this));
98
+ }
99
+ };
100
+
101
+ this.move = function($fromEl, $toEl, toPos, duration, dropSettings, callback) {
102
+ if ($fromEl.length === 0) {
103
+ if (callback) {
104
+ window.setTimeout(function() {
105
+ callback();
106
+ }, 300);
107
+ }
108
+ return false;
109
+ }
110
+
111
+ var zIndex = 9999,
112
+ fromPos = $fromEl.offset(),
113
+ wasVisible = $toEl && $toEl.is(':visible');
114
+
115
+ if (toPos === null && $toEl.length > 0) {
116
+ if ($toEl.attr('jqyoui-draggable') !== undefined && $toEl.attr('ng-model') !== undefined && $toEl.is(':visible') && dropSettings && dropSettings.multiple) {
117
+ toPos = $toEl.offset();
118
+ if (dropSettings.stack === false) {
119
+ toPos.left+= $toEl.outerWidth(true);
120
+ } else {
121
+ toPos.top+= $toEl.outerHeight(true);
122
+ }
123
+ } else {
124
+ toPos = $toEl.css({'visibility': 'hidden', 'display': 'block'}).offset();
125
+ $toEl.css({'visibility': '','display': wasVisible ? '' : 'none'});
126
+ }
127
+ }
128
+
129
+ $fromEl.css({'position': 'absolute', 'z-index': zIndex})
130
+ .css(fromPos)
131
+ .animate(toPos, duration, function() {
132
+ if (callback) callback();
133
+ });
134
+ };
135
+
136
+ this.mutateDroppable = function(scope, dropSettings, dragSettings, dropModel, dragItem, jqyoui_pos) {
137
+ var dropModelValue = scope.$eval(dropModel);
138
+
139
+ scope.__dragItem = dragItem;
140
+
141
+ if (angular.isArray(dropModelValue)) {
142
+ if (dropSettings && dropSettings.index >= 0) {
143
+ dropModelValue[dropSettings.index] = dragItem;
144
+ } else {
145
+ dropModelValue.push(dragItem);
146
+ }
147
+ if (dragSettings && dragSettings.placeholder === true) {
148
+ dropModelValue[dropModelValue.length - 1]['jqyoui_pos'] = jqyoui_pos;
149
+ }
150
+ } else {
151
+ $parse(dropModel + ' = __dragItem')(scope);
152
+ if (dragSettings && dragSettings.placeholder === true) {
153
+ dropModelValue['jqyoui_pos'] = jqyoui_pos;
154
+ }
155
+ }
156
+ };
157
+
158
+ this.mutateDraggable = function(scope, dropSettings, dragSettings, dragModel, dropModel, dropItem, $draggable) {
159
+ var isEmpty = $.isEmptyObject(angular.copy(dropItem)),
160
+ dragModelValue = scope.$eval(dragModel);
161
+
162
+ scope.__dropItem = dropItem;
163
+
164
+ if (dragSettings && dragSettings.placeholder) {
165
+ if (dragSettings.placeholder != 'keep'){
166
+ if (angular.isArray(dragModelValue) && dragSettings.index !== undefined) {
167
+ dragModelValue[dragSettings.index] = dropItem;
168
+ } else {
169
+ $parse(dragModel + ' = __dropItem')(scope);
170
+ }
171
+ }
172
+ } else {
173
+ if (angular.isArray(dragModelValue)) {
174
+ if (isEmpty) {
175
+ if (dragSettings && ( dragSettings.placeholder !== true && dragSettings.placeholder !== 'keep' )) {
176
+ dragModelValue.splice(dragSettings.index, 1);
177
+ }
178
+ } else {
179
+ dragModelValue[dragSettings.index] = dropItem;
180
+ }
181
+ } else {
182
+ // Fix: LIST(object) to LIST(array) - model does not get updated using just scope[dragModel] = {...}
183
+ // P.S.: Could not figure out why it happened
184
+ $parse(dragModel + ' = __dropItem')(scope);
185
+ if (scope.$parent) {
186
+ $parse(dragModel + ' = __dropItem')(scope.$parent);
187
+ }
188
+ }
189
+ }
190
+
191
+ $draggable.css({'z-index': '', 'left': '', 'top': ''});
192
+ };
193
+ }]).directive('jqyouiDraggable', ['ngDragDropService', function(ngDragDropService) {
194
+ return {
195
+ require: '?jqyouiDroppable',
196
+ restrict: 'A',
197
+ link: function(scope, element, attrs) {
198
+ var dragSettings, zIndex;
199
+ var updateDraggable = function(newValue, oldValue) {
200
+ if (newValue) {
201
+ dragSettings = scope.$eval(element.attr('jqyoui-draggable')) || [];
202
+ element
203
+ .draggable({disabled: false})
204
+ .draggable(scope.$eval(attrs.jqyouiOptions) || {})
205
+ .draggable({
206
+ start: function(event, ui) {
207
+ zIndex = $(this).css('z-index');
208
+ $(this).css('z-index', 99999);
209
+ jqyoui.startXY = $(this).offset();
210
+ ngDragDropService.callEventCallback(scope, dragSettings.onStart, event, ui);
211
+ },
212
+ stop: function(event, ui) {
213
+ $(this).css('z-index', zIndex);
214
+ ngDragDropService.callEventCallback(scope, dragSettings.onStop, event, ui);
215
+ },
216
+ drag: function(event, ui) {
217
+ ngDragDropService.callEventCallback(scope, dragSettings.onDrag, event, ui);
218
+ }
219
+ });
220
+ } else {
221
+ element.draggable({disabled: true});
222
+ }
223
+ };
224
+ scope.$watch(function() { return scope.$eval(attrs.drag); }, updateDraggable);
225
+ updateDraggable();
226
+ }
227
+ };
228
+ }]).directive('jqyouiDroppable', ['ngDragDropService', function(ngDragDropService) {
229
+ return {
230
+ restrict: 'A',
231
+ priority: 1,
232
+ link: function(scope, element, attrs) {
233
+ var updateDroppable = function(newValue, oldValue) {
234
+ if (newValue) {
235
+ element
236
+ .droppable({disabled: false})
237
+ .droppable(scope.$eval(attrs.jqyouiOptions) || {})
238
+ .droppable({
239
+ over: function(event, ui) {
240
+ var dropSettings = scope.$eval(angular.element(this).attr('jqyoui-droppable')) || [];
241
+ ngDragDropService.callEventCallback(scope, dropSettings.onOver, event, ui);
242
+ },
243
+ out: function(event, ui) {
244
+ var dropSettings = scope.$eval(angular.element(this).attr('jqyoui-droppable')) || [];
245
+ ngDragDropService.callEventCallback(scope, dropSettings.onOut, event, ui);
246
+ },
247
+ drop: function(event, ui) {
248
+ ngDragDropService.invokeDrop(angular.element(ui.draggable), angular.element(this), event, ui);
249
+ }
250
+ });
251
+ } else {
252
+ element.droppable({disabled: true});
253
+ }
254
+ };
255
+
256
+ scope.$watch(function() { return scope.$eval(attrs.drop); }, updateDroppable);
257
+ updateDroppable();
258
+ }
259
+ };
260
+ }]);
@@ -0,0 +1,3 @@
1
+ //= require angular
2
+ //= require jquery
3
+ //= require angular-dragdrop-original
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: angular-dragdrop-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dariusz Gertych
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jquery-rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jquery-ui-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: angularjs-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: angular-dragdrop-directive packaged for Rails assets pipeline
84
+ email:
85
+ - chytreg@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - angular-dragdrop-rails.gemspec
96
+ - lib/angular-dragdrop-rails.rb
97
+ - lib/angular-dragdrop-rails/version.rb
98
+ - vendor/assets/javascripts/angular-dragdrop-original.js
99
+ - vendor/assets/javascripts/angular-dragdrop.js
100
+ homepage: http://github.com/rails-assets/angular-dragdrop-rails
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.0.0
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: angular-dragdrop-directive packaged for Rails assets pipeline
124
+ test_files: []