108 Rkns.Renkan = function(_opts) { |
108 Rkns.Renkan = function(_opts) { |
109 var _this = this; |
109 var _this = this; |
110 |
110 |
111 this.options = _.defaults(_opts, Rkns.defaults); |
111 this.options = _.defaults(_opts, Rkns.defaults); |
112 |
112 |
113 Rkns._(this.options.property_files).each(function(f) { |
113 Rkns._(this.options.property_files).each(function(f) { |
114 Rkns.$.getJSON(f, function(data) { |
114 Rkns.$.getJSON(f, function(data) { |
115 _this.options.properties = _this.options.properties.concat(data); |
115 _this.options.properties = _this.options.properties.concat(data); |
116 }); |
116 }); |
117 }); |
117 }); |
118 |
118 |
119 this.read_only = this.options.read_only || !this.options.editor_mode; |
119 this.read_only = this.options.read_only || !this.options.editor_mode; |
120 |
120 |
121 this.project = new Rkns.Models.Project(); |
121 this.project = new Rkns.Models.Project(); |
122 |
122 |
139 var _tmpl = Rkns._.template('<li class="<%= className %>" data-key="<%= key %>"><%= title %></li>'), |
139 var _tmpl = Rkns._.template('<li class="<%= className %>" data-key="<%= key %>"><%= title %></li>'), |
140 _select = this.$.find(".Rk-Search-List"), |
140 _select = this.$.find(".Rk-Search-List"), |
141 _input = this.$.find(".Rk-Web-Search-Input") |
141 _input = this.$.find(".Rk-Web-Search-Input") |
142 _form = this.$.find(".Rk-Web-Search-Form"); |
142 _form = this.$.find(".Rk-Web-Search-Form"); |
143 Rkns._(this.options.search).each(function(_search, _key) { |
143 Rkns._(this.options.search).each(function(_search, _key) { |
144 if (Rkns[_search.type] && Rkns[_search.type].Search) { |
144 if (Rkns[_search.type] && Rkns[_search.type].Search) { |
145 _this.search_engines.push(new Rkns[_search.type].Search(_this, _search)); |
145 _this.search_engines.push(new Rkns[_search.type].Search(_this, _search)); |
146 } |
146 } |
147 }); |
147 }); |
148 _select.html( |
148 _select.html( |
149 Rkns._(this.search_engines).map(function(_search, _key) { |
149 Rkns._(this.search_engines).map(function(_search, _key) { |
150 return _tmpl({ |
150 return _tmpl({ |
151 key: _key, |
151 key: _key, |
200 }); |
200 }); |
201 } |
201 } |
202 }).mouseout(function() { |
202 }).mouseout(function() { |
203 _this.renderer.unhighlightAll(); |
203 _this.renderer.unhighlightAll(); |
204 }).on("mousemove", ".Rk-Bin-Item", function(e) { |
204 }).on("mousemove", ".Rk-Bin-Item", function(e) { |
205 try { |
205 try { |
206 this.dragDrop(); |
206 this.dragDrop(); |
207 } |
207 } |
208 catch(err) {} |
208 catch(err) {} |
209 }).on("touchstart", ".Rk-Bin-Item", function(e) { |
209 }).on("touchstart", ".Rk-Bin-Item", function(e) { |
210 elementDropped = false; |
210 elementDropped = false; |
211 }).on("touchmove", ".Rk-Bin-Item", function(e) { |
211 }).on("touchmove", ".Rk-Bin-Item", function(e) { |
212 e.preventDefault(); |
212 e.preventDefault(); |
213 var touch = e.originalEvent.changedTouches[0], |
213 var touch = e.originalEvent.changedTouches[0], |
214 off = _this.renderer.canvas_$.offset(), |
214 off = _this.renderer.canvas_$.offset(), |
215 w = _this.renderer.canvas_$.width(), |
215 w = _this.renderer.canvas_$.width(), |
216 h = _this.renderer.canvas_$.height(); |
216 h = _this.renderer.canvas_$.height(); |
217 if (touch.pageX >= off.left && touch.pageX < (off.left + w) && touch.pageY >= off.top && touch.pageY < (off.top + h)) { |
217 if (touch.pageX >= off.left && touch.pageX < (off.left + w) && touch.pageY >= off.top && touch.pageY < (off.top + h)) { |
218 if (elementDropped) { |
218 if (elementDropped) { |
219 _this.renderer.onMouseMove(touch, true); |
219 _this.renderer.onMouseMove(touch, true); |
220 } else { |
220 } else { |
221 elementDropped = true; |
221 elementDropped = true; |
222 var div = document.createElement('div'); |
222 var div = document.createElement('div'); |
223 div.appendChild(this.cloneNode(true)); |
223 div.appendChild(this.cloneNode(true)); |
224 _this.renderer.dropData({"text/html": div.innerHTML}, touch); |
224 _this.renderer.dropData({"text/html": div.innerHTML}, touch); |
225 _this.renderer.onMouseDown(touch, true); |
225 _this.renderer.onMouseDown(touch, true); |
226 } |
226 } |
227 } |
227 } |
228 }).on("touchend", ".Rk-Bin-Item", function(e) { |
228 }).on("touchend", ".Rk-Bin-Item", function(e) { |
229 if (elementDropped) { |
229 if (elementDropped) { |
230 _this.renderer.onMouseUp(e.originalEvent.changedTouches[0], true); |
230 _this.renderer.onMouseUp(e.originalEvent.changedTouches[0], true); |
231 } |
231 } |
232 elementDropped = false; |
232 elementDropped = false; |
233 }).on("dragstart", ".Rk-Bin-Item", function(e) { |
233 }).on("dragstart", ".Rk-Bin-Item", function(e) { |
234 var div = document.createElement('div'); |
234 var div = document.createElement('div'); |
235 div.appendChild(this.cloneNode(true)); |
235 div.appendChild(this.cloneNode(true)); |
236 try { |
236 try { |
237 e.originalEvent.dataTransfer.setData("text/html",div.innerHTML); |
237 e.originalEvent.dataTransfer.setData("text/html",div.innerHTML); |
238 } |
238 } |
239 catch(err) { |
239 catch(err) { |
240 e.originalEvent.dataTransfer.setData("text",div.innerHTML); |
240 e.originalEvent.dataTransfer.setData("text",div.innerHTML); |
241 } |
241 } |
242 }); |
242 }); |
243 Rkns.$(window).resize(function() { |
243 Rkns.$(window).resize(function() { |
244 _this.resizeBins(); |
244 _this.resizeBins(); |
245 }); |
245 }); |
246 |
246 |
264 + '<input type="submit" value="" class="Rk-Bins-Search-Submit Rk-Search-Submit" title="<%- translate("Search in Bins") %>" /></form></div>' |
264 + '<input type="submit" value="" class="Rk-Bins-Search-Submit Rk-Search-Submit" title="<%- translate("Search in Bins") %>" /></form></div>' |
265 + '<ul class="Rk-Bin-List"></ul></div><% } %><div class="Rk-Render Rk-Render-<% if (options.show_bins) { %>Panel<% } else { %>Full<% } %>"></div>' |
265 + '<ul class="Rk-Bin-List"></ul></div><% } %><div class="Rk-Render Rk-Render-<% if (options.show_bins) { %>Panel<% } else { %>Full<% } %>"></div>' |
266 ); |
266 ); |
267 |
267 |
268 Rkns.Renkan.prototype.translate = function(_text) { |
268 Rkns.Renkan.prototype.translate = function(_text) { |
269 if (Rkns.i18n[this.options.language] && Rkns.i18n[this.options.language][_text]) { |
269 if (Rkns.i18n[this.options.language] && Rkns.i18n[this.options.language][_text]) { |
270 return Rkns.i18n[this.options.language][_text]; |
270 return Rkns.i18n[this.options.language][_text]; |
271 } |
271 } |
272 if (this.options.language.length > 2 && Rkns.i18n[this.options.language.substr(0,2)] && Rkns.i18n[this.options.language.substr(0,2)][_text]) { |
272 if (this.options.language.length > 2 && Rkns.i18n[this.options.language.substr(0,2)] && Rkns.i18n[this.options.language.substr(0,2)][_text]) { |
273 return Rkns.i18n[this.options.language.substr(0,2)][_text]; |
273 return Rkns.i18n[this.options.language.substr(0,2)][_text]; |
274 } |
274 } |
275 return _text; |
275 return _text; |
276 } |
276 } |
277 |
277 |
278 Rkns.Renkan.prototype.onStatusChange = function() { |
278 Rkns.Renkan.prototype.onStatusChange = function() { |
279 this.renderer.onStatusChange(); |
279 this.renderer.onStatusChange(); |
280 } |
280 } |
281 |
281 |
282 Rkns.Renkan.prototype.setSearchEngine = function(_key) { |
282 Rkns.Renkan.prototype.setSearchEngine = function(_key) { |
283 this.search_engine = this.search_engines[_key]; |
283 this.search_engine = this.search_engines[_key]; |
284 this.$.find(".Rk-Search-Current").attr("class","Rk-Search-Current " + this.search_engine.getBgClass()); |
284 this.$.find(".Rk-Search-Current").attr("class","Rk-Search-Current " + this.search_engine.getBgClass()); |
309 } |
310 } |
310 return _d.getUTCFullYear() + '-' |
311 return _d.getUTCFullYear() + '-' |
311 + pad(_d.getUTCMonth()+1) + '-' |
312 + pad(_d.getUTCMonth()+1) + '-' |
312 + pad(_d.getUTCDate()) + '-' |
313 + pad(_d.getUTCDate()) + '-' |
313 + fillrand(16); |
314 + fillrand(16); |
|
315 |
314 })(new Date()), |
316 })(new Date()), |
315 getUID : function(_base) { |
317 getUID : function(_base) { |
|
318 |
316 var _n = (++this._ID_AUTO_INCREMENT).toString(16), |
319 var _n = (++this._ID_AUTO_INCREMENT).toString(16), |
317 _base = (typeof _base === "undefined" ? "" : _base + "-" ); |
320 _base = (typeof _base === "undefined" ? "" : _base + "-" ); |
318 while (_n.length < 4) { |
321 while (_n.length < 4) { |
319 _n = '0' + _n |
322 _n = '0' + _n |
320 } |
323 } |
321 return _base + this._ID_BASE + '-' + _n; |
324 return _base + this._ID_BASE + '-' + _n; |
|
325 |
322 }, |
326 }, |
323 getFullURL : function(url) { |
327 getFullURL : function(url) { |
324 |
328 |
325 if(typeof(url) == 'undefined' || url == null ) { |
329 if(typeof(url) == 'undefined' || url == null ) { |
326 return ""; |
330 return ""; |
327 } |
331 } |
328 if(url.indexOf("http://")==0) { |
332 if(/https?:\/\//.test(url)) { |
329 return url; |
333 return url; |
330 } |
334 } |
331 var img = new Image(); |
335 var img = new Image(); |
332 img.src = url; |
336 img.src = url; |
333 var res = img.src; |
337 var res = img.src; |
334 img.src = null; |
338 img.src = null; |
335 return res; |
339 return res; |
|
340 |
336 }, |
341 }, |
337 inherit : function(_baseClass, _callbefore) { |
342 inherit : function(_baseClass, _callbefore) { |
|
343 |
338 var _class = function() { |
344 var _class = function() { |
339 if (typeof _callbefore === "function") { |
345 if (typeof _callbefore === "function") { |
340 _callbefore.apply(this, Array.prototype.slice.call(arguments, 0)); |
346 _callbefore.apply(this, Array.prototype.slice.call(arguments, 0)); |
341 } |
347 } |
342 _baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |
348 _baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |