--- a/client/js/main.js Tue Apr 23 22:14:59 2013 +0200
+++ b/client/js/main.js Tue Apr 23 22:15:10 2013 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 Institut de recherche et d'innovation
+ * Copyright 2012-2013 Institut de recherche et d'innovation
* contributor(s) : Yves-Marie Haussonne, Raphael Velt, Samuel Huron
*
* contact@iri.centrepompidou.fr
@@ -52,25 +52,25 @@
Rkns.$('<a>')
.attr({
- href: "#",
- title: _renkan.translate("Close bin")
- })
+ href: "#",
+ title: _renkan.translate("Close bin")
+ })
.addClass("Rk-Bin-Close")
.html('×')
.appendTo(this.$)
.click(function() {
_this.destroy();
if (!_renkan.$.find(".Rk-Bin-Main:visible").length) {
- _renkan.$.find(".Rk-Bin-Main:last").slideDown();
+ _renkan.$.find(".Rk-Bin-Main:last").slideDown();
}
_renkan.resizeBins();
return false;
});
Rkns.$('<a>')
.attr({
- href: "#",
- title: _renkan.translate("Refresh bin")
- })
+ href: "#",
+ title: _renkan.translate("Refresh bin")
+ })
.addClass("Rk-Bin-Refresh")
.appendTo(this.$)
.click(function() {
@@ -96,12 +96,12 @@
},_opts.auto_refresh)
}
}
-}
+};
Rkns._BaseBin.prototype.destroy = function() {
this.$.detach();
this.renkan.resizeBins();
-}
+};
/* Point of entry */
@@ -110,19 +110,16 @@
this.options = _.defaults(_opts, Rkns.defaults);
- Rkns._(this.options.property_files).each(function(f) {
- Rkns.$.getJSON(f, function(data) {
- _this.options.properties = _this.options.properties.concat(data);
- });
- });
+ Rkns._(this.options.property_files).each(function(f) {
+ Rkns.$.getJSON(f, function(data) {
+ _this.options.properties = _this.options.properties.concat(data);
+ });
+ });
this.read_only = this.options.read_only || !this.options.editor_mode;
this.project = new Rkns.Models.Project();
- this.translate = function(_text) {
- return (Rkns.i18n[_this.options.language] || Rkns.i18n[_this.options.language.substr(0,2)] || {})[_text] || _text;
- }
if (typeof this.options.user_id !== "undefined") {
this.current_user = this.options.user_id;
}
@@ -144,9 +141,9 @@
_input = this.$.find(".Rk-Web-Search-Input")
_form = this.$.find(".Rk-Web-Search-Form");
Rkns._(this.options.search).each(function(_search, _key) {
- if (Rkns[_search.type] && Rkns[_search.type].Search) {
- _this.search_engines.push(new Rkns[_search.type].Search(_this, _search));
- }
+ if (Rkns[_search.type] && Rkns[_search.type].Search) {
+ _this.search_engines.push(new Rkns[_search.type].Search(_this, _search));
+ }
});
_select.html(
Rkns._(this.search_engines).map(function(_search, _key) {
@@ -178,11 +175,13 @@
this.setSearchEngine(0);
}
Rkns._(this.options.bins).each(function(_bin) {
- if (Rkns[_bin.type] && Rkns[_bin.type].Bin) {
- _this.tabs.push(new Rkns[_bin.type].Bin(_this, _bin));
- }
+ if (Rkns[_bin.type] && Rkns[_bin.type].Bin) {
+ _this.tabs.push(new Rkns[_bin.type].Bin(_this, _bin));
+ }
});
+ var elementDropped = false;
+
this.$.find(".Rk-Bins")
.on("click",".Rk-Bin-Title,.Rk-Bin-Title-Icon", function() {
var _mainDiv = Rkns.$(this).siblings(".Rk-Bin-Main");
@@ -203,19 +202,43 @@
}).mouseout(function() {
_this.renderer.unhighlightAll();
}).on("mousemove", ".Rk-Bin-Item", function(e) {
- try {
- this.dragDrop();
- }
- catch(err) {}
+ try {
+ this.dragDrop();
+ }
+ catch(err) {}
+ }).on("touchstart", ".Rk-Bin-Item", function(e) {
+ elementDropped = false;
+ }).on("touchmove", ".Rk-Bin-Item", function(e) {
+ e.preventDefault();
+ var touch = e.originalEvent.changedTouches[0],
+ off = _this.renderer.canvas_$.offset(),
+ w = _this.renderer.canvas_$.width(),
+ h = _this.renderer.canvas_$.height();
+ if (touch.pageX >= off.left && touch.pageX < (off.left + w) && touch.pageY >= off.top && touch.pageY < (off.top + h)) {
+ if (elementDropped) {
+ _this.renderer.onMouseMove(touch, true);
+ } else {
+ elementDropped = true;
+ var div = document.createElement('div');
+ div.appendChild(this.cloneNode(true));
+ _this.renderer.dropData({"text/html": div.innerHTML}, touch);
+ _this.renderer.onMouseDown(touch, true);
+ }
+ }
+ }).on("touchend", ".Rk-Bin-Item", function(e) {
+ if (elementDropped) {
+ _this.renderer.onMouseUp(e.originalEvent.changedTouches[0], true);
+ }
+ elementDropped = false;
}).on("dragstart", ".Rk-Bin-Item", function(e) {
- var div = document.createElement('div');
- div.appendChild(this.cloneNode(true));
- try {
- e.originalEvent.dataTransfer.setData("text/html",div.innerHTML);
- }
- catch(err) {
- e.originalEvent.dataTransfer.setData("text",div.innerHTML);
- }
+ var div = document.createElement('div');
+ div.appendChild(this.cloneNode(true));
+ try {
+ e.originalEvent.dataTransfer.setData("text/html",div.innerHTML);
+ }
+ catch(err) {
+ e.originalEvent.dataTransfer.setData("text",div.innerHTML);
+ }
});
Rkns.$(window).resize(function() {
_this.resizeBins();
@@ -230,7 +253,7 @@
this.$.find(".Rk-Bins-Search-Form").submit(function() {
return false
});
-}
+};
Rkns.Renkan.prototype.template = Rkns._.template(
'<% if (options.show_bins) { %><div class="Rk-Bins"><div class="Rk-Bins-Head"><h2 class="Rk-Bins-Title"><%- translate("Select contents:")%></h2>'
@@ -242,15 +265,24 @@
+ '<ul class="Rk-Bin-List"></ul></div><% } %><div class="Rk-Render Rk-Render-<% if (options.show_bins) { %>Panel<% } else { %>Full<% } %>"></div>'
);
+Rkns.Renkan.prototype.translate = function(_text) {
+ if (Rkns.i18n[this.options.language] && Rkns.i18n[this.options.language][_text]) {
+ return Rkns.i18n[this.options.language][_text];
+ }
+ if (this.options.language.length > 2 && Rkns.i18n[this.options.language.substr(0,2)] && Rkns.i18n[this.options.language.substr(0,2)][_text]) {
+ return Rkns.i18n[this.options.language.substr(0,2)][_text];
+ }
+ return _text;
+};
+
Rkns.Renkan.prototype.onStatusChange = function() {
- this.renderer.onStatusChange();
-}
-
+ this.renderer.onStatusChange();
+};
Rkns.Renkan.prototype.setSearchEngine = function(_key) {
this.search_engine = this.search_engines[_key];
this.$.find(".Rk-Search-Current").attr("class","Rk-Search-Current " + this.search_engine.getBgClass());
-}
+};
Rkns.Renkan.prototype.resizeBins = function() {
var _d = + this.$.find(".Rk-Bins-Head").outerHeight();
@@ -260,13 +292,14 @@
this.$.find(".Rk-Bin-Main").css({
height: this.$.find(".Rk-Bins").height() - _d
});
-}
+};
/* Utility functions */
Rkns.Utils = {
_ID_AUTO_INCREMENT : 0,
_ID_BASE : (function(_d) {
+
function pad(n){return n<10 ? '0'+n : n}
function fillrand(n) {
var _res = ''
@@ -279,40 +312,47 @@
+ pad(_d.getUTCMonth()+1) + '-'
+ pad(_d.getUTCDate()) + '-'
+ fillrand(16);
+
})(new Date()),
getUID : function(_base) {
+
var _n = (++this._ID_AUTO_INCREMENT).toString(16),
_base = (typeof _base === "undefined" ? "" : _base + "-" );
while (_n.length < 4) {
_n = '0' + _n
}
return _base + this._ID_BASE + '-' + _n;
+
},
getFullURL : function(url) {
-
- if(typeof(url) == 'undefined' || url == null ) {
- return "";
- }
- if(url.indexOf("http://")==0) {
- return url;
- }
- var img = new Image();
- img.src = url;
- var res = img.src;
- img.src = null;
- return res;
+
+ if(typeof(url) == 'undefined' || url == null ) {
+ return "";
+ }
+ if(/https?:\/\//.test(url)) {
+ return url;
+ }
+ var img = new Image();
+ img.src = url;
+ var res = img.src;
+ img.src = null;
+ return res;
+
},
inherit : function(_baseClass, _callbefore) {
- var _class = function() {
+
+ var _class = function(_arg) {
if (typeof _callbefore === "function") {
_callbefore.apply(this, Array.prototype.slice.call(arguments, 0));
}
_baseClass.apply(this, Array.prototype.slice.call(arguments, 0));
- if (typeof this._init == "function") {
+ if (typeof this._init == "function" && !this._initialized) {
this._init.apply(this, Array.prototype.slice.call(arguments, 0));
+ this._initialized = true;
}
}
- _class.prototype = new _baseClass();
+ Rkns._(_class.prototype).extend(_baseClass.prototype);
return _class;
+
}
-}
\ No newline at end of file
+};