right-rails 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/init.rb +1 -0
- data/lib/generators/right_rails/right_rails_generator.rb +15 -6
- data/lib/right_rails.rb +1 -1
- data/lib/right_rails/controller_extensions.rb +28 -15
- data/lib/right_rails/helpers/misc.rb +38 -38
- data/lib/right_rails/helpers/rails.rb +50 -7
- data/lib/rjs_renderer.rb +26 -0
- data/spec/lib/right_rails/controller_extensions_spec.rb +25 -14
- data/spec/lib/right_rails/helpers/forms_spec.rb +6 -6
- data/spec/lib/right_rails/helpers/rails_spec.rb +44 -45
- data/vendor/assets/images/rightjs-ui/rte.png +0 -0
- data/vendor/assets/javascripts/right-safe-src.js +2 -2
- data/vendor/assets/javascripts/right-safe.js +2 -2
- data/vendor/assets/javascripts/right-src.js +386 -100
- data/vendor/assets/javascripts/right.js +2 -2
- data/vendor/assets/javascripts/right/calendar-src.js +19 -3
- data/vendor/assets/javascripts/right/calendar.js +2 -2
- data/vendor/assets/javascripts/right/colorpicker-src.js +59 -20
- data/vendor/assets/javascripts/right/colorpicker.js +2 -2
- data/vendor/assets/javascripts/right/i18n/de.js +43 -42
- data/vendor/assets/javascripts/right/i18n/es.js +1 -0
- data/vendor/assets/javascripts/right/i18n/fi.js +1 -0
- data/vendor/assets/javascripts/right/i18n/fr.js +1 -0
- data/vendor/assets/javascripts/right/i18n/hu.js +1 -0
- data/vendor/assets/javascripts/right/i18n/it.js +1 -0
- data/vendor/assets/javascripts/right/i18n/jp.js +1 -0
- data/vendor/assets/javascripts/right/i18n/lt.js +96 -0
- data/vendor/assets/javascripts/right/i18n/nl.js +1 -0
- data/vendor/assets/javascripts/right/i18n/pt-br.js +1 -0
- data/vendor/assets/javascripts/right/i18n/ru.js +1 -0
- data/vendor/assets/javascripts/right/i18n/ua.js +1 -0
- data/vendor/assets/javascripts/right/jquerysh-src.js +4 -4
- data/vendor/assets/javascripts/right/jquerysh.js +2 -2
- data/vendor/assets/javascripts/right/rails-src.js +51 -15
- data/vendor/assets/javascripts/right/rails.js +2 -2
- data/vendor/assets/javascripts/right/resizable-src.js +11 -11
- data/vendor/assets/javascripts/right/rte-src.js +33 -13
- data/vendor/assets/javascripts/right/rte.js +2 -2
- data/vendor/assets/javascripts/right/slider-src.js +137 -28
- data/vendor/assets/javascripts/right/slider.js +2 -2
- metadata +24 -126
- data/generators/right_rails/right_rails_generator.rb +0 -46
- data/generators/right_rails/templates/iframed.html.erb +0 -10
- data/generators/right_scaffold/right_scaffold_generator.rb +0 -53
- data/generators/right_scaffold/templates/controller.rb +0 -99
- data/generators/right_scaffold/templates/helper.rb +0 -2
- data/generators/right_scaffold/templates/layout.html.erb +0 -18
- data/generators/right_scaffold/templates/style.css +0 -54
- data/generators/right_scaffold/templates/view__form.html.erb +0 -16
- data/generators/right_scaffold/templates/view__item.html.erb +0 -13
- data/generators/right_scaffold/templates/view_edit.html.erb +0 -6
- data/generators/right_scaffold/templates/view_index.html.erb +0 -9
- data/generators/right_scaffold/templates/view_new.html.erb +0 -5
- data/generators/right_scaffold/templates/view_show.html.erb +0 -10
- data/lib/generators/right_rails/templates/iframed.html.erb +0 -10
- data/public/images/rightjs-ui/colorpicker.png +0 -0
- data/public/images/rightjs-ui/resizable.png +0 -0
- data/public/images/rightjs-ui/rte.png +0 -0
- data/public/javascripts/right-olds-src.js +0 -652
- data/public/javascripts/right-olds.js +0 -9
- data/public/javascripts/right-safe-src.js +0 -68
- data/public/javascripts/right-safe.js +0 -7
- data/public/javascripts/right-src.js +0 -6014
- data/public/javascripts/right.js +0 -7
- data/public/javascripts/right/autocompleter-src.js +0 -625
- data/public/javascripts/right/autocompleter.js +0 -7
- data/public/javascripts/right/billboard-src.js +0 -564
- data/public/javascripts/right/billboard.js +0 -7
- data/public/javascripts/right/calendar-src.js +0 -1464
- data/public/javascripts/right/calendar.js +0 -7
- data/public/javascripts/right/casting-src.js +0 -183
- data/public/javascripts/right/casting.js +0 -7
- data/public/javascripts/right/colorpicker-src.js +0 -981
- data/public/javascripts/right/colorpicker.js +0 -7
- data/public/javascripts/right/dialog-src.js +0 -768
- data/public/javascripts/right/dialog.js +0 -7
- data/public/javascripts/right/dnd-src.js +0 -591
- data/public/javascripts/right/dnd.js +0 -7
- data/public/javascripts/right/effects-src.js +0 -508
- data/public/javascripts/right/effects.js +0 -7
- data/public/javascripts/right/i18n/de.js +0 -95
- data/public/javascripts/right/i18n/en-us.js +0 -11
- data/public/javascripts/right/i18n/es.js +0 -95
- data/public/javascripts/right/i18n/fi.js +0 -96
- data/public/javascripts/right/i18n/fr.js +0 -95
- data/public/javascripts/right/i18n/hu.js +0 -100
- data/public/javascripts/right/i18n/it.js +0 -95
- data/public/javascripts/right/i18n/jp.js +0 -99
- data/public/javascripts/right/i18n/nl.js +0 -95
- data/public/javascripts/right/i18n/pt-br.js +0 -95
- data/public/javascripts/right/i18n/ru.js +0 -95
- data/public/javascripts/right/i18n/ua.js +0 -99
- data/public/javascripts/right/in-edit-src.js +0 -373
- data/public/javascripts/right/in-edit.js +0 -7
- data/public/javascripts/right/jquerysh-src.js +0 -362
- data/public/javascripts/right/jquerysh.js +0 -7
- data/public/javascripts/right/json-src.js +0 -147
- data/public/javascripts/right/json.js +0 -7
- data/public/javascripts/right/keys-src.js +0 -87
- data/public/javascripts/right/keys.js +0 -7
- data/public/javascripts/right/lightbox-src.js +0 -931
- data/public/javascripts/right/lightbox.js +0 -7
- data/public/javascripts/right/rails-src.js +0 -402
- data/public/javascripts/right/rails.js +0 -7
- data/public/javascripts/right/rater-src.js +0 -384
- data/public/javascripts/right/rater.js +0 -7
- data/public/javascripts/right/resizable-src.js +0 -465
- data/public/javascripts/right/resizable.js +0 -7
- data/public/javascripts/right/rte-src.js +0 -2685
- data/public/javascripts/right/rte.js +0 -7
- data/public/javascripts/right/selectable-src.js +0 -725
- data/public/javascripts/right/selectable.js +0 -7
- data/public/javascripts/right/sizzle-src.js +0 -1132
- data/public/javascripts/right/sizzle.js +0 -7
- data/public/javascripts/right/slider-src.js +0 -395
- data/public/javascripts/right/slider.js +0 -7
- data/public/javascripts/right/sortable-src.js +0 -430
- data/public/javascripts/right/sortable.js +0 -7
- data/public/javascripts/right/table-src.js +0 -176
- data/public/javascripts/right/table.js +0 -7
- data/public/javascripts/right/tabs-src.js +0 -1157
- data/public/javascripts/right/tabs.js +0 -7
- data/public/javascripts/right/tags-src.js +0 -745
- data/public/javascripts/right/tags.js +0 -7
- data/public/javascripts/right/tooltips-src.js +0 -331
- data/public/javascripts/right/tooltips.js +0 -7
- data/public/javascripts/right/uploader-src.js +0 -302
- data/public/javascripts/right/uploader.js +0 -7
@@ -1,54 +0,0 @@
|
|
1
|
-
body { background-color: #fff; color: #333; }
|
2
|
-
|
3
|
-
body, p, ol, ul, td {
|
4
|
-
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
-
font-size: 13px;
|
6
|
-
line-height: 18px;
|
7
|
-
}
|
8
|
-
|
9
|
-
pre {
|
10
|
-
background-color: #eee;
|
11
|
-
padding: 10px;
|
12
|
-
font-size: 11px;
|
13
|
-
}
|
14
|
-
|
15
|
-
a { color: #000; }
|
16
|
-
a:visited { color: #666; }
|
17
|
-
a:hover { color: #fff; background-color:#000; }
|
18
|
-
|
19
|
-
.fieldWithErrors {
|
20
|
-
padding: 2px;
|
21
|
-
background-color: red;
|
22
|
-
display: table;
|
23
|
-
}
|
24
|
-
|
25
|
-
#errorExplanation {
|
26
|
-
width: 400px;
|
27
|
-
border: 2px solid red;
|
28
|
-
padding: 7px;
|
29
|
-
padding-bottom: 12px;
|
30
|
-
margin-bottom: 20px;
|
31
|
-
background-color: #f0f0f0;
|
32
|
-
}
|
33
|
-
|
34
|
-
#errorExplanation h2 {
|
35
|
-
text-align: left;
|
36
|
-
font-weight: bold;
|
37
|
-
padding: 5px 5px 5px 15px;
|
38
|
-
font-size: 12px;
|
39
|
-
margin: -7px;
|
40
|
-
background-color: #c00;
|
41
|
-
color: #fff;
|
42
|
-
}
|
43
|
-
|
44
|
-
#errorExplanation p {
|
45
|
-
color: #333;
|
46
|
-
margin-bottom: 0;
|
47
|
-
padding: 5px;
|
48
|
-
}
|
49
|
-
|
50
|
-
#errorExplanation ul li {
|
51
|
-
font-size: 12px;
|
52
|
-
list-style: square;
|
53
|
-
}
|
54
|
-
|
@@ -1,16 +0,0 @@
|
|
1
|
-
<%% form_for(@<%= singular_name %>) do |f| %>
|
2
|
-
<%%= f.error_messages %>
|
3
|
-
|
4
|
-
<% for attribute in attributes -%>
|
5
|
-
<p>
|
6
|
-
<%%= f.label :<%= attribute.name %> %><br />
|
7
|
-
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
|
8
|
-
</p>
|
9
|
-
<% end -%>
|
10
|
-
|
11
|
-
<p class="buttons">
|
12
|
-
<%%= f.submit f.object.new_record? ? 'Create' : 'Update' %>
|
13
|
-
<%%= link_to_function 'Cancel', "$(this).parent('form').remove();" if request.xhr? %>
|
14
|
-
<%%= image_tag 'spinner.gif', :style => 'display:none', :class => :spinner %>
|
15
|
-
</p>
|
16
|
-
<%% end %>
|
@@ -1,13 +0,0 @@
|
|
1
|
-
<%% div_for <%= singular_name %> do %>
|
2
|
-
<% for attribute in attributes -%>
|
3
|
-
<p>
|
4
|
-
<label><%= attribute.name %></label>: <%%=h <%= singular_name %>.<%= attribute.name %> %>
|
5
|
-
</p>
|
6
|
-
<% end -%>
|
7
|
-
|
8
|
-
<div class="actions">
|
9
|
-
<%%= link_to 'Show', <%= singular_name %> %> |
|
10
|
-
<%%= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>), :class => :edit %> |
|
11
|
-
<%%= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete, :class => :destroy %>
|
12
|
-
</div>
|
13
|
-
<%% end -%>
|
@@ -1,10 +0,0 @@
|
|
1
|
-
<% for attribute in attributes -%>
|
2
|
-
<p>
|
3
|
-
<b><%= attribute.column.human_name %>:</b>
|
4
|
-
<%%=h @<%= singular_name %>.<%= attribute.name %> %>
|
5
|
-
</p>
|
6
|
-
|
7
|
-
<% end -%>
|
8
|
-
|
9
|
-
<%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
|
10
|
-
<%%= link_to 'Back', <%= plural_name %>_path %>
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,652 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* The old browsers support module for RightJS
|
3
|
-
*
|
4
|
-
* Released under the terms of the MIT license
|
5
|
-
* Visit http://rightjs.org for more details
|
6
|
-
*
|
7
|
-
* Copyright (C) 2008-2011 Nikolay V. Nemshilov
|
8
|
-
*/
|
9
|
-
(function(RightJS) {
|
10
|
-
/**
|
11
|
-
* Old IE browser hacks
|
12
|
-
*
|
13
|
-
* Keep them in one place so they were more compact
|
14
|
-
*
|
15
|
-
* Copyright (C) 2009-2011 Nikolay Nemshilov
|
16
|
-
*/
|
17
|
-
if (RightJS.Browser.OLD && RightJS.Browser.IE) {
|
18
|
-
// loads DOM element extensions for selected elements
|
19
|
-
window.$ = RightJS.$ = (function(old_function) {
|
20
|
-
return function(id) {
|
21
|
-
var element = old_function(id);
|
22
|
-
|
23
|
-
// old IE browses match both, ID and NAME
|
24
|
-
if (element && element instanceof RightJS.Element &&
|
25
|
-
RightJS.isString(id) && element._.id !== id
|
26
|
-
) {
|
27
|
-
element = RightJS.$(document).first('#'+ id);
|
28
|
-
}
|
29
|
-
|
30
|
-
return element;
|
31
|
-
};
|
32
|
-
})(RightJS.$);
|
33
|
-
}
|
34
|
-
|
35
|
-
|
36
|
-
/**
|
37
|
-
* Making the 'submit' and 'change' events bubble under IE browsers
|
38
|
-
*
|
39
|
-
* Copyright (C) 2010-2011 Nikolay Nemshilov
|
40
|
-
*/
|
41
|
-
|
42
|
-
/**
|
43
|
-
* Tests if there is the event support
|
44
|
-
*
|
45
|
-
* @param String event name
|
46
|
-
* @retrun Boolean check result
|
47
|
-
*/
|
48
|
-
function event_support_for(name, tag) {
|
49
|
-
var e = document.createElement(tag);
|
50
|
-
e.setAttribute(name, ';');
|
51
|
-
return isFunction(e[name]);
|
52
|
-
}
|
53
|
-
|
54
|
-
if (!event_support_for('onsubmit', 'form')) {
|
55
|
-
/**
|
56
|
-
* Emulates the 'submit' event bubbling for IE browsers
|
57
|
-
*
|
58
|
-
* @param raw dom-event
|
59
|
-
* @return void
|
60
|
-
*/
|
61
|
-
var submit_boobler = function(raw_event) {
|
62
|
-
var event = $(raw_event), element = event.target._,
|
63
|
-
type = element.type, form = element.form, parent;
|
64
|
-
|
65
|
-
if (form && (parent = $(form).parent()) && (
|
66
|
-
(raw_event.keyCode === 13 && (type === 'text' || type === 'password')) ||
|
67
|
-
(raw_event.type === 'click' && (type === 'submit' || type === 'image'))
|
68
|
-
)) {
|
69
|
-
event.type = 'submit';
|
70
|
-
event.target = $(form);
|
71
|
-
parent.fire(event);
|
72
|
-
}
|
73
|
-
};
|
74
|
-
|
75
|
-
document.attachEvent('onclick', submit_boobler);
|
76
|
-
document.attachEvent('onkeypress', submit_boobler);
|
77
|
-
}
|
78
|
-
|
79
|
-
if (!event_support_for('onchange', 'input')) {
|
80
|
-
|
81
|
-
var get_input_value = function(target) {
|
82
|
-
var element = target._,
|
83
|
-
type = element.type;
|
84
|
-
|
85
|
-
return type === 'radio' || type === 'checkbox' ?
|
86
|
-
element.checked : target.getValue();
|
87
|
-
},
|
88
|
-
|
89
|
-
/**
|
90
|
-
* Emulates the 'change' event bubbling
|
91
|
-
*
|
92
|
-
* @param Event wrapped dom-event
|
93
|
-
* @param Input wrapped input element
|
94
|
-
* @return void
|
95
|
-
*/
|
96
|
-
change_boobler = function(event, target) {
|
97
|
-
var parent = target.parent(),
|
98
|
-
value = get_input_value(target);
|
99
|
-
|
100
|
-
if (parent && ''+target._prev_value !== ''+value) {
|
101
|
-
target._prev_value = value; // saving the value so it didn't fire up again
|
102
|
-
event.type = 'change';
|
103
|
-
parent.fire(event);
|
104
|
-
}
|
105
|
-
},
|
106
|
-
|
107
|
-
/**
|
108
|
-
* Catches the input field changes
|
109
|
-
*
|
110
|
-
* @param raw dom-event
|
111
|
-
* @return void
|
112
|
-
*/
|
113
|
-
catch_inputs_access = function(raw_event) {
|
114
|
-
var event = $(raw_event),
|
115
|
-
target = event.target,
|
116
|
-
type = target._.type,
|
117
|
-
tag = target._.tagName,
|
118
|
-
input_is_radio = (type === 'radio' || type === 'checkbox');
|
119
|
-
|
120
|
-
if (
|
121
|
-
(event.type === 'click' && (input_is_radio || tag === 'SELECT')) ||
|
122
|
-
(event.type === 'keydown' && (
|
123
|
-
(event.keyCode == 13 && (tag !== 'TEXTAREA')) ||
|
124
|
-
type === 'select-multiple'
|
125
|
-
))
|
126
|
-
) {
|
127
|
-
change_boobler(event, target);
|
128
|
-
}
|
129
|
-
},
|
130
|
-
|
131
|
-
/**
|
132
|
-
* Catch inputs blur
|
133
|
-
*
|
134
|
-
* @param raw dom-event
|
135
|
-
* @return void
|
136
|
-
*/
|
137
|
-
catch_input_left = function(raw_event) {
|
138
|
-
var event = $(raw_event),
|
139
|
-
target = event.target;
|
140
|
-
|
141
|
-
if (target instanceof Input) {
|
142
|
-
change_boobler(event, target);
|
143
|
-
}
|
144
|
-
};
|
145
|
-
|
146
|
-
document.attachEvent('onclick', catch_inputs_access);
|
147
|
-
document.attachEvent('onkeydown', catch_inputs_access);
|
148
|
-
document.attachEvent('onfocusout', catch_input_left);
|
149
|
-
|
150
|
-
/**
|
151
|
-
* storing the input element previous value, so we could figure out
|
152
|
-
* if it was changed later on
|
153
|
-
*/
|
154
|
-
document.attachEvent('onbeforeactivate', function(event) {
|
155
|
-
var element = $(event).target;
|
156
|
-
|
157
|
-
if (element instanceof Input) {
|
158
|
-
element._prev_value = get_input_value(element);
|
159
|
-
}
|
160
|
-
});
|
161
|
-
}
|
162
|
-
|
163
|
-
|
164
|
-
/**
|
165
|
-
* Konqueror browser fixes
|
166
|
-
*
|
167
|
-
* Copyright (C) 2009-2011 Nikolay V. Nemshilov
|
168
|
-
*/
|
169
|
-
|
170
|
-
/**
|
171
|
-
* manual position calculator, it works for Konqueror and also
|
172
|
-
* for old versions of Opera and FF
|
173
|
-
*/
|
174
|
-
if (!RightJS.$E('p')._.getBoundingClientRect) {
|
175
|
-
RightJS.Element.include({
|
176
|
-
position: function() {
|
177
|
-
var element = this._,
|
178
|
-
top = element.offsetTop,
|
179
|
-
left = element.offsetLeft,
|
180
|
-
parent = element.offsetParent;
|
181
|
-
|
182
|
-
while (parent) {
|
183
|
-
top += parent.offsetTop;
|
184
|
-
left += parent.offsetLeft;
|
185
|
-
|
186
|
-
parent = parent.offsetParent;
|
187
|
-
}
|
188
|
-
|
189
|
-
return {x: left, y: top};
|
190
|
-
}
|
191
|
-
});
|
192
|
-
}
|
193
|
-
|
194
|
-
|
195
|
-
/**
|
196
|
-
* The manual css-selector feature implementation
|
197
|
-
*
|
198
|
-
* Credits:
|
199
|
-
* - Sizzle (http://sizzlejs.org) Copyright (C) John Resig
|
200
|
-
* - MooTools (http://mootools.net) Copyright (C) Valerio Proietti
|
201
|
-
*
|
202
|
-
* Copyright (C) 2009-2011 Nikolay V. Nemshilov
|
203
|
-
*/
|
204
|
-
var has_native_css_selector = !!document.querySelector,
|
205
|
-
needs_css_engine_patch = !has_native_css_selector;
|
206
|
-
|
207
|
-
if (RightJS.Browser.IE8L) {
|
208
|
-
needs_css_engine_patch = true;
|
209
|
-
}
|
210
|
-
|
211
|
-
if (needs_css_engine_patch) {
|
212
|
-
/**
|
213
|
-
* The token searchers collection
|
214
|
-
*/
|
215
|
-
var search = {
|
216
|
-
// search for any descendant nodes
|
217
|
-
' ': function(element, tag) {
|
218
|
-
return RightJS.$A(element.getElementsByTagName(tag));
|
219
|
-
},
|
220
|
-
|
221
|
-
// search for immidate descendant nodes
|
222
|
-
'>': function(element, tag) {
|
223
|
-
var result = [], node = element.firstChild;
|
224
|
-
while (node) {
|
225
|
-
if (tag === '*' || node.tagName === tag) {
|
226
|
-
result.push(node);
|
227
|
-
}
|
228
|
-
node = node.nextSibling;
|
229
|
-
}
|
230
|
-
return result;
|
231
|
-
},
|
232
|
-
|
233
|
-
// search for immiate sibling nodes
|
234
|
-
'+': function(element, tag) {
|
235
|
-
while ((element = element.nextSibling)) {
|
236
|
-
if (element.tagName) {
|
237
|
-
return (tag === '*' || element.tagName === tag) ? [element] : [];
|
238
|
-
}
|
239
|
-
}
|
240
|
-
return [];
|
241
|
-
},
|
242
|
-
|
243
|
-
// search for late sibling nodes
|
244
|
-
'~': function(element, tag) {
|
245
|
-
var result = [];
|
246
|
-
while ((element = element.nextSibling)) {
|
247
|
-
if (tag === '*' || element.tagName === tag) {
|
248
|
-
result.push(element);
|
249
|
-
}
|
250
|
-
}
|
251
|
-
return result;
|
252
|
-
}
|
253
|
-
},
|
254
|
-
|
255
|
-
|
256
|
-
/**
|
257
|
-
* Collection of pseudo selector matchers
|
258
|
-
*/
|
259
|
-
pseudos = {
|
260
|
-
not: function(node, css_rule) {
|
261
|
-
return node.nodeType === 1 && !RightJS.$(node).match(css_rule);
|
262
|
-
},
|
263
|
-
|
264
|
-
checked: function(node) {
|
265
|
-
return node.checked === true;
|
266
|
-
},
|
267
|
-
|
268
|
-
enabled: function(node) {
|
269
|
-
return node.disabled === false;
|
270
|
-
},
|
271
|
-
|
272
|
-
disabled: function(node) {
|
273
|
-
return node.disabled === true;
|
274
|
-
},
|
275
|
-
|
276
|
-
selected: function(node) {
|
277
|
-
return node.selected === true;
|
278
|
-
},
|
279
|
-
|
280
|
-
empty: function(node) {
|
281
|
-
return !node.firstChild;
|
282
|
-
},
|
283
|
-
|
284
|
-
'first-child': function(node, node_name) {
|
285
|
-
while ((node = node.previousSibling)) {
|
286
|
-
if (node.nodeType === 1 && (node_name === null || node.nodeName === node_name)) {
|
287
|
-
return false;
|
288
|
-
}
|
289
|
-
}
|
290
|
-
return true;
|
291
|
-
},
|
292
|
-
|
293
|
-
'first-of-type': function(node) {
|
294
|
-
return pseudos['first-child'](node, node.nodeName);
|
295
|
-
},
|
296
|
-
|
297
|
-
'last-child': function(node, node_name) {
|
298
|
-
while ((node = node.nextSibling)) {
|
299
|
-
if (node.nodeType === 1 && (node_name === null || node.nodeName === node_name)) {
|
300
|
-
return false;
|
301
|
-
}
|
302
|
-
}
|
303
|
-
return true;
|
304
|
-
},
|
305
|
-
|
306
|
-
'last-of-type': function(node) {
|
307
|
-
return pseudos['last-child'](node, node.nodeName);
|
308
|
-
},
|
309
|
-
|
310
|
-
'only-child': function(node, node_name) {
|
311
|
-
return pseudos['first-child'](node, node_name) &&
|
312
|
-
pseudos['last-child'](node, node_name);
|
313
|
-
},
|
314
|
-
|
315
|
-
'only-of-type': function(node) {
|
316
|
-
return pseudos['only-child'](node, node.nodeName);
|
317
|
-
},
|
318
|
-
|
319
|
-
'nth-child': function(node, number, node_name, reverse) {
|
320
|
-
var index = 1, a = number[0], b = number[1];
|
321
|
-
|
322
|
-
while ((node = (reverse === true) ? node.nextSibling : node.previousSibling)) {
|
323
|
-
if (node.nodeType === 1 && (node_name === undefined || node.nodeName === node_name)) {
|
324
|
-
index++;
|
325
|
-
}
|
326
|
-
}
|
327
|
-
|
328
|
-
return (b === undefined ? (index === a) : ((index - b) % a === 0 && (index - b) / a >= 0));
|
329
|
-
},
|
330
|
-
|
331
|
-
'nth-of-type': function(node, number) {
|
332
|
-
return pseudos['nth-child'](node, number, node.nodeName);
|
333
|
-
},
|
334
|
-
|
335
|
-
'nth-last-child': function(node, number) {
|
336
|
-
return pseudos['nth-child'](node, number, undefined, true);
|
337
|
-
},
|
338
|
-
|
339
|
-
'nth-last-of-type': function(node, number) {
|
340
|
-
return pseudos['nth-child'](node, number, node.nodeName, true);
|
341
|
-
}
|
342
|
-
},
|
343
|
-
|
344
|
-
// the regexps collection
|
345
|
-
chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g,
|
346
|
-
id_re = /#([\w\-_]+)/,
|
347
|
-
tag_re = /^[\w\*]+/,
|
348
|
-
class_re = /\.([\w\-\._]+)/,
|
349
|
-
pseudo_re = /:([\w\-]+)(\((.+?)\))*$/,
|
350
|
-
attrs_re = /\[((?:[\w\-]*:)?[\w\-]+)\s*(?:([!\^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/,
|
351
|
-
|
352
|
-
///////////////////////////////////////////////////////////////////////////////
|
353
|
-
///////////////////////////////////////////////////////////////////////////////
|
354
|
-
///////////////////////////////////////////////////////////////////////////////
|
355
|
-
|
356
|
-
/**
|
357
|
-
* Builds an atom matcher
|
358
|
-
*
|
359
|
-
* @param String atom definition
|
360
|
-
* @return Object atom matcher
|
361
|
-
*/
|
362
|
-
atoms_cache = {},
|
363
|
-
build_atom = function(in_atom) {
|
364
|
-
if (!atoms_cache[in_atom]) {
|
365
|
-
var id, tag, classes, classes_length, attrs, pseudo,
|
366
|
-
values_of_pseudo, match, func, desc = {}, atom = in_atom;
|
367
|
-
|
368
|
-
// grabbing the attributes
|
369
|
-
while((match = atom.match(attrs_re))) {
|
370
|
-
attrs = attrs || {};
|
371
|
-
attrs[match[1]] = { o: match[2] || '', v: match[5] || match[6] || '' };
|
372
|
-
atom = atom.replace(match[0], '');
|
373
|
-
}
|
374
|
-
|
375
|
-
// extracting the pseudos
|
376
|
-
if ((match = atom.match(pseudo_re))) {
|
377
|
-
pseudo = match[1];
|
378
|
-
values_of_pseudo = match[3] === '' ? null : match[3];
|
379
|
-
|
380
|
-
if (pseudo.startsWith('nth')) {
|
381
|
-
// preparsing the nth-child pseoudo numbers
|
382
|
-
values_of_pseudo = values_of_pseudo.toLowerCase();
|
383
|
-
|
384
|
-
if (values_of_pseudo === 'n') {
|
385
|
-
// no need in the pseudo then
|
386
|
-
pseudo = null;
|
387
|
-
values_of_pseudo = null;
|
388
|
-
} else {
|
389
|
-
if (values_of_pseudo === 'odd') { values_of_pseudo = '2n+1'; }
|
390
|
-
if (values_of_pseudo === 'even') { values_of_pseudo = '2n'; }
|
391
|
-
|
392
|
-
var m = /^([+\-]?\d*)?n([+\-]?\d*)?$/.exec(values_of_pseudo);
|
393
|
-
if (m) {
|
394
|
-
values_of_pseudo = [
|
395
|
-
m[1] === '-' ? -1 : parseInt(m[1], 10) || 1,
|
396
|
-
parseInt(m[2], 10) || 0
|
397
|
-
];
|
398
|
-
} else {
|
399
|
-
values_of_pseudo = [parseInt(values_of_pseudo, 10), undefined];
|
400
|
-
}
|
401
|
-
}
|
402
|
-
}
|
403
|
-
|
404
|
-
atom = atom.replace(match[0], '');
|
405
|
-
}
|
406
|
-
|
407
|
-
// getting all the other options
|
408
|
-
id = (atom.match(id_re) || [1, null])[1];
|
409
|
-
tag = (atom.match(tag_re) || '*').toString().toUpperCase();
|
410
|
-
classes = (atom.match(class_re) || [1, ''])[1].split('.').without('');
|
411
|
-
classes_length = classes.length;
|
412
|
-
|
413
|
-
desc.tag = tag;
|
414
|
-
|
415
|
-
if (id || classes.length || attrs || pseudo) {
|
416
|
-
// optimizing a bit the values for quiker runtime checks
|
417
|
-
id = id || false;
|
418
|
-
attrs = attrs || false;
|
419
|
-
pseudo = pseudo in pseudos ? pseudos[pseudo] : false;
|
420
|
-
classes = classes_length ? classes : false;
|
421
|
-
|
422
|
-
desc.filter = function(elements) {
|
423
|
-
var node, result = [], i=0, j=0, l = elements.length, failed;
|
424
|
-
for (; i < l; i++) {
|
425
|
-
node = elements[i];
|
426
|
-
|
427
|
-
//////////////////////////////////////////////
|
428
|
-
// ID check
|
429
|
-
//
|
430
|
-
if (id !== false && node.id !== id) {
|
431
|
-
continue;
|
432
|
-
}
|
433
|
-
|
434
|
-
//////////////////////////////////////////////
|
435
|
-
// Class names check
|
436
|
-
if (classes !== false) {
|
437
|
-
var names = node.className.split(' '),
|
438
|
-
names_length = names.length,
|
439
|
-
x = 0; failed = false;
|
440
|
-
|
441
|
-
for (; x < classes_length; x++) {
|
442
|
-
for (var y=0, found = false; y < names_length; y++) {
|
443
|
-
if (classes[x] === names[y]) {
|
444
|
-
found = true;
|
445
|
-
break;
|
446
|
-
}
|
447
|
-
}
|
448
|
-
|
449
|
-
if (!found) {
|
450
|
-
failed = true;
|
451
|
-
break;
|
452
|
-
}
|
453
|
-
}
|
454
|
-
|
455
|
-
if (failed) { continue; }
|
456
|
-
}
|
457
|
-
|
458
|
-
///////////////////////////////////////////////
|
459
|
-
// Attributes check
|
460
|
-
if (attrs !== false) {
|
461
|
-
var key, attr, operand, value; failed = false;
|
462
|
-
for (key in attrs) {
|
463
|
-
attr = key === 'class' ? node.className : (node.getAttribute(key) || '');
|
464
|
-
operand = attrs[key].o;
|
465
|
-
value = attrs[key].v;
|
466
|
-
|
467
|
-
if (
|
468
|
-
(operand === '' && (key === 'class'|| key === 'lang' ?
|
469
|
-
(attr === '') : (node.getAttributeNode(key) === null))) ||
|
470
|
-
(operand === '=' && attr !== value) ||
|
471
|
-
(operand === '*=' && attr.indexOf(value) === -1) ||
|
472
|
-
(operand === '^=' && attr.indexOf(value) !== 0) ||
|
473
|
-
(operand === '$=' && attr.substring(attr.length - value.length) !== value) ||
|
474
|
-
(operand === '~=' && attr.split(' ').indexOf(value) === -1) ||
|
475
|
-
(operand === '|=' && attr.split('-').indexOf(value) === -1)
|
476
|
-
) { failed = true; break; }
|
477
|
-
}
|
478
|
-
|
479
|
-
if (failed) { continue; }
|
480
|
-
}
|
481
|
-
|
482
|
-
///////////////////////////////////////////////
|
483
|
-
// Pseudo selectors check
|
484
|
-
if (pseudo !== false) {
|
485
|
-
if (!pseudo(node, values_of_pseudo)) {
|
486
|
-
continue;
|
487
|
-
}
|
488
|
-
}
|
489
|
-
|
490
|
-
result[j++] = node;
|
491
|
-
}
|
492
|
-
return result;
|
493
|
-
};
|
494
|
-
}
|
495
|
-
|
496
|
-
atoms_cache[in_atom] = desc;
|
497
|
-
}
|
498
|
-
|
499
|
-
return atoms_cache[in_atom];
|
500
|
-
},
|
501
|
-
|
502
|
-
/**
|
503
|
-
* Builds a single selector out of a simple rule chunk
|
504
|
-
*
|
505
|
-
* @param Array of a single rule tokens
|
506
|
-
* @return Function selector
|
507
|
-
*/
|
508
|
-
tokens_cache = {},
|
509
|
-
build_selector = function(rule) {
|
510
|
-
var rule_key = rule.join('');
|
511
|
-
if (!tokens_cache[rule_key]) {
|
512
|
-
for (var i=0; i < rule.length; i++) {
|
513
|
-
rule[i][1] = build_atom(rule[i][1]);
|
514
|
-
}
|
515
|
-
|
516
|
-
// creates a list of uniq nodes
|
517
|
-
var _uid = RightJS.$uid;
|
518
|
-
var uniq = function(elements) {
|
519
|
-
var uniq = [], uids = [], uid;
|
520
|
-
for (var i=0, length = elements.length; i < length; i++) {
|
521
|
-
uid = _uid(elements[i]);
|
522
|
-
if (!uids[uid]) {
|
523
|
-
uniq.push(elements[i]);
|
524
|
-
uids[uid] = true;
|
525
|
-
}
|
526
|
-
}
|
527
|
-
|
528
|
-
return uniq;
|
529
|
-
};
|
530
|
-
|
531
|
-
// performs the actual search of subnodes
|
532
|
-
var find_subnodes = function(element, atom) {
|
533
|
-
var result = search[atom[0]](element, atom[1].tag);
|
534
|
-
return atom[1].filter ? atom[1].filter(result) : result;
|
535
|
-
};
|
536
|
-
|
537
|
-
// building the actual selector function
|
538
|
-
tokens_cache[rule_key] = function(element) {
|
539
|
-
var founds, sub_founds;
|
540
|
-
|
541
|
-
for (var i=0, i_length = rule.length; i < i_length; i++) {
|
542
|
-
if (i === 0) {
|
543
|
-
founds = find_subnodes(element, rule[i]);
|
544
|
-
|
545
|
-
} else {
|
546
|
-
if (i > 1) { founds = uniq(founds); }
|
547
|
-
|
548
|
-
for (var j=0; j < founds.length; j++) {
|
549
|
-
sub_founds = find_subnodes(founds[j], rule[i]);
|
550
|
-
|
551
|
-
sub_founds.unshift(1); // <- nuke the parent node out of the list
|
552
|
-
sub_founds.unshift(j); // <- position to insert the subresult
|
553
|
-
|
554
|
-
founds.splice.apply(founds, sub_founds);
|
555
|
-
|
556
|
-
j += sub_founds.length - 3;
|
557
|
-
}
|
558
|
-
}
|
559
|
-
}
|
560
|
-
|
561
|
-
return rule.length > 1 ? uniq(founds) : founds;
|
562
|
-
};
|
563
|
-
}
|
564
|
-
return tokens_cache[rule_key];
|
565
|
-
},
|
566
|
-
|
567
|
-
|
568
|
-
/**
|
569
|
-
* Builds the list of selectors for the css_rule
|
570
|
-
*
|
571
|
-
* @param String raw css-rule
|
572
|
-
* @return Array of selectors
|
573
|
-
*/
|
574
|
-
selectors_cache = {}, chunks_cache = {},
|
575
|
-
split_rule_to_selectors = function(css_rule) {
|
576
|
-
if (!selectors_cache[css_rule]) {
|
577
|
-
chunker.lastIndex = 0;
|
578
|
-
|
579
|
-
var rules = [], rule = [], rel = ' ', m, token;
|
580
|
-
while ((m = chunker.exec(css_rule))) {
|
581
|
-
token = m[1];
|
582
|
-
|
583
|
-
if (token === '+' || token === '>' || token === '~') {
|
584
|
-
rel = token;
|
585
|
-
} else {
|
586
|
-
rule.push([rel, token]);
|
587
|
-
rel = ' ';
|
588
|
-
}
|
589
|
-
|
590
|
-
if (m[2]) {
|
591
|
-
rules.push(build_selector(rule));
|
592
|
-
rule = [];
|
593
|
-
}
|
594
|
-
}
|
595
|
-
rules.push(build_selector(rule));
|
596
|
-
|
597
|
-
selectors_cache[css_rule] = rules;
|
598
|
-
}
|
599
|
-
return selectors_cache[css_rule];
|
600
|
-
},
|
601
|
-
|
602
|
-
|
603
|
-
/**
|
604
|
-
* The top level method, it just goes throught the css-rule chunks
|
605
|
-
* collect and merge the results that's it
|
606
|
-
*
|
607
|
-
* @param Element context
|
608
|
-
* @param String raw css-rule
|
609
|
-
* @return Array search result
|
610
|
-
*/
|
611
|
-
select_all = function(element, css_rule) {
|
612
|
-
var selectors = split_rule_to_selectors(css_rule), result = [];
|
613
|
-
for (var i=0, length = selectors.length; i < length; i++) {
|
614
|
-
result = result.concat(selectors[i](element));
|
615
|
-
}
|
616
|
-
|
617
|
-
return result;
|
618
|
-
},
|
619
|
-
|
620
|
-
|
621
|
-
///////////////////////////////////////////////////////////////////////////////
|
622
|
-
///////////////////////////////////////////////////////////////////////////////
|
623
|
-
///////////////////////////////////////////////////////////////////////////////
|
624
|
-
|
625
|
-
// the previous dom-selection methods replacement
|
626
|
-
dom_extension = {
|
627
|
-
first: function(css_rule) {
|
628
|
-
return this.find(css_rule)[0];
|
629
|
-
},
|
630
|
-
|
631
|
-
find: function(css_rule, raw) {
|
632
|
-
var result, rule = css_rule || '*', element = this._, tag = element.tagName;
|
633
|
-
|
634
|
-
if (has_native_css_selector) {
|
635
|
-
try { // trying to reuse native css-engine under IE8
|
636
|
-
result = $A(element.querySelectorAll(rule));
|
637
|
-
} catch(e) { // if it fails use our own engine
|
638
|
-
result = select_all(element, rule);
|
639
|
-
}
|
640
|
-
} else {
|
641
|
-
result = select_all(element, rule);
|
642
|
-
}
|
643
|
-
|
644
|
-
return raw === true ? result : result.map(RightJS.$);
|
645
|
-
}
|
646
|
-
};
|
647
|
-
|
648
|
-
// hooking up the rightjs wrappers with the new methods
|
649
|
-
RightJS.$ext(RightJS.Element.prototype, dom_extension);
|
650
|
-
RightJS.$ext(RightJS.Document.prototype, dom_extension);
|
651
|
-
}
|
652
|
-
})(RightJS);
|