angular-ujs 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4e07e05d8baa28d55f528ea4398146791793039
4
- data.tar.gz: b11485ec174e7d151d772936f52958ef131695ea
3
+ metadata.gz: d9014c8edfa2d4616d44cbbb6fdcdba1976162af
4
+ data.tar.gz: 632a69340d981c4608cfe98caed708efb0c889c3
5
5
  SHA512:
6
- metadata.gz: 01744fb5190801af5ced520e8f90220797e3622d2c5acc277a00db0c6922afe82e2bf58afde24fb85dd714f8569007729d5fe848d3e90af4a0a25ef874864424
7
- data.tar.gz: c9e890d35777d701b172991190dbbc5c20990b427e4d5b123e5303673a9e6a28811324259312b623c1ce01a3430f4799e84e6266248f9b5f9d2c387ace1ace04
6
+ metadata.gz: 76085a5211cac4a39f5a355825bb85d2ded9cf54af6c7d8d737b84ecff11d6348db80ee04e13396dd810917c6cfa9362d6e6f6c3ed8ee03e5bd660206cfc8d46
7
+ data.tar.gz: 29e42cb163e97b4069bb56aa88e4c83018802d648de91850ee6343bb9207d26f2ee805b04d159dcd48b97f8983f2c610e5d548eafba208c73199a19b99039ee4
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # angular-ujs
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/angular-ujs.png)](http://badge.fury.io/rb/angular-ujs) [![NPM version](https://badge.fury.io/js/angular-ujs.png)](http://badge.fury.io/js/angular-ujs) [![Build Status](https://secure.travis-ci.org/tomchentw/angular-ujs.png)](http://travis-ci.org/tomchentw/angular-ujs) [![Code Climate](https://codeclimate.com/github/tomchentw/angular-ujs.png)](https://codeclimate.com/github/tomchentw/angular-ujs) [![Dependency Status](https://gemnasium.com/tomchentw/angular-ujs.png)](https://gemnasium.com/tomchentw/angular-ujs)
3
+ [![Gem Version](https://badge.fury.io/rb/angular-ujs.png)](http://badge.fury.io/rb/angular-ujs) [![NPM version](https://badge.fury.io/js/angular-ujs.png)](http://badge.fury.io/js/angular-ujs) [![Build Status](https://secure.travis-ci.org/tomchentw/angular-ujs.png)](http://travis-ci.org/tomchentw/angular-ujs) [![Coverage Status](https://coveralls.io/repos/tomchentw/angular-ujs/badge.png?branch=master)](https://coveralls.io/r/tomchentw/angular-ujs?branch=master) [![Code Climate](https://codeclimate.com/github/tomchentw/angular-ujs.png)](https://codeclimate.com/github/tomchentw/angular-ujs) [![Dependency Status](https://gemnasium.com/tomchentw/angular-ujs.png)](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.6",
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.10.9"
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.6 - Fri Jan 17 2014 19:02:50 GMT+0800 (CST)
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', []).config(['$provide', '$injector'].concat(function($provide, $injector){
14
- var NAME;
15
- NAME = '$getRailsCSRF';
16
- if ($injector.has(NAME)) {
17
- return;
18
- }
19
- /*
20
- * Maybe provided in `ng-rails-csrf`
21
- */
22
- $provide.factory(NAME, ['$document'].concat(function($document){
23
- return function(){
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('noopRailsRemoteFormCtrl', function(){
40
- this.submit = function($form){
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
- })).directive('confirm', function(){
54
- var postLinkFn;
55
- postLinkFn = function($scope, $element, $attrs, $ctrls){
56
- var confirmCtrl, onClickHandler;
57
- confirmCtrl = $ctrls[0];
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, modelName){
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('remote', ['$controller'].concat(function($controller){
118
- var postLinkFn;
119
- postLinkFn = function($scope, $element, $attrs, $ctrls){
120
- var remoteCtrl, confirmCtrl, onSubmitHandler;
121
- remoteCtrl = $ctrls[0], confirmCtrl = $ctrls[1] || $controller('noopRailsConfirmCtrl', {
122
- $scope: $scope
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
- onSubmitHandler = function(event){
125
- confirmCtrl.denyDefaultAction(event);
126
- if (!confirmCtrl.allowAction($attrs)) {
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
- remoteCtrl.submit($element, $attrs.remote);
130
- };
131
- $element.on('submit', onSubmitHandler);
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', onSubmitHandler);
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
- var postLinkFn;
149
- postLinkFn = function($scope, $element, $attrs, $ctrls){
150
- var confirmCtrl, remoteCtrl, onClickHandler;
151
- confirmCtrl = $ctrls[0] || $controller('noopRailsConfirmCtrl', {
152
- $scope: $scope
153
- }), remoteCtrl = $ctrls[1] || $controller('noopRailsRemoteFormCtrl', {
154
- $scope: $scope
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
- onClickHandler = function(event){
157
- var metaTags, childScope, $form;
158
- if (confirmCtrl.allowAction($attrs)) {
159
- confirmCtrl.denyDefaultAction(event);
160
- }
161
- metaTags = $getRailsCSRF();
162
- childScope = $scope.$new();
163
- $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);
164
- $document.find('body').append($form);
165
- childScope.$apply(function(){
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
- $element.on('click', onClickHandler);
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', onClickHandler);
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.6
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-17 00:00:00.000000000 Z
11
+ date: 2014-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler