uri-js-rails 1.7.4
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +1 -0
- data/lib/uri-js-rails.rb +2 -0
- data/lib/uri-js-rails/engine.rb +11 -0
- data/lib/uri-js-rails/version.rb +7 -0
- data/uri-js-rails.gemspec +19 -0
- data/vendor/assets/javascripts/URI.js +1586 -0
- data/vendor/assets/javascripts/jquery.URI.js +216 -0
- metadata +57 -0
@@ -0,0 +1,216 @@
|
|
1
|
+
/*!
|
2
|
+
* URI.js - Mutating URLs
|
3
|
+
* jQuery Plugin
|
4
|
+
*
|
5
|
+
* Version: 1.7.4
|
6
|
+
*
|
7
|
+
* Author: Rodney Rehm
|
8
|
+
* Web: http://medialize.github.com/URI.js/jquery-uri-plugin.html
|
9
|
+
*
|
10
|
+
* Licensed under
|
11
|
+
* MIT License http://www.opensource.org/licenses/mit-license
|
12
|
+
* GPL v3 http://opensource.org/licenses/GPL-3.0
|
13
|
+
*
|
14
|
+
*/
|
15
|
+
|
16
|
+
(function($, undefined){
|
17
|
+
|
18
|
+
var URI = typeof module !== "undefined" && module.exports
|
19
|
+
? require('./URIjs')
|
20
|
+
: window.URI;
|
21
|
+
|
22
|
+
function escapeRegEx(string) {
|
23
|
+
// https://github.com/medialize/URI.js/commit/85ac21783c11f8ccab06106dba9735a31a86924d#commitcomment-821963
|
24
|
+
return string.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
|
25
|
+
}
|
26
|
+
|
27
|
+
function getUriProperty(elem) {
|
28
|
+
var property;
|
29
|
+
|
30
|
+
// Note: IE9 will report img.href, so check img.src first (Issue #48)
|
31
|
+
$.each(['src', 'href', 'action'], function(k, v) {
|
32
|
+
if (v in elem ) {
|
33
|
+
property = v;
|
34
|
+
return false;
|
35
|
+
}
|
36
|
+
|
37
|
+
return true;
|
38
|
+
});
|
39
|
+
|
40
|
+
// compensate ambiguous <input>
|
41
|
+
if (elem.nodeName.toLowerCase() === 'input' && elem.type !== 'image') {
|
42
|
+
return undefined;
|
43
|
+
}
|
44
|
+
|
45
|
+
return property;
|
46
|
+
}
|
47
|
+
|
48
|
+
var pseudo = /^([a-zA-Z]+)\s*([\^\$*]?=|:)\s*(['"]?)(.+)\3|^\s*([a-zA-Z0-9]+)\s*$/,
|
49
|
+
comparable = {},
|
50
|
+
// https://developer.mozilla.org/en/CSS/Attribute_selectors
|
51
|
+
compare = {
|
52
|
+
// equals
|
53
|
+
'=': function(value, target) {
|
54
|
+
return value === target;
|
55
|
+
},
|
56
|
+
// ~= translates to value.match((?:^|\s)target(?:\s|$)) which is useless for URIs
|
57
|
+
// |= translates to value.match((?:\b)target(?:-|\s|$)) which is useless for URIs
|
58
|
+
// begins with
|
59
|
+
'^=': function(value, target, property) {
|
60
|
+
return !!(value + "").match(new RegExp('^' + escapeRegEx(target), 'i'));
|
61
|
+
},
|
62
|
+
// ends with
|
63
|
+
'$=': function(value, target, property) {
|
64
|
+
return !!(value + "").match(new RegExp(escapeRegEx(target) + '$', 'i'));
|
65
|
+
},
|
66
|
+
// contains
|
67
|
+
'*=': function(value, target, property) {
|
68
|
+
if (property == 'directory') {
|
69
|
+
// add trailing slash so /dir/ will match the deep-end as well
|
70
|
+
value += '/';
|
71
|
+
}
|
72
|
+
|
73
|
+
return !!(value + "").match(new RegExp(escapeRegEx(target), 'i'));
|
74
|
+
},
|
75
|
+
'equals:': function(uri, target) {
|
76
|
+
return uri.equals(target);
|
77
|
+
},
|
78
|
+
'is:': function(uri, target) {
|
79
|
+
return uri.is(target);
|
80
|
+
}
|
81
|
+
},
|
82
|
+
generateAccessor = function(property) {
|
83
|
+
return {
|
84
|
+
get: function(elem) {
|
85
|
+
return $(elem).uri()[property]();
|
86
|
+
},
|
87
|
+
set: function(elem, value) {
|
88
|
+
$(elem).uri()[property](value);
|
89
|
+
return value;
|
90
|
+
}
|
91
|
+
};
|
92
|
+
};
|
93
|
+
|
94
|
+
// populate lookup table and register $.attr('uri:accessor') handlers
|
95
|
+
$.each('authority directory domain filename fragment hash host hostname href password path pathname port protocol query scheme search subdomain suffix tld username'.split(" "), function(k, v) {
|
96
|
+
comparable[v] = true;
|
97
|
+
$.attrHooks['uri:' + v] = generateAccessor(v);
|
98
|
+
});
|
99
|
+
|
100
|
+
// general URI accessor
|
101
|
+
$.fn.uri = function(uri) {
|
102
|
+
var $this = this.first(),
|
103
|
+
elem = $this.get(0),
|
104
|
+
property = getUriProperty(elem);
|
105
|
+
|
106
|
+
if (!property) {
|
107
|
+
throw new Error('Element "' + elem.nodeName + '" does not have either property: href, src, action');
|
108
|
+
}
|
109
|
+
|
110
|
+
if (uri !== undefined) {
|
111
|
+
var old = $this.data('uri');
|
112
|
+
if (old) {
|
113
|
+
return old.href(uri);
|
114
|
+
}
|
115
|
+
|
116
|
+
if (!(uri instanceof URI)) {
|
117
|
+
uri = URI(uri);
|
118
|
+
}
|
119
|
+
} else {
|
120
|
+
uri = $this.data('uri');
|
121
|
+
if (uri) {
|
122
|
+
return uri;
|
123
|
+
} else {
|
124
|
+
uri = URI($this.attr(property));
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
uri._dom_element = elem;
|
129
|
+
uri._dom_attribute = property;
|
130
|
+
uri.normalize();
|
131
|
+
$this.data('uri', uri);
|
132
|
+
return uri;
|
133
|
+
};
|
134
|
+
|
135
|
+
// overwrite URI.build() to update associated DOM element if necessary
|
136
|
+
URI.prototype.build = function(deferBuild) {
|
137
|
+
if (this._dom_element) {
|
138
|
+
// cannot defer building when hooked into a DOM element
|
139
|
+
this._string = URI.build(this._parts);
|
140
|
+
this._deferred_build = false;
|
141
|
+
this._dom_element.setAttribute(this._dom_attribute, this._string);
|
142
|
+
this._dom_element[this._dom_attribute] = this._string;
|
143
|
+
} else if (deferBuild === true) {
|
144
|
+
this._deferred_build = true;
|
145
|
+
} else if (deferBuild === undefined || this._deferred_build) {
|
146
|
+
this._string = URI.build(this._parts);
|
147
|
+
this._deferred_build = false;
|
148
|
+
}
|
149
|
+
|
150
|
+
return this;
|
151
|
+
};
|
152
|
+
|
153
|
+
// :uri() pseudo-selector for $.find(), $.filter() $.is(), et al.
|
154
|
+
$.expr.filters.uri = function(elem, index, matches) {
|
155
|
+
// documentation on this is scarce, look into
|
156
|
+
// - https://github.com/jquery/sizzle/wiki/Sizzle-Home
|
157
|
+
// - https://github.com/jquery/sizzle/blob/master/sizzle.js#L626
|
158
|
+
|
159
|
+
// skip anything without src|href|action and bad :uri() syntax
|
160
|
+
if (!getUriProperty(elem) || !matches[3]) {
|
161
|
+
return false;
|
162
|
+
}
|
163
|
+
|
164
|
+
var t = matches[3].match(pseudo),
|
165
|
+
property,
|
166
|
+
uri;
|
167
|
+
|
168
|
+
if (!t || (!t[5] && t[2] !== ':' && !compare[t[2]])) {
|
169
|
+
// abort because the given selector cannot be executed
|
170
|
+
// filers seem to fail silently
|
171
|
+
return false;
|
172
|
+
}
|
173
|
+
|
174
|
+
uri = $(elem).uri();
|
175
|
+
|
176
|
+
if (t[5]) {
|
177
|
+
return uri.is(t[5]);
|
178
|
+
} else if (t[2] === ':') {
|
179
|
+
property = t[1].toLowerCase() + ':';
|
180
|
+
if (!compare[property]) {
|
181
|
+
// filers seem to fail silently
|
182
|
+
return false;
|
183
|
+
}
|
184
|
+
|
185
|
+
return compare[property](uri, t[4]);
|
186
|
+
} else {
|
187
|
+
property = t[1].toLowerCase();
|
188
|
+
if (!comparable[property]) {
|
189
|
+
// filers seem to fail silently
|
190
|
+
return false;
|
191
|
+
}
|
192
|
+
|
193
|
+
return compare[t[2]](uri[property](), t[4], property);
|
194
|
+
}
|
195
|
+
|
196
|
+
return false;
|
197
|
+
};
|
198
|
+
|
199
|
+
// pipe $.attr('src') and $.attr('href') through URI.js
|
200
|
+
var _attrHooks = {
|
201
|
+
get: function(elem) {
|
202
|
+
return $(elem).uri();
|
203
|
+
},
|
204
|
+
set: function(elem, value) {
|
205
|
+
return $(elem).uri().href(value).toString();
|
206
|
+
}
|
207
|
+
};
|
208
|
+
$.each(['src', 'href', 'action', 'uri'], function(k, v) {
|
209
|
+
$.attrHooks[v] = {
|
210
|
+
set: _attrHooks.set
|
211
|
+
};
|
212
|
+
});
|
213
|
+
$.attrHooks.uri.get = _attrHooks.get;
|
214
|
+
|
215
|
+
|
216
|
+
})(jQuery);
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uri-js-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.7.4
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Robin Wenglewski
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-04 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ''
|
15
|
+
email:
|
16
|
+
- robin@wenglewski.de
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/uri-js-rails.rb
|
27
|
+
- lib/uri-js-rails/engine.rb
|
28
|
+
- lib/uri-js-rails/version.rb
|
29
|
+
- uri-js-rails.gemspec
|
30
|
+
- vendor/assets/javascripts/URI.js
|
31
|
+
- vendor/assets/javascripts/jquery.URI.js
|
32
|
+
homepage: ''
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.8.24
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: URI.js for rails
|
56
|
+
test_files: []
|
57
|
+
has_rdoc:
|