role-rails 1.2.1 → 1.3.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.
data/lib/role-rails/version.rb
CHANGED
@@ -1,19 +1,68 @@
|
|
1
1
|
!function($){
|
2
2
|
function rewriteSelector(context, name, argPos){
|
3
3
|
var original = context[name];
|
4
|
-
|
4
|
+
|
5
5
|
if (!original) return;
|
6
|
-
|
6
|
+
|
7
7
|
context[name] = function(){
|
8
|
-
arguments[argPos] = arguments[argPos].replace(/@([\w\u00c0-\uFFFF\-]+)/g, '[role~="$1"]')
|
8
|
+
arguments[argPos] = arguments[argPos].replace(/@([\w\u00c0-\uFFFF\-]+)/g, '[role~="$1"]');
|
9
9
|
return original.apply(context, arguments);
|
10
10
|
};
|
11
|
-
|
11
|
+
|
12
12
|
$.extend(context[name], original);
|
13
13
|
}
|
14
|
-
|
14
|
+
|
15
15
|
rewriteSelector($, 'find', 0);
|
16
16
|
rewriteSelector($, 'multiFilter', 0);
|
17
17
|
rewriteSelector($.find, 'matchesSelector', 1);
|
18
18
|
rewriteSelector($.find, 'matches', 0);
|
19
|
+
|
20
|
+
function parse(roleString, without){
|
21
|
+
var role, result = [], roles = $.trim(roleString).split(/\s+/);
|
22
|
+
|
23
|
+
for(var i=0; i<roles.length; i++) {
|
24
|
+
role = roles[i];
|
25
|
+
if (!~$.inArray(role, result) && (!without || !~$.inArray(role, without)))
|
26
|
+
result.push(role);
|
27
|
+
}
|
28
|
+
|
29
|
+
return result;
|
30
|
+
};
|
31
|
+
|
32
|
+
$.extend($.fn, {
|
33
|
+
roles: function(){ return parse(this.attr('role')); },
|
34
|
+
|
35
|
+
hasRole: function(roleName){
|
36
|
+
var roles = parse(roleName);
|
37
|
+
for(var i=0;i<roles.length;i++)
|
38
|
+
if (!this.is('@'+roles[i])) return false;
|
39
|
+
|
40
|
+
return true;
|
41
|
+
},
|
42
|
+
|
43
|
+
addRole: function(roleName){
|
44
|
+
if (this.hasRole(roleName)) return this;
|
45
|
+
|
46
|
+
return this.each(function(_, element){
|
47
|
+
var $el = $(element);
|
48
|
+
$el.attr('role', parse($el.attr('role') + ' ' + roleName).join(' '));
|
49
|
+
});
|
50
|
+
},
|
51
|
+
|
52
|
+
removeRole: function(roleName){
|
53
|
+
if (!this.hasRole(roleName)) return this;
|
54
|
+
|
55
|
+
return this.each(function(_, element){
|
56
|
+
var $el = $(element);
|
57
|
+
$el.attr('role', parse($el.attr('role'), parse(roleName)).join(' '));
|
58
|
+
});
|
59
|
+
},
|
60
|
+
|
61
|
+
toggleRole: function(roleName){
|
62
|
+
var roles = parse(roleName);
|
63
|
+
for(var i=0;i<roles.length;i++)
|
64
|
+
this[this.hasRole(roles[i]) ? 'removeRole' : 'addRole'].call(this, roles[i]);
|
65
|
+
return this;
|
66
|
+
}
|
67
|
+
});
|
19
68
|
}(jQuery)
|
@@ -1 +1 @@
|
|
1
|
-
!function(a){function b(b,c,d){var e=b[c];if(!e)return;b[c]=function(){return arguments[d]=arguments[d].replace(/@([\w\u00c0-\uFFFF\-]+)/g,'[role~="$1"]'),e.apply(b,arguments)},a.extend(b[c],e)}b(a,"find",0),b(a,"multiFilter",0),b(a.find,"matchesSelector",1),b(a.find,"matches",0)}(jQuery);
|
1
|
+
!function(a){function b(b,c,d){var e=b[c];if(!e)return;b[c]=function(){return arguments[d]=arguments[d].replace(/@([\w\u00c0-\uFFFF\-]+)/g,'[role~="$1"]'),e.apply(b,arguments)},a.extend(b[c],e)}function c(b,c){var d,e=[],f=a.trim(b).split(/\s+/);for(var g=0;g<f.length;g++)d=f[g],!~a.inArray(d,e)&&(!c||!~a.inArray(d,c))&&e.push(d);return e}b(a,"find",0),b(a,"multiFilter",0),b(a.find,"matchesSelector",1),b(a.find,"matches",0),a.extend(a.fn,{roles:function(){return c(this.attr("role"))},hasRole:function(a){var b=c(a);for(var d=0;d<b.length;d++)if(!this.is("@"+b[d]))return!1;return!0},addRole:function(b){return this.hasRole(b)?this:this.each(function(d,e){var f=a(e);f.attr("role",c(f.attr("role")+" "+b).join(" "))})},removeRole:function(b){return this.hasRole(b)?this.each(function(d,e){var f=a(e);f.attr("role",c(f.attr("role"),c(b)).join(" "))}):this},toggleRole:function(a){var b=c(a);for(var d=0;d<b.length;d++)this[this.hasRole(b[d])?"removeRole":"addRole"].call(this,b[d]);return this}})}(jQuery);
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: role-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -174,21 +174,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
174
174
|
- - ! '>='
|
175
175
|
- !ruby/object:Gem::Version
|
176
176
|
version: '0'
|
177
|
-
segments:
|
178
|
-
- 0
|
179
|
-
hash: -3661075772796767822
|
180
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
178
|
none: false
|
182
179
|
requirements:
|
183
180
|
- - ! '>='
|
184
181
|
- !ruby/object:Gem::Version
|
185
182
|
version: '0'
|
186
|
-
segments:
|
187
|
-
- 0
|
188
|
-
hash: -3661075772796767822
|
189
183
|
requirements: []
|
190
184
|
rubyforge_project: role-rails
|
191
|
-
rubygems_version: 1.8.
|
185
|
+
rubygems_version: 1.8.24
|
192
186
|
signing_key:
|
193
187
|
specification_version: 3
|
194
188
|
summary: jQuery plugin to provide easy way to handle DOM elements by role attribute
|