| author | ymh <ymh.work@gmail.com> |
| Fri, 25 Oct 2013 01:20:25 +0200 | |
| changeset 211 | d87f6bdee43d |
| parent 210 | f4cbc517126d |
| child 212 | ee7b5831d382 |
| permissions | -rw-r--r-- |
| 1 | 1 |
|
| 5 | 2 |
/* Declaring the Renkan Namespace Rkns and Default values */ |
| 1 | 3 |
|
| 195 | 4 |
(function(root) { |
5 |
||
6 |
"use strict"; |
|
7 |
||
8 |
if (typeof root.Rkns !== "object") { |
|
9 |
root.Rkns = {}; |
|
| 3 | 10 |
} |
| 1 | 11 |
|
| 195 | 12 |
var Rkns = root.Rkns; |
13 |
var $ = Rkns.$ = root.jQuery; |
|
14 |
var _ = Rkns._ = root._; |
|
| 1 | 15 |
|
|
211
d87f6bdee43d
upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents:
210
diff
changeset
|
16 |
Rkns.VERSION = '0.2.2'; |
| 68 | 17 |
|
| 69 | 18 |
Rkns.pickerColors = ["#8f1919", "#a80000", "#d82626", "#ff0000", "#e87c7c", "#ff6565", "#f7d3d3", "#fecccc", |
19 |
"#8f5419", "#a85400", "#d87f26", "#ff7f00", "#e8b27c", "#ffb265", "#f7e5d3", "#fee5cc", |
|
20 |
"#8f8f19", "#a8a800", "#d8d826", "#feff00", "#e8e87c", "#feff65", "#f7f7d3", "#fefecc", |
|
21 |
"#198f19", "#00a800", "#26d826", "#00ff00", "#7ce87c", "#65ff65", "#d3f7d3", "#ccfecc", |
|
22 |
"#198f8f", "#00a8a8", "#26d8d8", "#00feff", "#7ce8e8", "#65feff", "#d3f7f7", "#ccfefe", |
|
23 |
"#19198f", "#0000a8", "#2626d8", "#0000ff", "#7c7ce8", "#6565ff", "#d3d3f7", "#ccccfe", |
|
24 |
"#8f198f", "#a800a8", "#d826d8", "#ff00fe", "#e87ce8", "#ff65fe", "#f7d3f7", "#feccfe", |
|
25 |
"#000000", "#242424", "#484848", "#6d6d6d", "#919191", "#b6b6b6", "#dadada", "#ffffff"]; |
|
| 52 | 26 |
|
| 195 | 27 |
Rkns.__renkans = []; |
28 |
||
29 |
var _BaseBin = Rkns._BaseBin = function(_renkan, _opts) { |
|
| 21 | 30 |
if (typeof _renkan !== "undefined") { |
31 |
this.renkan = _renkan; |
|
32 |
this.renkan.$.find(".Rk-Bin-Main").hide(); |
|
33 |
this.$ = Rkns.$('<li>') |
|
34 |
.addClass("Rk-Bin") |
|
35 |
.appendTo(_renkan.$.find(".Rk-Bin-List")); |
|
| 34 | 36 |
this.title_icon_$ = Rkns.$('<span>') |
37 |
.addClass("Rk-Bin-Title-Icon") |
|
38 |
.appendTo(this.$); |
|
| 42 | 39 |
|
| 34 | 40 |
var _this = this; |
| 42 | 41 |
|
42 |
Rkns.$('<a>') |
|
| 119 | 43 |
.attr({ |
| 160 | 44 |
href: "#", |
45 |
title: _renkan.translate("Close bin") |
|
46 |
}) |
|
| 34 | 47 |
.addClass("Rk-Bin-Close") |
48 |
.html('×') |
|
49 |
.appendTo(this.$) |
|
50 |
.click(function() { |
|
51 |
_this.destroy(); |
|
| 119 | 52 |
if (!_renkan.$.find(".Rk-Bin-Main:visible").length) { |
| 160 | 53 |
_renkan.$.find(".Rk-Bin-Main:last").slideDown(); |
| 119 | 54 |
} |
55 |
_renkan.resizeBins(); |
|
| 42 | 56 |
return false; |
57 |
}); |
|
58 |
Rkns.$('<a>') |
|
| 119 | 59 |
.attr({ |
| 160 | 60 |
href: "#", |
61 |
title: _renkan.translate("Refresh bin") |
|
62 |
}) |
|
| 42 | 63 |
.addClass("Rk-Bin-Refresh") |
64 |
.appendTo(this.$) |
|
65 |
.click(function() { |
|
66 |
_this.refresh(); |
|
67 |
return false; |
|
| 34 | 68 |
}); |
| 44 | 69 |
this.count_$ = Rkns.$('<div>') |
70 |
.addClass("Rk-Bin-Count") |
|
71 |
.appendTo(this.$); |
|
| 21 | 72 |
this.title_$ = Rkns.$('<h2>') |
73 |
.addClass("Rk-Bin-Title") |
|
74 |
.appendTo(this.$); |
|
75 |
this.main_$ = Rkns.$('<div>') |
|
76 |
.addClass("Rk-Bin-Main") |
|
| 64 | 77 |
.appendTo(this.$) |
| 66 | 78 |
.html('<h4 class="Rk-Bin-Loading">' + _renkan.translate("Loading, please wait") + '</h4>'); |
| 26 | 79 |
this.title_$.html(_opts.title || '(new bin)'); |
| 21 | 80 |
this.renkan.resizeBins(); |
| 42 | 81 |
|
82 |
if (_opts.auto_refresh) { |
|
83 |
window.setInterval(function() { |
|
84 |
_this.refresh(); |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
169
diff
changeset
|
85 |
},_opts.auto_refresh); |
| 42 | 86 |
} |
| 20 | 87 |
} |
| 163 | 88 |
}; |
| 34 | 89 |
|
| 195 | 90 |
_BaseBin.prototype.destroy = function() { |
| 34 | 91 |
this.$.detach(); |
92 |
this.renkan.resizeBins(); |
|
| 163 | 93 |
}; |
| 34 | 94 |
|
| 20 | 95 |
/* Point of entry */ |
96 |
||
| 195 | 97 |
var Renkan = Rkns.Renkan = function(_opts) { |
| 68 | 98 |
var _this = this; |
99 |
|
|
| 195 | 100 |
Rkns.__renkans.push(this); |
101 |
|
|
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
102 |
this.options = _.defaults(_opts, Rkns.defaults); |
|
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
103 |
|
| 196 | 104 |
_(this.options.property_files).each(function(f) { |
| 160 | 105 |
Rkns.$.getJSON(f, function(data) { |
106 |
_this.options.properties = _this.options.properties.concat(data); |
|
107 |
}); |
|
108 |
}); |
|
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
109 |
|
|
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
110 |
this.read_only = this.options.read_only || !this.options.editor_mode; |
|
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
111 |
|
| 23 | 112 |
this.project = new Rkns.Models.Project(); |
| 69 | 113 |
|
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
114 |
if (typeof this.options.user_id !== "undefined") { |
|
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
115 |
this.current_user = this.options.user_id; |
| 4 | 116 |
} |
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
117 |
this.$ = Rkns.$("#" + this.options.container); |
| 34 | 118 |
this.$ |
119 |
.addClass("Rk-Main") |
|
| 68 | 120 |
.html(this.template(this)); |
| 188 | 121 |
|
| 21 | 122 |
this.tabs = []; |
| 34 | 123 |
this.search_engines = []; |
| 56 | 124 |
|
125 |
this.current_user_list = new Rkns.Models.UsersList(); |
|
126 |
|
|
| 195 | 127 |
this.current_user_list.on("add remove", function() { |
128 |
if (this.renderer) { |
|
129 |
this.renderer.redrawUsers(); |
|
130 |
} |
|
131 |
}); |
|
132 |
|
|
133 |
this.colorPicker = (function() { |
|
134 |
var _tmpl = _.template('<li data-color="<%=c%>" style="background: <%=c%>"></li>'); |
|
135 |
return '<ul class="Rk-Edit-ColorPicker">' + Rkns.pickerColors.map(function(c) { return _tmpl({c:c})}).join("") + '</ul>' |
|
136 |
})(); |
|
137 |
|
|
138 |
if (this.options.show_editor) { |
|
139 |
this.renderer = new Rkns.Renderer.Scene(this); |
|
140 |
} |
|
141 |
|
|
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
142 |
if (!this.options.search.length) { |
| 44 | 143 |
this.$.find(".Rk-Web-Search-Form").detach(); |
| 21 | 144 |
} else { |
| 196 | 145 |
var _tmpl = _.template('<li class="<%= className %>" data-key="<%= key %>"><%= title %></li>'), |
| 34 | 146 |
_select = this.$.find(".Rk-Search-List"), |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
169
diff
changeset
|
147 |
_input = this.$.find(".Rk-Web-Search-Input"), |
| 44 | 148 |
_form = this.$.find(".Rk-Web-Search-Form"); |
| 196 | 149 |
_(this.options.search).each(function(_search, _key) { |
| 160 | 150 |
if (Rkns[_search.type] && Rkns[_search.type].Search) { |
151 |
_this.search_engines.push(new Rkns[_search.type].Search(_this, _search)); |
|
152 |
} |
|
| 34 | 153 |
}); |
| 24 | 154 |
_select.html( |
| 196 | 155 |
_(this.search_engines).map(function(_search, _key) { |
| 24 | 156 |
return _tmpl({ |
157 |
key: _key, |
|
| 34 | 158 |
title: _search.getSearchTitle(), |
159 |
className: _search.getBgClass() |
|
| 24 | 160 |
}); |
| 21 | 161 |
}).join("") |
| 34 | 162 |
); |
163 |
_select.find("li").click(function() { |
|
164 |
var _el = Rkns.$(this); |
|
165 |
_this.setSearchEngine(_el.attr("data-key")); |
|
| 24 | 166 |
_form.submit(); |
167 |
}); |
|
168 |
_form.submit(function() { |
|
169 |
if (_input.val()) { |
|
| 34 | 170 |
var _search = _this.search_engine; |
171 |
_search.search(_input.val()); |
|
| 24 | 172 |
} |
173 |
return false; |
|
174 |
}); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
175 |
this.$.find(".Rk-Search-Current").mouseenter( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
176 |
function() { _select.slideDown(); } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
177 |
); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
178 |
this.$.find(".Rk-Search-Select").mouseleave( |
| 70 | 179 |
function() { _select.hide(); } |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
180 |
); |
| 34 | 181 |
this.setSearchEngine(0); |
| 21 | 182 |
} |
| 196 | 183 |
_(this.options.bins).each(function(_bin) { |
| 160 | 184 |
if (Rkns[_bin.type] && Rkns[_bin.type].Bin) { |
185 |
_this.tabs.push(new Rkns[_bin.type].Bin(_this, _bin)); |
|
186 |
} |
|
| 42 | 187 |
}); |
| 24 | 188 |
|
| 155 | 189 |
var elementDropped = false; |
190 |
|
|
| 21 | 191 |
this.$.find(".Rk-Bins") |
|
41
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
192 |
.on("click",".Rk-Bin-Title,.Rk-Bin-Title-Icon", function() { |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
193 |
var _mainDiv = Rkns.$(this).siblings(".Rk-Bin-Main"); |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
194 |
if (_mainDiv.is(":hidden")) { |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
195 |
_this.$.find(".Rk-Bin-Main").slideUp(); |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
196 |
_mainDiv.slideDown(); |
| 21 | 197 |
} |
| 188 | 198 |
}); |
199 |
|
|
200 |
if (this.options.show_editor) { |
|
201 |
|
|
202 |
this.$.find(".Rk-Bins").on("mouseover", ".Rk-Bin-Item", function(_e) { |
|
|
41
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
203 |
var _t = Rkns.$(this); |
| 26 | 204 |
if (_t && $(_t).attr("data-uri")) { |
205 |
var _models = _this.project.get("nodes").where({ |
|
206 |
uri: $(_t).attr("data-uri") |
|
207 |
}); |
|
| 196 | 208 |
_(_models).each(function(_model) { |
| 26 | 209 |
_this.renderer.highlightModel(_model); |
210 |
}); |
|
211 |
} |
|
212 |
}).mouseout(function() { |
|
213 |
_this.renderer.unhighlightAll(); |
|
| 113 | 214 |
}).on("mousemove", ".Rk-Bin-Item", function(e) { |
| 160 | 215 |
try { |
216 |
this.dragDrop(); |
|
217 |
} |
|
218 |
catch(err) {} |
|
| 155 | 219 |
}).on("touchstart", ".Rk-Bin-Item", function(e) { |
| 160 | 220 |
elementDropped = false; |
| 155 | 221 |
}).on("touchmove", ".Rk-Bin-Item", function(e) { |
| 160 | 222 |
e.preventDefault(); |
223 |
var touch = e.originalEvent.changedTouches[0], |
|
224 |
off = _this.renderer.canvas_$.offset(), |
|
225 |
w = _this.renderer.canvas_$.width(), |
|
226 |
h = _this.renderer.canvas_$.height(); |
|
227 |
if (touch.pageX >= off.left && touch.pageX < (off.left + w) && touch.pageY >= off.top && touch.pageY < (off.top + h)) { |
|
228 |
if (elementDropped) { |
|
229 |
_this.renderer.onMouseMove(touch, true); |
|
230 |
} else { |
|
231 |
elementDropped = true; |
|
232 |
var div = document.createElement('div'); |
|
233 |
div.appendChild(this.cloneNode(true)); |
|
234 |
_this.renderer.dropData({"text/html": div.innerHTML}, touch); |
|
235 |
_this.renderer.onMouseDown(touch, true); |
|
236 |
} |
|
237 |
} |
|
| 155 | 238 |
}).on("touchend", ".Rk-Bin-Item", function(e) { |
| 160 | 239 |
if (elementDropped) { |
240 |
_this.renderer.onMouseUp(e.originalEvent.changedTouches[0], true); |
|
241 |
} |
|
242 |
elementDropped = false; |
|
| 68 | 243 |
}).on("dragstart", ".Rk-Bin-Item", function(e) { |
| 160 | 244 |
var div = document.createElement('div'); |
245 |
div.appendChild(this.cloneNode(true)); |
|
246 |
try { |
|
247 |
e.originalEvent.dataTransfer.setData("text/html",div.innerHTML); |
|
248 |
} |
|
249 |
catch(err) { |
|
250 |
e.originalEvent.dataTransfer.setData("text",div.innerHTML); |
|
251 |
} |
|
| 20 | 252 |
}); |
| 188 | 253 |
|
254 |
} |
|
255 |
|
|
| 21 | 256 |
Rkns.$(window).resize(function() { |
257 |
_this.resizeBins(); |
|
| 2 | 258 |
}); |
| 44 | 259 |
|
| 196 | 260 |
var lastsearch = false, lastval = ''; |
261 |
|
|
| 44 | 262 |
this.$.find(".Rk-Bins-Search-Input").on("change keyup paste input", function() { |
| 196 | 263 |
var val = Rkns.$(this).val(); |
264 |
if (val === lastval) { |
|
265 |
return; |
|
266 |
} |
|
267 |
var search = Rkns.Utils.regexpFromTextOrArray(val.length > 1 ? val: null); |
|
268 |
if (search.source === lastsearch) { |
|
269 |
return; |
|
270 |
} |
|
271 |
lastsearch = search.source; |
|
272 |
_(_this.tabs).each(function(tab) { |
|
273 |
tab.render(search); |
|
274 |
}); |
|
275 |
|
|
| 44 | 276 |
}); |
277 |
this.$.find(".Rk-Bins-Search-Form").submit(function() { |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
169
diff
changeset
|
278 |
return false; |
| 44 | 279 |
}); |
| 195 | 280 |
|
| 163 | 281 |
}; |
| 1 | 282 |
|
| 196 | 283 |
Renkan.prototype.template = _.template( |
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
284 |
'<% if (options.show_bins) { %><div class="Rk-Bins"><div class="Rk-Bins-Head"><h2 class="Rk-Bins-Title"><%- translate("Select contents:")%></h2>' |
| 68 | 285 |
+ '<form class="Rk-Web-Search-Form Rk-Search-Form"><input class="Rk-Web-Search-Input Rk-Search-Input" type="search" placeholder="<%- translate("Search the Web") %>" />' |
| 34 | 286 |
+ '<div class="Rk-Search-Select"><div class="Rk-Search-Current"></div><ul class="Rk-Search-List"></ul></div>' |
| 119 | 287 |
+ '<input type="submit" value="" class="Rk-Web-Search-Submit Rk-Search-Submit" title="<%- translate("Search the Web") %>" /></form>' |
| 68 | 288 |
+ '<form class="Rk-Bins-Search-Form Rk-Search-Form"><input class="Rk-Bins-Search-Input Rk-Search-Input" type="search" placeholder="<%- translate("Search in Bins") %>" />' |
| 119 | 289 |
+ '<input type="submit" value="" class="Rk-Bins-Search-Submit Rk-Search-Submit" title="<%- translate("Search in Bins") %>" /></form></div>' |
| 188 | 290 |
+ '<ul class="Rk-Bin-List"></ul></div><% } %>' |
291 |
+ '<% if (options.show_editor) { %><div class="Rk-Render Rk-Render-<% if (options.show_bins) { %>Panel<% } else { %>Full<% } %>"></div><% } %>' |
|
| 20 | 292 |
); |
| 18 | 293 |
|
| 195 | 294 |
Renkan.prototype.translate = function(_text) { |
| 160 | 295 |
if (Rkns.i18n[this.options.language] && Rkns.i18n[this.options.language][_text]) { |
296 |
return Rkns.i18n[this.options.language][_text]; |
|
297 |
} |
|
298 |
if (this.options.language.length > 2 && Rkns.i18n[this.options.language.substr(0,2)] && Rkns.i18n[this.options.language.substr(0,2)][_text]) { |
|
299 |
return Rkns.i18n[this.options.language.substr(0,2)][_text]; |
|
300 |
} |
|
301 |
return _text; |
|
| 163 | 302 |
}; |
| 159 | 303 |
|
| 195 | 304 |
Renkan.prototype.onStatusChange = function() { |
| 160 | 305 |
this.renderer.onStatusChange(); |
| 163 | 306 |
}; |
| 111 | 307 |
|
| 195 | 308 |
Renkan.prototype.setSearchEngine = function(_key) { |
| 34 | 309 |
this.search_engine = this.search_engines[_key]; |
310 |
this.$.find(".Rk-Search-Current").attr("class","Rk-Search-Current " + this.search_engine.getBgClass()); |
|
| 163 | 311 |
}; |
| 34 | 312 |
|
| 195 | 313 |
Renkan.prototype.resizeBins = function() { |
| 75 | 314 |
var _d = + this.$.find(".Rk-Bins-Head").outerHeight(); |
| 44 | 315 |
this.$.find(".Rk-Bin-Title:visible").each(function() { |
| 26 | 316 |
_d += Rkns.$(this).outerHeight(); |
317 |
}); |
|
| 21 | 318 |
this.$.find(".Rk-Bin-Main").css({ |
319 |
height: this.$.find(".Rk-Bins").height() - _d |
|
320 |
}); |
|
| 163 | 321 |
}; |
| 21 | 322 |
|
| 1 | 323 |
/* Utility functions */ |
324 |
||
325 |
Rkns.Utils = { |
|
| 196 | 326 |
getUID : (function() { |
327 |
function pad(n){ |
|
328 |
return n<10 ? '0'+n : n; |
|
329 |
} |
|
| 1 | 330 |
function fillrand(n) { |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
169
diff
changeset
|
331 |
var _res = ''; |
| 1 | 332 |
for (var i=0; i<n; i++) { |
333 |
_res += Math.floor(16*Math.random()).toString(16); |
|
334 |
} |
|
335 |
return _res; |
|
336 |
} |
|
| 196 | 337 |
var _d = new Date(), |
338 |
ID_AUTO_INCREMENT = 0, |
|
339 |
ID_BASE = _d.getUTCFullYear() + '-' |
|
| 1 | 340 |
+ pad(_d.getUTCMonth()+1) + '-' |
341 |
+ pad(_d.getUTCDate()) + '-' |
|
342 |
+ fillrand(16); |
|
| 196 | 343 |
return function(_base) { |
344 |
var _n = (++ID_AUTO_INCREMENT).toString(16), |
|
345 |
_base = (typeof _base === "undefined" ? "" : _base + "-" ); |
|
346 |
while (_n.length < 4) { _n = '0' + _n; } |
|
347 |
return _base + this._ID_BASE + '-' + _n; |
|
| 1 | 348 |
} |
| 196 | 349 |
})(), |
| 132 | 350 |
getFullURL : function(url) { |
| 160 | 351 |
|
352 |
if(typeof(url) == 'undefined' || url == null ) { |
|
353 |
return ""; |
|
354 |
} |
|
355 |
if(/https?:\/\//.test(url)) { |
|
356 |
return url; |
|
357 |
} |
|
358 |
var img = new Image(); |
|
359 |
img.src = url; |
|
360 |
var res = img.src; |
|
361 |
img.src = null; |
|
362 |
return res; |
|
363 |
|
|
| 132 | 364 |
}, |
| 1 | 365 |
inherit : function(_baseClass, _callbefore) { |
| 160 | 366 |
|
| 163 | 367 |
var _class = function(_arg) { |
| 1 | 368 |
if (typeof _callbefore === "function") { |
369 |
_callbefore.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
370 |
} |
|
| 28 | 371 |
_baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |
| 163 | 372 |
if (typeof this._init == "function" && !this._initialized) { |
| 28 | 373 |
this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
| 163 | 374 |
this._initialized = true; |
| 1 | 375 |
} |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
169
diff
changeset
|
376 |
}; |
| 196 | 377 |
_(_class.prototype).extend(_baseClass.prototype); |
| 1 | 378 |
return _class; |
| 160 | 379 |
|
| 196 | 380 |
}, |
381 |
regexpFromTextOrArray: (function() { |
|
382 |
var charsub = [ |
|
383 |
'[aáàâä]', |
|
384 |
'[cç]', |
|
385 |
'[eéèêë]', |
|
386 |
'[iíìîï]', |
|
387 |
'[oóòôö]', |
|
388 |
'[uùûü]' |
|
389 |
], |
|
390 |
removeChars = [ |
|
391 |
String.fromCharCode(768), String.fromCharCode(769), String.fromCharCode(770), String.fromCharCode(771), String.fromCharCode(807), |
|
392 |
"{", "}", "(", ")", "[", "]", "【", "】", "、", "・", "‥", "。", "「", "」", "『", "』", "〜", ":", "!", "?", " ", |
|
393 |
",", " ", ";", "(", ")", ".", "*", "+", "\\", "?", "|", "{", "}", "[", "]", "^", "#", "/" |
|
394 |
], |
|
395 |
remsrc = "[\\" + removeChars.join("\\") + "]", |
|
396 |
remrx = new RegExp(remsrc, "gm"), |
|
397 |
charsrx = _(charsub).map(function(c) { |
|
398 |
return new RegExp(c); |
|
399 |
}); |
|
400 |
|
|
401 |
function replaceText(_text) { |
|
402 |
var txt = _text.toLowerCase().replace(remrx,""), src = ""; |
|
403 |
for (var j = 0; j < txt.length; j++) { |
|
404 |
if (j) { |
|
405 |
src += remsrc + "*"; |
|
406 |
} |
|
407 |
var l = txt[j]; |
|
408 |
_(charsub).each(function(v, k) { |
|
409 |
l = l.replace(charsrx[k], v); |
|
410 |
}); |
|
411 |
src += l; |
|
412 |
} |
|
413 |
return src; |
|
414 |
} |
|
415 |
|
|
416 |
function getSource(inp) { |
|
417 |
switch (typeof inp) { |
|
418 |
case "string": |
|
419 |
return replaceText(inp); |
|
420 |
case "object": |
|
421 |
var src = ''; |
|
422 |
_(inp).each(function(v) { |
|
423 |
var res = getSource(v); |
|
424 |
if (res) { |
|
425 |
if (src) { |
|
426 |
src += '|'; |
|
427 |
} |
|
428 |
src += res; |
|
429 |
} |
|
430 |
}); |
|
431 |
return src; |
|
432 |
} |
|
433 |
return ''; |
|
434 |
} |
|
435 |
|
|
436 |
return function(_textOrArray) { |
|
437 |
var source = getSource(_textOrArray); |
|
438 |
if (source) { |
|
439 |
var testrx = new RegExp( source, "im"), |
|
440 |
replacerx = new RegExp( '(' + source + ')', "igm") |
|
441 |
return { |
|
442 |
isempty: false, |
|
443 |
source: source, |
|
444 |
test: function(_t) { return testrx.test(_t) }, |
|
445 |
replace: function(_text, _replace) { return _text.replace(replacerx, _replace); } |
|
446 |
} |
|
447 |
} else { |
|
448 |
return { |
|
449 |
isempty: true, |
|
450 |
source: '', |
|
451 |
test: function() { return true }, |
|
452 |
replace: function(_text) { return text } |
|
453 |
} |
|
454 |
} |
|
455 |
} |
|
456 |
})() |
|
| 163 | 457 |
}; |
| 195 | 458 |
})(window); |
| 188 | 459 |
|
460 |
/* END main.js */ |