client/js/main.js
changeset 160 408da84d4dc0
parent 159 1796e0220bef
child 163 fca0475da9a7
equal deleted inserted replaced
159:1796e0220bef 160:408da84d4dc0
    50             
    50             
    51         var _this = this;
    51         var _this = this;
    52         
    52         
    53         Rkns.$('<a>')
    53         Rkns.$('<a>')
    54             .attr({
    54             .attr({
    55             	href: "#",
    55                 href: "#",
    56             	title: _renkan.translate("Close bin")
    56                 title: _renkan.translate("Close bin")
    57         	})
    57             })
    58             .addClass("Rk-Bin-Close")
    58             .addClass("Rk-Bin-Close")
    59             .html('&times;')
    59             .html('&times;')
    60             .appendTo(this.$)
    60             .appendTo(this.$)
    61             .click(function() {
    61             .click(function() {
    62                 _this.destroy();
    62                 _this.destroy();
    63                 if (!_renkan.$.find(".Rk-Bin-Main:visible").length) {
    63                 if (!_renkan.$.find(".Rk-Bin-Main:visible").length) {
    64                 	_renkan.$.find(".Rk-Bin-Main:last").slideDown();
    64                     _renkan.$.find(".Rk-Bin-Main:last").slideDown();
    65                 }
    65                 }
    66                 _renkan.resizeBins();
    66                 _renkan.resizeBins();
    67                 return false;
    67                 return false;
    68             });
    68             });
    69         Rkns.$('<a>')
    69         Rkns.$('<a>')
    70             .attr({
    70             .attr({
    71             	href: "#",
    71                 href: "#",
    72             	title: _renkan.translate("Refresh bin")
    72                 title: _renkan.translate("Refresh bin")
    73         	})
    73             })
    74             .addClass("Rk-Bin-Refresh")
    74             .addClass("Rk-Bin-Refresh")
    75             .appendTo(this.$)
    75             .appendTo(this.$)
    76             .click(function() {
    76             .click(function() {
    77                 _this.refresh();
    77                 _this.refresh();
    78                 return false;
    78                 return false;
   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,
   173             function() { _select.hide(); }
   173             function() { _select.hide(); }
   174         );
   174         );
   175         this.setSearchEngine(0);
   175         this.setSearchEngine(0);
   176     }
   176     }
   177     Rkns._(this.options.bins).each(function(_bin) {
   177     Rkns._(this.options.bins).each(function(_bin) {
   178     	if (Rkns[_bin.type] && Rkns[_bin.type].Bin) {
   178         if (Rkns[_bin.type] && Rkns[_bin.type].Bin) {
   179     		_this.tabs.push(new Rkns[_bin.type].Bin(_this, _bin));
   179             _this.tabs.push(new Rkns[_bin.type].Bin(_this, _bin));
   180     	}
   180         }
   181     });
   181     });
   182     
   182     
   183     var elementDropped = false;
   183     var elementDropped = false;
   184     
   184     
   185     this.$.find(".Rk-Bins")
   185     this.$.find(".Rk-Bins")
   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());
   297 /* Utility functions */
   297 /* Utility functions */
   298 
   298 
   299 Rkns.Utils = {
   299 Rkns.Utils = {
   300     _ID_AUTO_INCREMENT : 0,
   300     _ID_AUTO_INCREMENT : 0,
   301     _ID_BASE : (function(_d) {
   301     _ID_BASE : (function(_d) {
       
   302         
   302         function pad(n){return n<10 ? '0'+n : n}
   303         function pad(n){return n<10 ? '0'+n : n}
   303         function fillrand(n) {
   304         function fillrand(n) {
   304             var _res = ''
   305             var _res = ''
   305             for (var i=0; i<n; i++) {
   306             for (var i=0; i<n; i++) {
   306                 _res += Math.floor(16*Math.random()).toString(16);
   307                 _res += Math.floor(16*Math.random()).toString(16);
   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));
   344                 this._init.apply(this, Array.prototype.slice.call(arguments, 0));
   350                 this._init.apply(this, Array.prototype.slice.call(arguments, 0));
   345             }
   351             }
   346         }
   352         }
   347         _class.prototype = new _baseClass();
   353         _class.prototype = new _baseClass();
   348         return _class;
   354         return _class;
   349     }
   355         
   350 }
   356     }
       
   357 }