client/js/main.js
changeset 293 fba23fde14ba
parent 290 8a6eb26ac87f
child 298 2f35c2ae7de8
equal deleted inserted replaced
292:f67047a16084 293:fba23fde14ba
    32             .addClass("Rk-Bin")
    32             .addClass("Rk-Bin")
    33             .appendTo(_renkan.$.find(".Rk-Bin-List"));
    33             .appendTo(_renkan.$.find(".Rk-Bin-List"));
    34         this.title_icon_$ = Rkns.$('<span>')
    34         this.title_icon_$ = Rkns.$('<span>')
    35             .addClass("Rk-Bin-Title-Icon")
    35             .addClass("Rk-Bin-Title-Icon")
    36             .appendTo(this.$);
    36             .appendTo(this.$);
    37             
    37 
    38         var _this = this;
    38         var _this = this;
    39         
    39 
    40         Rkns.$('<a>')
    40         Rkns.$('<a>')
    41             .attr({
    41             .attr({
    42                 href: "#",
    42                 href: "#",
    43                 title: _renkan.translate("Close bin")
    43                 title: _renkan.translate("Close bin")
    44             })
    44             })
    74             .addClass("Rk-Bin-Main")
    74             .addClass("Rk-Bin-Main")
    75             .appendTo(this.$)
    75             .appendTo(this.$)
    76             .html('<h4 class="Rk-Bin-Loading">' + _renkan.translate("Loading, please wait") + '</h4>');
    76             .html('<h4 class="Rk-Bin-Loading">' + _renkan.translate("Loading, please wait") + '</h4>');
    77         this.title_$.html(_opts.title || '(new bin)');
    77         this.title_$.html(_opts.title || '(new bin)');
    78         this.renkan.resizeBins();
    78         this.renkan.resizeBins();
    79         
    79 
    80         if (_opts.auto_refresh) {
    80         if (_opts.auto_refresh) {
    81             window.setInterval(function() {
    81             window.setInterval(function() {
    82                 _this.refresh();
    82                 _this.refresh();
    83             },_opts.auto_refresh);
    83             },_opts.auto_refresh);
    84         }
    84         }
    92 
    92 
    93 /* Point of entry */
    93 /* Point of entry */
    94 
    94 
    95 var Renkan = Rkns.Renkan = function(_opts) {
    95 var Renkan = Rkns.Renkan = function(_opts) {
    96     var _this = this;
    96     var _this = this;
    97     
    97 
    98     Rkns.__renkans.push(this);
    98     Rkns.__renkans.push(this);
    99     
    99 
   100     this.options = _.defaults(_opts, Rkns.defaults);
   100     this.options = _.defaults(_opts, Rkns.defaults);
   101         
   101 
   102     _(this.options.property_files).each(function(f) {
   102     _(this.options.property_files).each(function(f) {
   103         Rkns.$.getJSON(f, function(data) {
   103         Rkns.$.getJSON(f, function(data) {
   104             _this.options.properties = _this.options.properties.concat(data);
   104             _this.options.properties = _this.options.properties.concat(data);
   105         });
   105         });
   106     });
   106     });
   107     
   107 
   108     this.read_only = this.options.read_only || !this.options.editor_mode;
   108     this.read_only = this.options.read_only || !this.options.editor_mode;
   109 
   109 
   110     this.project = new Rkns.Models.Project();
   110     this.project = new Rkns.Models.Project();
   111     
   111 
   112     if (typeof this.options.user_id !== "undefined") {
   112     if (typeof this.options.user_id !== "undefined") {
   113         this.current_user = this.options.user_id;
   113         this.current_user = this.options.user_id;
   114     }
   114     }
   115     this.$ = Rkns.$("#" + this.options.container);
   115     this.$ = Rkns.$("#" + this.options.container);
   116     this.$
   116     this.$
   117         .addClass("Rk-Main")
   117         .addClass("Rk-Main")
   118         .html(this.template(this));
   118         .html(this.template(this));
   119     
   119 
   120     this.tabs = [];
   120     this.tabs = [];
   121     this.search_engines = [];
   121     this.search_engines = [];
   122 
   122 
   123     this.current_user_list = new Rkns.Models.UsersList();
   123     this.current_user_list = new Rkns.Models.UsersList();
   124     
   124 
   125     this.current_user_list.on("add remove", function() {
   125     this.current_user_list.on("add remove", function() {
   126         if (this.renderer) {
   126         if (this.renderer) {
   127             this.renderer.redrawUsers();
   127             this.renderer.redrawUsers();
   128         }
   128         }
   129     });
   129     });
   130     
   130 
   131     this.colorPicker = (function() {
   131     this.colorPicker = (function() {
   132         var _tmpl = _.template('<li data-color="<%=c%>" style="background: <%=c%>"></li>');
   132         var _tmpl = _.template('<li data-color="<%=c%>" style="background: <%=c%>"></li>');
   133         return '<ul class="Rk-Edit-ColorPicker">' + Rkns.pickerColors.map(function(c) { return _tmpl({c:c})}).join("") + '</ul>'
   133         return '<ul class="Rk-Edit-ColorPicker">' + Rkns.pickerColors.map(function(c) { return _tmpl({c:c});}).join("") + '</ul>';
   134     })();
   134     })();
   135     
   135 
   136     if (this.options.show_editor) {
   136     if (this.options.show_editor) {
   137         this.renderer = new Rkns.Renderer.Scene(this);
   137         this.renderer = new Rkns.Renderer.Scene(this);
   138     }
   138     }
   139     
   139 
   140     if (!this.options.search.length) {
   140     if (!this.options.search.length) {
   141         this.$.find(".Rk-Web-Search-Form").detach();
   141         this.$.find(".Rk-Web-Search-Form").detach();
   142     } else {
   142     } else {
   143         var _tmpl = _.template('<li class="<%= className %>" data-key="<%= key %>"><%= title %></li>'),
   143         var _tmpl = _.template('<li class="<%= className %>" data-key="<%= key %>"><%= title %></li>'),
   144             _select = this.$.find(".Rk-Search-List"),
   144             _select = this.$.find(".Rk-Search-List"),
   181     _(this.options.bins).each(function(_bin) {
   181     _(this.options.bins).each(function(_bin) {
   182         if (Rkns[_bin.type] && Rkns[_bin.type].Bin) {
   182         if (Rkns[_bin.type] && Rkns[_bin.type].Bin) {
   183             _this.tabs.push(new Rkns[_bin.type].Bin(_this, _bin));
   183             _this.tabs.push(new Rkns[_bin.type].Bin(_this, _bin));
   184         }
   184         }
   185     });
   185     });
   186     
   186 
   187     var elementDropped = false;
   187     var elementDropped = false;
   188     
   188 
   189     this.$.find(".Rk-Bins")
   189     this.$.find(".Rk-Bins")
   190         .on("click",".Rk-Bin-Title,.Rk-Bin-Title-Icon", function() {
   190         .on("click",".Rk-Bin-Title,.Rk-Bin-Title-Icon", function() {
   191             var _mainDiv = Rkns.$(this).siblings(".Rk-Bin-Main");
   191             var _mainDiv = Rkns.$(this).siblings(".Rk-Bin-Main");
   192             if (_mainDiv.is(":hidden")) {
   192             if (_mainDiv.is(":hidden")) {
   193                 _this.$.find(".Rk-Bin-Main").slideUp();
   193                 _this.$.find(".Rk-Bin-Main").slideUp();
   194                 _mainDiv.slideDown();
   194                 _mainDiv.slideDown();
   195             }
   195             }
   196         });
   196         });
   197     
   197 
   198     if (this.options.show_editor) {
   198     if (this.options.show_editor) {
   199         
   199 
   200         this.$.find(".Rk-Bins").on("mouseover", ".Rk-Bin-Item", function(_e) {
   200         this.$.find(".Rk-Bins").on("mouseover", ".Rk-Bin-Item", function(_e) {
   201             var _t = Rkns.$(this);
   201             var _t = Rkns.$(this);
   202             if (_t && $(_t).attr("data-uri")) {
   202             if (_t && $(_t).attr("data-uri")) {
   203                 var _models = _this.project.get("nodes").where({
   203                 var _models = _this.project.get("nodes").where({
   204                     uri: $(_t).attr("data-uri")
   204                     uri: $(_t).attr("data-uri")
   246             }
   246             }
   247             catch(err) {
   247             catch(err) {
   248                 e.originalEvent.dataTransfer.setData("text",div.innerHTML);
   248                 e.originalEvent.dataTransfer.setData("text",div.innerHTML);
   249             }
   249             }
   250         });
   250         });
   251         
   251 
   252     }
   252     }
   253     
   253 
   254     Rkns.$(window).resize(function() {
   254     Rkns.$(window).resize(function() {
   255         _this.resizeBins();
   255         _this.resizeBins();
   256     });
   256     });
   257     
   257 
   258     var lastsearch = false, lastval = '';
   258     var lastsearch = false, lastval = '';
   259     
   259 
   260     this.$.find(".Rk-Bins-Search-Input").on("change keyup paste input", function() {
   260     this.$.find(".Rk-Bins-Search-Input").on("change keyup paste input", function() {
   261         var val = Rkns.$(this).val();
   261         var val = Rkns.$(this).val();
   262         if (val === lastval) {
   262         if (val === lastval) {
   263             return;
   263             return;
   264         }
   264         }
   268         }
   268         }
   269         lastsearch = search.source;
   269         lastsearch = search.source;
   270         _(_this.tabs).each(function(tab) {
   270         _(_this.tabs).each(function(tab) {
   271             tab.render(search);
   271             tab.render(search);
   272         });
   272         });
   273         
   273 
   274     });
   274     });
   275     this.$.find(".Rk-Bins-Search-Form").submit(function() {
   275     this.$.find(".Rk-Bins-Search-Form").submit(function() {
   276         return false;
   276         return false;
   277     });
   277     });
   278     
   278 
   279 };
   279 };
   280 
   280 
   281 Renkan.prototype.template = _.template(
   281 Renkan.prototype.template = _.template(
   282     '<% if (options.show_bins) { %><div class="Rk-Bins"><div class="Rk-Bins-Head"><h2 class="Rk-Bins-Title"><%- translate("Select contents:")%></h2>'
   282     '<% if (options.show_bins) { %><div class="Rk-Bins"><div class="Rk-Bins-Head"><h2 class="Rk-Bins-Title"><%- translate("Select contents:")%></h2>' +
   283     + '<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") %>" />'
   283     '<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") %>" />' +
   284     + '<div class="Rk-Search-Select"><div class="Rk-Search-Current"></div><ul class="Rk-Search-List"></ul></div>'
   284     '<div class="Rk-Search-Select"><div class="Rk-Search-Current"></div><ul class="Rk-Search-List"></ul></div>' +
   285     + '<input type="submit" value="" class="Rk-Web-Search-Submit Rk-Search-Submit" title="<%- translate("Search the Web") %>" /></form>'
   285     '<input type="submit" value="" class="Rk-Web-Search-Submit Rk-Search-Submit" title="<%- translate("Search the Web") %>" /></form>' +
   286     + '<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") %>" />'
   286     '<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") %>" />' +
   287     + '<input type="submit" value="" class="Rk-Bins-Search-Submit Rk-Search-Submit" title="<%- translate("Search in Bins") %>" /></form></div>'
   287     '<input type="submit" value="" class="Rk-Bins-Search-Submit Rk-Search-Submit" title="<%- translate("Search in Bins") %>" /></form></div>' +
   288     + '<ul class="Rk-Bin-List"></ul></div><% } %>'
   288     '<ul class="Rk-Bin-List"></ul></div><% } %>' +
   289     + '<% if (options.show_editor) { %><div class="Rk-Render Rk-Render-<% if (options.show_bins) { %>Panel<% } else { %>Full<% } %>"></div><% } %>'
   289     '<% if (options.show_editor) { %><div class="Rk-Render Rk-Render-<% if (options.show_bins) { %>Panel<% } else { %>Full<% } %>"></div><% } %>'
   290 );
   290 );
   291 
   291 
   292 Renkan.prototype.translate = function(_text) {
   292 Renkan.prototype.translate = function(_text) {
   293     if (Rkns.i18n[this.options.language] && Rkns.i18n[this.options.language][_text]) {
   293     if (Rkns.i18n[this.options.language] && Rkns.i18n[this.options.language][_text]) {
   294         return Rkns.i18n[this.options.language][_text];
   294         return Rkns.i18n[this.options.language][_text];
   325         function pad(n){
   325         function pad(n){
   326             return n<10 ? '0'+n : n;
   326             return n<10 ? '0'+n : n;
   327         }
   327         }
   328         function fillrand() {
   328         function fillrand() {
   329             return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
   329             return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
   330                 var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
   330                 var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);
   331                 return v.toString(16);
   331                 return v.toString(16);
   332             });
   332             });
   333         }
   333         }
   334         var _d = new Date(),
   334         var _d = new Date(),
   335             ID_AUTO_INCREMENT = 0,
   335             ID_AUTO_INCREMENT = 0,
   336             ID_BASE = _d.getUTCFullYear() + '-'  
   336             ID_BASE = _d.getUTCFullYear() + '-' +
   337             + pad(_d.getUTCMonth()+1) + '-'  
   337               pad(_d.getUTCMonth()+1) + '-' +
   338             + pad(_d.getUTCDate()) + '-'
   338               pad(_d.getUTCDate()) + '-' +
   339             + fillrand();
   339               fillrand();
   340         return function(_base) {
   340         return function(_base) {
   341             var _n = (++ID_AUTO_INCREMENT).toString(16),
   341             var _n = (++ID_AUTO_INCREMENT).toString(16),
   342                 _base = (typeof _base === "undefined" ? "" : _base + "-" );
   342                 _uidbase = (typeof _base === "undefined" ? "" : _base + "-" );
   343             while (_n.length < 4) { _n = '0' + _n; }
   343             while (_n.length < 4) { _n = '0' + _n; }
   344             return _base + ID_BASE + '-' + _n;
   344             return _uidbase + ID_BASE + '-' + _n;
   345         }
   345         };
   346     })(),
   346     })(),
   347     getFullURL : function(url) {
   347     getFullURL : function(url) {
   348         
   348 
   349         if(typeof(url) == 'undefined' || url == null ) {
   349         if(typeof(url) === 'undefined' || url == null ) {
   350             return "";
   350             return "";
   351         }
   351         }
   352         if(/https?:\/\//.test(url)) {
   352         if(/https?:\/\//.test(url)) {
   353             return url;
   353             return url;
   354         }
   354         }
   355         var img = new Image();
   355         var img = new Image();
   356         img.src = url;
   356         img.src = url;
   357         var res = img.src;
   357         var res = img.src;
   358         img.src = null;
   358         img.src = null;
   359         return res;
   359         return res;
   360         
   360 
   361     },
   361     },
   362     inherit : function(_baseClass, _callbefore) {
   362     inherit : function(_baseClass, _callbefore) {
   363         
   363 
   364         var _class = function(_arg) {
   364         var _class = function(_arg) {
   365             if (typeof _callbefore === "function") {
   365             if (typeof _callbefore === "function") {
   366                 _callbefore.apply(this, Array.prototype.slice.call(arguments, 0));
   366                 _callbefore.apply(this, Array.prototype.slice.call(arguments, 0));
   367             }
   367             }
   368             _baseClass.apply(this, Array.prototype.slice.call(arguments, 0));
   368             _baseClass.apply(this, Array.prototype.slice.call(arguments, 0));
   369             if (typeof this._init == "function" && !this._initialized) {
   369             if (typeof this._init === "function" && !this._initialized) {
   370                 this._init.apply(this, Array.prototype.slice.call(arguments, 0));
   370                 this._init.apply(this, Array.prototype.slice.call(arguments, 0));
   371                 this._initialized = true;
   371                 this._initialized = true;
   372             }
   372             }
   373         };
   373         };
   374         _(_class.prototype).extend(_baseClass.prototype);
   374         _(_class.prototype).extend(_baseClass.prototype);
   375         
   375 
   376         return _class;
   376         return _class;
   377         
   377 
   378     },
   378     },
   379     regexpFromTextOrArray: (function() {
   379     regexpFromTextOrArray: (function() {
   380         var charsub = [
   380         var charsub = [
   381                 '[aáàâä]',
   381                 '[aáàâä]',
   382                 '[cç]',
   382                 '[cç]',
   393             remsrc = "[\\" + removeChars.join("\\") + "]",
   393             remsrc = "[\\" + removeChars.join("\\") + "]",
   394             remrx = new RegExp(remsrc, "gm"),
   394             remrx = new RegExp(remsrc, "gm"),
   395             charsrx = _(charsub).map(function(c) {
   395             charsrx = _(charsub).map(function(c) {
   396                 return new RegExp(c);
   396                 return new RegExp(c);
   397             });
   397             });
   398         
   398 
   399         function replaceText(_text) {
   399         function replaceText(_text) {
   400             var txt = _text.toLowerCase().replace(remrx,""), src = "";
   400             var txt = _text.toLowerCase().replace(remrx,""), src = "";
       
   401             function makeReplaceFunc(l) {
       
   402               return function(k,v) {
       
   403                 l = l.replace(charsrx[k], v);
       
   404               };
       
   405             }
   401             for (var j = 0; j < txt.length; j++) {
   406             for (var j = 0; j < txt.length; j++) {
   402                 if (j) {
   407                 if (j) {
   403                     src += remsrc + "*";
   408                     src += remsrc + "*";
   404                 }
   409                 }
   405                 var l = txt[j];
   410                 var l = txt[j];
   406                 _(charsub).each(function(v, k) {
   411                 _(charsub).each(makeReplaceFunc(l));
   407                     l = l.replace(charsrx[k], v);
       
   408                 });
       
   409                 src += l;
   412                 src += l;
   410             }
   413             }
   411             return src;
   414             return src;
   412         }
   415         }
   413         
   416 
   414         function getSource(inp) {
   417         function getSource(inp) {
   415             switch (typeof inp) {
   418             switch (typeof inp) {
   416                 case "string":
   419                 case "string":
   417                     return replaceText(inp);
   420                     return replaceText(inp);
   418                 case "object":
   421                 case "object":
   428                     });
   431                     });
   429                     return src;
   432                     return src;
   430             }
   433             }
   431             return '';
   434             return '';
   432         }
   435         }
   433         
   436 
   434         return function(_textOrArray) {
   437         return function(_textOrArray) {
   435             var source = getSource(_textOrArray);
   438             var source = getSource(_textOrArray);
   436             if (source) {
   439             if (source) {
   437                 var testrx = new RegExp( source, "im"),
   440                 var testrx = new RegExp( source, "im"),
   438                     replacerx = new RegExp( '(' + source + ')', "igm")
   441                     replacerx = new RegExp( '(' + source + ')', "igm");
   439                 return {
   442                 return {
   440                     isempty: false,
   443                     isempty: false,
   441                     source: source,
   444                     source: source,
   442                     test: function(_t) { return testrx.test(_t) },
   445                     test: function(_t) { return testrx.test(_t); },
   443                     replace: function(_text, _replace) { return _text.replace(replacerx, _replace); }
   446                     replace: function(_text, _replace) { return _text.replace(replacerx, _replace); }
   444                 }
   447                 };
   445             } else {
   448             } else {
   446                 return {
   449                 return {
   447                     isempty: true,
   450                     isempty: true,
   448                     source: '',
   451                     source: '',
   449                     test: function() { return true },
   452                     test: function() { return true; },
   450                     replace: function(_text) { return text }
   453                     replace: function(_text) { return text; }
   451                 }
   454                 };
   452             }
   455             }
   453         }
   456         };
   454     })(),
   457     })(),
   455     /* The minimum distance (in pixels) the mouse has to move to consider an element was dragged */
   458     /* The minimum distance (in pixels) the mouse has to move to consider an element was dragged */
   456     _MIN_DRAG_DISTANCE: 2,
   459     _MIN_DRAG_DISTANCE: 2,
   457     /* Distance between the inner and outer radius of buttons that appear when hovering on a node */
   460     /* Distance between the inner and outer radius of buttons that appear when hovering on a node */
   458     _NODE_BUTTON_WIDTH: 40,
   461     _NODE_BUTTON_WIDTH: 40,
   484     },
   487     },
   485     /* The code for the "Drag and Add Bookmarklet", slightly minified and with whitespaces removed, though
   488     /* The code for the "Drag and Add Bookmarklet", slightly minified and with whitespaces removed, though
   486      * it doesn't seem that it's still a requirement in newer browsers (i.e. the ones compatibles with canvas drawing)
   489      * it doesn't seem that it's still a requirement in newer browsers (i.e. the ones compatibles with canvas drawing)
   487      */
   490      */
   488     _BOOKMARKLET_CODE: function(_renkan) {
   491     _BOOKMARKLET_CODE: function(_renkan) {
   489         return "(function(a,b,c,d,e,f,h,i,j,k,l,m,n,o,p,q,r){a=document;b=a.body;c=a.location.href;j='draggable';m='text/x-iri-';d=a.createElement('div');d.innerHTML='<p_style=\"position:fixed;top:0;right:0;font:bold_18px_sans-serif;color:#fff;background:#909;padding:10px;z-index:100000;\">"
   492         return "(function(a,b,c,d,e,f,h,i,j,k,l,m,n,o,p,q,r){a=document;b=a.body;c=a.location.href;j='draggable';m='text/x-iri-';d=a.createElement('div');d.innerHTML='<p_style=\"position:fixed;top:0;right:0;font:bold_18px_sans-serif;color:#fff;background:#909;padding:10px;z-index:100000;\">" +
   490         + _renkan.translate("Drag items from this website, drop them in Renkan").replace(/ /g,"_")
   493         _renkan.translate("Drag items from this website, drop them in Renkan").replace(/ /g,"_") +
   491         + "</p>'.replace(/_/g,String.fromCharCode(32));b.appendChild(d);e=[{r:/https?:\\/\\/[^\\/]*twitter\\.com\\//,s:'.tweet',n:'twitter'},{r:/https?:\\/\\/[^\\/]*google\\.[^\\/]+\\//,s:'.g',n:'google'},{r:/https?:\\/\\/[^\\/]*lemonde\\.fr\\//,s:'[data-vr-contentbox]',n:'lemonde'}];f=false;e.forEach(function(g){if(g.r.test(c)){f=g;}});if(f){h=function(){Array.prototype.forEach.call(a.querySelectorAll(f.s),function(i){i[j]=true;k=i.style;k.borderWidth='2px';k.borderColor='#909';k.borderStyle='solid';k.backgroundColor='rgba(200,0,180,.1)';})};window.setInterval(h,500);h();};a.addEventListener('dragstart',function(k){l=k.dataTransfer;l.setData(m+'source-uri',c);l.setData(m+'source-title',a.title);n=k.target;if(f){o=n;while(!o.attributes[j]){o=o.parentNode;if(o==b){break;}}}if(f&&o.attributes[j]){p=o.cloneNode(true);l.setData(m+'specific-site',f.n)}else{q=a.getSelection();if(q.type==='Range'||!q.type){p=q.getRangeAt(0).cloneContents();}else{p=n.cloneNode();}}r=a.createElement('div');r.appendChild(p);l.setData('text/x-iri-selected-text',r.textContent.trim());l.setData('text/x-iri-selected-html',r.innerHTML);},false);})();";
   494         "</p>'.replace(/_/g,String.fromCharCode(32));b.appendChild(d);e=[{r:/https?:\\/\\/[^\\/]*twitter\\.com\\//,s:'.tweet',n:'twitter'},{r:/https?:\\/\\/[^\\/]*google\\.[^\\/]+\\//,s:'.g',n:'google'},{r:/https?:\\/\\/[^\\/]*lemonde\\.fr\\//,s:'[data-vr-contentbox]',n:'lemonde'}];f=false;e.forEach(function(g){if(g.r.test(c)){f=g;}});if(f){h=function(){Array.prototype.forEach.call(a.querySelectorAll(f.s),function(i){i[j]=true;k=i.style;k.borderWidth='2px';k.borderColor='#909';k.borderStyle='solid';k.backgroundColor='rgba(200,0,180,.1)';})};window.setInterval(h,500);h();};a.addEventListener('dragstart',function(k){l=k.dataTransfer;l.setData(m+'source-uri',c);l.setData(m+'source-title',a.title);n=k.target;if(f){o=n;while(!o.attributes[j]){o=o.parentNode;if(o==b){break;}}}if(f&&o.attributes[j]){p=o.cloneNode(true);l.setData(m+'specific-site',f.n)}else{q=a.getSelection();if(q.type==='Range'||!q.type){p=q.getRangeAt(0).cloneContents();}else{p=n.cloneNode();}}r=a.createElement('div');r.appendChild(p);l.setData('text/x-iri-selected-text',r.textContent.trim());l.setData('text/x-iri-selected-html',r.innerHTML);},false);})();";
   492     },
   495     },
   493     /* Shortens text to the required length then adds ellipsis */
   496     /* Shortens text to the required length then adds ellipsis */
   494     shortenText: function(_text, _maxlength) {
   497     shortenText: function(_text, _maxlength) {
   495         return (_text.length > _maxlength ? (_text.substr(0,_maxlength) + '…') : _text);
   498         return (_text.length > _maxlength ? (_text.substr(0,_maxlength) + '…') : _text);
   496     },
   499     },
   510         }
   513         }
   511         if (_top < _options.tooltip_margin) {
   514         if (_top < _options.tooltip_margin) {
   512             _top = Math.min( _options.tooltip_margin, _coords.y - _options.tooltip_arrow_width / 2 );
   515             _top = Math.min( _options.tooltip_margin, _coords.y - _options.tooltip_arrow_width / 2 );
   513         }
   516         }
   514         var _bottom = _top + _height;
   517         var _bottom = _top + _height;
       
   518         /* jshint laxbreak:true */
   515         _path.segments[0].point
   519         _path.segments[0].point
   516         = _path.segments[7].point
   520           = _path.segments[7].point
   517         = _coords.add([_isLeft * _xmargin, 0]);
   521           = _coords.add([_isLeft * _xmargin, 0]);
   518         _path.segments[1].point.x
   522         _path.segments[1].point.x
   519         = _path.segments[2].point.x
   523           = _path.segments[2].point.x
   520         = _path.segments[5].point.x
   524           = _path.segments[5].point.x
   521         = _path.segments[6].point.x
   525           = _path.segments[6].point.x
   522         = _left;
   526           = _left;
   523         _path.segments[3].point.x
   527         _path.segments[3].point.x
   524         = _path.segments[4].point.x
   528           = _path.segments[4].point.x
   525         = _right;
   529           = _right;
   526         _path.segments[2].point.y
   530         _path.segments[2].point.y
   527         = _path.segments[3].point.y
   531           = _path.segments[3].point.y
   528         = _top;
   532           = _top;
   529         _path.segments[4].point.y
   533         _path.segments[4].point.y
   530         = _path.segments[5].point.y
   534           = _path.segments[5].point.y
   531         = _bottom;
   535           = _bottom;
   532         _path.segments[1].point.y = _coords.y - _options.tooltip_arrow_width / 2;
   536         _path.segments[1].point.y = _coords.y - _options.tooltip_arrow_width / 2;
   533         _path.segments[6].point.y = _coords.y + _options.tooltip_arrow_width / 2;
   537         _path.segments[6].point.y = _coords.y + _options.tooltip_arrow_width / 2;
   534         _path.closed = true;
   538         _path.closed = true;
   535         _path.fillColor = new paper.GradientColor(new paper.Gradient([_options.tooltip_top_color, _options.tooltip_bottom_color]), [0,_top], [0, _bottom]);
   539         _path.fillColor = new paper.GradientColor(new paper.Gradient([_options.tooltip_top_color, _options.tooltip_bottom_color]), [0,_top], [0, _bottom]);
   536         _selector.css({
   540         _selector.css({