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