angular-ujs 0.4.6 → 0.4.7
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 +4 -4
- data/README.md +1 -1
- data/package.json +4 -2
- data/vendor/assets/javascripts/angular-ujs.js +90 -100
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9014c8edfa2d4616d44cbbb6fdcdba1976162af
|
4
|
+
data.tar.gz: 632a69340d981c4608cfe98caed708efb0c889c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76085a5211cac4a39f5a355825bb85d2ded9cf54af6c7d8d737b84ecff11d6348db80ee04e13396dd810917c6cfa9362d6e6f6c3ed8ee03e5bd660206cfc8d46
|
7
|
+
data.tar.gz: 29e42cb163e97b4069bb56aa88e4c83018802d648de91850ee6343bb9207d26f2ee805b04d159dcd48b97f8983f2c610e5d548eafba208c73199a19b99039ee4
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# angular-ujs
|
2
2
|
|
3
|
-
[](http://badge.fury.io/rb/angular-ujs) [](http://badge.fury.io/js/angular-ujs) [](http://travis-ci.org/tomchentw/angular-ujs) [](https://codeclimate.com/github/tomchentw/angular-ujs) [](https://gemnasium.com/tomchentw/angular-ujs)
|
3
|
+
[](http://badge.fury.io/rb/angular-ujs) [](http://badge.fury.io/js/angular-ujs) [](http://travis-ci.org/tomchentw/angular-ujs) [](https://coveralls.io/r/tomchentw/angular-ujs?branch=master) [](https://codeclimate.com/github/tomchentw/angular-ujs) [](https://gemnasium.com/tomchentw/angular-ujs)
|
4
4
|
|
5
5
|
|
6
6
|
## Project philosophy
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "angular-ujs",
|
3
|
-
"version": "0.4.
|
3
|
+
"version": "0.4.7",
|
4
4
|
"description": "Unobtrusive scripting for AngularJS ( without jQuery dependency )",
|
5
5
|
"longDescription": "Ruby on Rails replacement for unobtrusive scripting library `jquery_ujs` implemented in AngularJS without jQuery dependency",
|
6
6
|
"main": "angular-ujs.js",
|
@@ -51,6 +51,8 @@
|
|
51
51
|
"karma-firefox-launcher": "~0.1.3",
|
52
52
|
"karma-jasmine": "~0.1.5",
|
53
53
|
"karma-phantomjs-launcher": "~0.1.1",
|
54
|
-
"karma": "~0.
|
54
|
+
"karma-coverage": "~0.1.4",
|
55
|
+
"karma": "~0.10.9",
|
56
|
+
"coveralls": "~2.6.1"
|
55
57
|
}
|
56
58
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/*! angular-ujs - v 0.4.
|
1
|
+
/*! angular-ujs - v 0.4.7 - Sat Jan 25 2014 23:06:35 GMT+0800 (CST)
|
2
2
|
* https://github.com/tomchentw/angular-ujs
|
3
3
|
* Copyright (c) 2014 [tomchentw](https://github.com/tomchentw/);
|
4
4
|
* Licensed [MIT](http://tomchentw.mit-license.org/)
|
@@ -10,75 +10,37 @@
|
|
10
10
|
event.preventDefault();
|
11
11
|
event.stopPropagation();
|
12
12
|
};
|
13
|
-
angular.module('angular.ujs', []).
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
var metas, i$, ref$, len$, meta;
|
25
|
-
metas = {};
|
26
|
-
for (i$ = 0, len$ = (ref$ = $document[0].querySelectorAll('meta[name^="csrf-"]')).length; i$ < len$; ++i$) {
|
27
|
-
meta = ref$[i$];
|
28
|
-
meta = angular.element(meta);
|
29
|
-
metas[meta.attr('name')] = meta.attr('content');
|
30
|
-
}
|
31
|
-
return metas;
|
32
|
-
};
|
33
|
-
}));
|
13
|
+
angular.module('angular.ujs', []).factory('$getRailsCSRF', ['$document'].concat(function($document){
|
14
|
+
return function(){
|
15
|
+
var metas, i$, ref$, len$, meta;
|
16
|
+
metas = {};
|
17
|
+
for (i$ = 0, len$ = (ref$ = $document[0].querySelectorAll('meta[name^="csrf-"]')).length; i$ < len$; ++i$) {
|
18
|
+
meta = ref$[i$];
|
19
|
+
meta = angular.element(meta);
|
20
|
+
metas[meta.attr('name')] = meta.attr('content');
|
21
|
+
}
|
22
|
+
return metas;
|
23
|
+
};
|
34
24
|
})).controller('noopRailsConfirmCtrl', function(){
|
35
25
|
this.allowAction = function(){
|
36
26
|
return true;
|
37
27
|
};
|
38
28
|
this.denyDefaultAction = denyDefaultAction;
|
39
|
-
}).controller('
|
40
|
-
this.
|
41
|
-
$form[0].submit();
|
42
|
-
return {
|
43
|
-
then: angular.noop
|
44
|
-
};
|
45
|
-
};
|
46
|
-
}).controller('RailsConfirmCtrl', ['$window'].concat(function($window){
|
47
|
-
this.allowAction = function($attrs){
|
29
|
+
}).controller('RailsConfirmCtrl', ['$window', '$attrs'].concat(function($window, $attrs){
|
30
|
+
this.allowAction = function(){
|
48
31
|
var message;
|
49
32
|
message = $attrs.confirm;
|
50
33
|
return angular.isDefined(message) && $window.confirm(message);
|
51
34
|
};
|
52
35
|
this.denyDefaultAction = denyDefaultAction;
|
53
|
-
})).
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
onClickHandler = function(event){
|
59
|
-
if (!confirmCtrl.allowAction($attrs)) {
|
60
|
-
confirmCtrl.denyDefaultAction(event);
|
61
|
-
}
|
36
|
+
})).controller('noopRailsRemoteFormCtrl', function(){
|
37
|
+
this.submit = function($form){
|
38
|
+
$form[0].submit();
|
39
|
+
return {
|
40
|
+
then: angular.noop
|
62
41
|
};
|
63
|
-
$element.on('click', onClickHandler);
|
64
|
-
$scope.$on('$destroy', function(){
|
65
|
-
$element.off('click', onClickHandler);
|
66
|
-
});
|
67
|
-
};
|
68
|
-
return {
|
69
|
-
restrict: 'A',
|
70
|
-
require: ['confirm'],
|
71
|
-
controller: 'RailsConfirmCtrl',
|
72
|
-
compile: function(tElement, tAttrs){
|
73
|
-
var $attr;
|
74
|
-
$attr = tAttrs.$attr;
|
75
|
-
if ($attr.confirm !== 'data-confirm' || $attr.remote === 'data-remote' || $attr.method === 'data-method') {
|
76
|
-
return;
|
77
|
-
}
|
78
|
-
return postLinkFn;
|
79
|
-
}
|
80
42
|
};
|
81
|
-
}).controller('RailsRemoteFormCtrl', ['$scope', '$parse', '$http'].concat(function($scope, $parse, $http){
|
43
|
+
}).controller('RailsRemoteFormCtrl', ['$scope', '$attrs', '$parse', '$http'].concat(function($scope, $attrs, $parse, $http){
|
82
44
|
var successCallback, errorCallback;
|
83
45
|
successCallback = function(response){
|
84
46
|
$scope.$emit('rails:remote:success', response);
|
@@ -86,9 +48,10 @@
|
|
86
48
|
errorCallback = function(response){
|
87
49
|
$scope.$emit('rails:remote:error', response);
|
88
50
|
};
|
89
|
-
this.submit = function($form
|
90
|
-
var targetScope, data, key, value, config, METHOD, own$ = {}.hasOwnProperty;
|
51
|
+
this.submit = function($form){
|
52
|
+
var targetScope, modelName, data, key, value, config, METHOD, own$ = {}.hasOwnProperty;
|
91
53
|
targetScope = $form.scope();
|
54
|
+
modelName = $attrs.remote;
|
92
55
|
data = {};
|
93
56
|
if (modelName + "" !== 'true') {
|
94
57
|
$parse(modelName).assign(data, targetScope.$eval(modelName));
|
@@ -114,25 +77,51 @@
|
|
114
77
|
}
|
115
78
|
return $http(config).then(successCallback, errorCallback);
|
116
79
|
};
|
117
|
-
})).directive('
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
80
|
+
})).directive('confirm', function(){
|
81
|
+
function onClickHandler(event){
|
82
|
+
if (!this.allowAction()) {
|
83
|
+
this.denyDefaultAction(event);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
function postLinkFn($scope, $element, $attrs, $ctrls){
|
87
|
+
var callback;
|
88
|
+
callback = angular.bind($ctrls[0], onClickHandler);
|
89
|
+
$element.on('click', callback);
|
90
|
+
$scope.$on('$destroy', function(){
|
91
|
+
$element.off('click', callback);
|
123
92
|
});
|
124
|
-
|
125
|
-
|
126
|
-
|
93
|
+
}
|
94
|
+
return {
|
95
|
+
restrict: 'A',
|
96
|
+
require: ['confirm'],
|
97
|
+
controller: 'RailsConfirmCtrl',
|
98
|
+
compile: function(tElement, tAttrs){
|
99
|
+
var $attr;
|
100
|
+
$attr = tAttrs.$attr;
|
101
|
+
if ($attr.confirm !== 'data-confirm' || $attr.remote === 'data-remote' || $attr.method === 'data-method') {
|
127
102
|
return;
|
128
103
|
}
|
129
|
-
|
130
|
-
}
|
131
|
-
|
104
|
+
return postLinkFn;
|
105
|
+
}
|
106
|
+
};
|
107
|
+
}).directive('remote', ['$controller'].concat(function($controller){
|
108
|
+
function onSubmitHandler($element, event){
|
109
|
+
this[1].denyDefaultAction(event);
|
110
|
+
if (this[1].allowAction()) {
|
111
|
+
this[0].submit($element);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
function postLinkFn($scope, $element, $attrs, $ctrls){
|
115
|
+
var callback;
|
116
|
+
$ctrls[1] || ($ctrls[1] = $controller('noopRailsConfirmCtrl', {
|
117
|
+
$scope: $scope
|
118
|
+
}));
|
119
|
+
callback = angular.bind($ctrls, onSubmitHandler, $element);
|
120
|
+
$element.on('submit', callback);
|
132
121
|
$scope.$on('$destroy', function(){
|
133
|
-
$element.off('submit',
|
122
|
+
$element.off('submit', callback);
|
134
123
|
});
|
135
|
-
}
|
124
|
+
}
|
136
125
|
return {
|
137
126
|
require: ['remote', '?confirm'],
|
138
127
|
restrict: 'A',
|
@@ -145,36 +134,37 @@
|
|
145
134
|
}
|
146
135
|
};
|
147
136
|
})).directive('method', ['$controller', '$compile', '$document', '$getRailsCSRF'].concat(function($controller, $compile, $document, $getRailsCSRF){
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
137
|
+
function onClickHandler($scope, $attrs, event){
|
138
|
+
var metaTags, childScope, $form;
|
139
|
+
if (this[0].allowAction()) {
|
140
|
+
this[0].denyDefaultAction(event);
|
141
|
+
}
|
142
|
+
metaTags = $getRailsCSRF();
|
143
|
+
childScope = $scope.$new();
|
144
|
+
$form = $compile("<form class=\"ng-hide\" method=\"POST\" action=\"" + $attrs.href + "\">\n <input type=\"text\" name=\"_method\" ng-model=\"_method\">\n <input type=\"text\" name=\"" + metaTags['csrf-param'] + "\" value=\"" + metaTags['csrf-token'] + "\">\n</form>")(childScope);
|
145
|
+
$document.find('body').append($form);
|
146
|
+
childScope.$apply(function(){
|
147
|
+
childScope._method = $attrs.method;
|
155
148
|
});
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
$
|
165
|
-
|
166
|
-
childScope._method = $attrs.method;
|
167
|
-
});
|
168
|
-
remoteCtrl.submit($form, true).then(function(){
|
169
|
-
childScope.$destroy();
|
170
|
-
$form.remove();
|
171
|
-
});
|
149
|
+
this[1].submit($form).then(function(){
|
150
|
+
childScope.$destroy();
|
151
|
+
$form.remove();
|
152
|
+
});
|
153
|
+
}
|
154
|
+
function postLinkFn($scope, $element, $attrs, $ctrls){
|
155
|
+
var controllerArgs, callback;
|
156
|
+
controllerArgs = {
|
157
|
+
$scope: $scope,
|
158
|
+
$attrs: $attrs
|
172
159
|
};
|
173
|
-
$
|
160
|
+
$ctrls[0] || ($ctrls[0] = $controller('noopRailsConfirmCtrl', controllerArgs));
|
161
|
+
$ctrls[1] || ($ctrls[1] = $controller('noopRailsRemoteFormCtrl', controllerArgs));
|
162
|
+
callback = angular.bind($ctrls, onClickHandler, $scope, $attrs);
|
163
|
+
$element.on('click', callback);
|
174
164
|
$scope.$on('$destroy', function(){
|
175
|
-
$element.off('click',
|
165
|
+
$element.off('click', callback);
|
176
166
|
});
|
177
|
-
}
|
167
|
+
}
|
178
168
|
return {
|
179
169
|
require: ['?confirm', '?remote'],
|
180
170
|
restrict: 'A',
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: angular-ujs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tomchentw
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|