client/js/main.js
changeset 68 803dbeb7c919
parent 66 9b459e41e2df
child 69 f0873867143a
equal deleted inserted replaced
67:d341117f9370 68:803dbeb7c919
    23 }
    23 }
    24 
    24 
    25 Rkns.$ = jQuery;
    25 Rkns.$ = jQuery;
    26 
    26 
    27 Rkns._ = _;
    27 Rkns._ = _;
       
    28 
       
    29 Rkns.VERSION = '0.2';
    28 
    30 
    29 Rkns.pickerColors = ["#8f1919", "#a80000", "#d82626", "#ff0000", "#e87c7c", "#ff6565", "#f7d3d3", "#fecccc", "#8f5419", "#a85400", "#d87f26", "#ff7f00", "#e8b27c", "#ffb265", "#f7e5d3", "#fee5cc", "#8f8f19", "#a8a800", "#d8d826", "#feff00", "#e8e87c", "#feff65", "#f7f7d3", "#fefecc", "#198f19", "#00a800", "#26d826", "#00ff00", "#7ce87c", "#65ff65", "#d3f7d3", "#ccfecc", "#198f8f", "#00a8a8", "#26d8d8", "#00feff", "#7ce8e8", "#65feff", "#d3f7f7", "#ccfefe", "#19198f", "#0000a8", "#2626d8", "#0000ff", "#7c7ce8", "#6565ff", "#d3d3f7", "#ccccfe", "#8f198f", "#a800a8", "#d826d8", "#ff00fe", "#e87ce8", "#ff65fe", "#f7d3f7", "#feccfe", "#000000", "#242424", "#484848", "#6d6d6d", "#919191", "#b6b6b6", "#dadada", "#ffffff"];
    31 Rkns.pickerColors = ["#8f1919", "#a80000", "#d82626", "#ff0000", "#e87c7c", "#ff6565", "#f7d3d3", "#fecccc", "#8f5419", "#a85400", "#d87f26", "#ff7f00", "#e8b27c", "#ffb265", "#f7e5d3", "#fee5cc", "#8f8f19", "#a8a800", "#d8d826", "#feff00", "#e8e87c", "#feff65", "#f7f7d3", "#fefecc", "#198f19", "#00a800", "#26d826", "#00ff00", "#7ce87c", "#65ff65", "#d3f7d3", "#ccfecc", "#198f8f", "#00a8a8", "#26d8d8", "#00feff", "#7ce8e8", "#65feff", "#d3f7f7", "#ccfefe", "#19198f", "#0000a8", "#2626d8", "#0000ff", "#7c7ce8", "#6565ff", "#d3d3f7", "#ccccfe", "#8f198f", "#a800a8", "#d826d8", "#ff00fe", "#e87ce8", "#ff65fe", "#f7d3f7", "#feccfe", "#000000", "#242424", "#484848", "#6d6d6d", "#919191", "#b6b6b6", "#dadada", "#ffffff"];
    30 
    32 
    31 Rkns._BaseBin = function(_renkan, _opts) {
    33 Rkns._BaseBin = function(_renkan, _opts) {
    32     if (typeof _renkan !== "undefined") {
    34     if (typeof _renkan !== "undefined") {
    85 }
    87 }
    86 
    88 
    87 /* Point of entry */
    89 /* Point of entry */
    88 
    90 
    89 Rkns.Renkan = function(_opts) {
    91 Rkns.Renkan = function(_opts) {
       
    92     var _this = this;
       
    93     
    90     if (typeof _opts.language !== "string" || typeof Rkns.i18n[_opts.language] == "undefined") {
    94     if (typeof _opts.language !== "string" || typeof Rkns.i18n[_opts.language] == "undefined") {
    91         _opts.language = "en";
    95         _opts.language = "en";
    92     }
    96     }
    93     if (typeof _opts.container !== "string") {
    97     if (typeof _opts.container !== "string") {
    94         _opts.container = "renkan";
    98         _opts.container = "renkan";
   105     if (typeof _opts.show_bins !== "boolean") {
   109     if (typeof _opts.show_bins !== "boolean") {
   106         _opts.show_bins = !!_opts.search.length || !!_opts.bins.length;
   110         _opts.show_bins = !!_opts.search.length || !!_opts.bins.length;
   107     }
   111     }
   108     if (typeof _opts.read_only !== "boolean") {
   112     if (typeof _opts.read_only !== "boolean") {
   109         _opts.read_only = false;
   113         _opts.read_only = false;
       
   114     }
       
   115     if (typeof _opts.properties !== "object") {
       
   116     	_opts.properties = [];
       
   117     }
       
   118     if (typeof _opts.property_files === "object") {
       
   119     	Rkns._(_opts.property_files).each(function(f) {
       
   120     		Rkns.$.getJSON(f, function(data) {
       
   121     			_this.properties = _this.properties.concat(data);
       
   122     		});
       
   123     	});
   110     }
   124     }
   111     this.project = new Rkns.Models.Project();
   125     this.project = new Rkns.Models.Project();
   112     this.language = _opts.language;
   126     this.language = _opts.language;
   113     this.static_url = _opts.static_url;
   127     this.static_url = _opts.static_url;
       
   128     this.show_bins = _opts.show_bins;
   114     this.read_only = _opts.read_only;
   129     this.read_only = _opts.read_only;
       
   130     this.properties = _opts.properties;
   115     this.translate = function(_text) {
   131     this.translate = function(_text) {
   116     	return (Rkns.i18n[_opts.language] || Rkns.i18n[_opts.language.substr(0,2)] || {})[_text] || _text;
   132     	return (Rkns.i18n[_opts.language] || Rkns.i18n[_opts.language.substr(0,2)] || {})[_text] || _text;
   117     }
   133     }
   118     if (typeof _opts.user_id !== "undefined") {
   134     if (typeof _opts.user_id !== "undefined") {
   119         this.current_user = _opts.user_id;
   135         this.current_user = _opts.user_id;
   120     }
   136     }
   121     this.$ = Rkns.$("#" + _opts.container);
   137     this.$ = Rkns.$("#" + _opts.container);
   122     this.$
   138     this.$
   123         .addClass("Rk-Main")
   139         .addClass("Rk-Main")
   124         .html(this.template(_opts));
   140         .html(this.template(this));
   125     this.renderer = new Rkns.Renderer.Scene(this);
   141     this.renderer = new Rkns.Renderer.Scene(this);
   126     this.tabs = [];
   142     this.tabs = [];
   127     this.search_engines = [];
   143     this.search_engines = [];
   128     this.selected_bin_item = undefined;
       
   129 
   144 
   130     this.current_user_list = new Rkns.Models.UsersList();
   145     this.current_user_list = new Rkns.Models.UsersList();
   131     
   146     
   132     var _this = this;
       
   133     this.$.mouseup(function() {
       
   134         _this.selected_bin_item = undefined;
       
   135         _this.$.find(".Rk-Bin-Item.dragging").removeClass("dragging");
       
   136     });
       
   137     if (!_opts.search.length) {
   147     if (!_opts.search.length) {
   138         this.$.find(".Rk-Web-Search-Form").detach();
   148         this.$.find(".Rk-Web-Search-Form").detach();
   139     } else {
   149     } else {
   140         var _tmpl = Rkns._.template('<li class="<%= className %>" data-key="<%= key %>"><%= title %></li>'),
   150         var _tmpl = Rkns._.template('<li class="<%= className %>" data-key="<%= key %>"><%= title %></li>'),
   141             _select = this.$.find(".Rk-Search-List"),
   151             _select = this.$.find(".Rk-Search-List"),
   183             var _mainDiv = Rkns.$(this).siblings(".Rk-Bin-Main");
   193             var _mainDiv = Rkns.$(this).siblings(".Rk-Bin-Main");
   184             if (_mainDiv.is(":hidden")) {
   194             if (_mainDiv.is(":hidden")) {
   185                 _this.$.find(".Rk-Bin-Main").slideUp();
   195                 _this.$.find(".Rk-Bin-Main").slideUp();
   186                 _mainDiv.slideDown();
   196                 _mainDiv.slideDown();
   187             }
   197             }
   188         }).on("mousedown", ".Rk-Bin-Item", function() {
       
   189             if (_this.read_only) {
       
   190                 return false;
       
   191             }
       
   192             var _t = Rkns.$(this);
       
   193             _t.addClass("dragging");
       
   194             _this.selected_bin_item = {
       
   195                 uri : $(_t).attr("data-uri"),
       
   196                 title : $(_t).attr("data-title"),
       
   197                 description : $(_t).attr("data-description"),
       
   198                 image: $(_t).attr("data-image")
       
   199             }
       
   200             return false;
       
   201         }).on("mouseover", ".Rk-Bin-Item", function(_e) {
   198         }).on("mouseover", ".Rk-Bin-Item", function(_e) {
   202             var _t = Rkns.$(this);
   199             var _t = Rkns.$(this);
   203             if (_t && $(_t).attr("data-uri")) {
   200             if (_t && $(_t).attr("data-uri")) {
   204                 var _models = _this.project.get("nodes").where({
   201                 var _models = _this.project.get("nodes").where({
   205                     uri: $(_t).attr("data-uri")
   202                     uri: $(_t).attr("data-uri")
   208                     _this.renderer.highlightModel(_model);
   205                     _this.renderer.highlightModel(_model);
   209                 });
   206                 });
   210             }
   207             }
   211         }).mouseout(function() {
   208         }).mouseout(function() {
   212             _this.renderer.unhighlightAll();
   209             _this.renderer.unhighlightAll();
       
   210         }).on("dragstart", ".Rk-Bin-Item", function(e) {
       
   211             var _t = Rkns.$(this);
       
   212         	e.originalEvent.dataTransfer.setData("text/x-iri-title",$(_t).attr("data-title"));
       
   213         	e.originalEvent.dataTransfer.setData("text/x-iri-description",$(_t).attr("data-description"));
       
   214         	e.originalEvent.dataTransfer.setData("text/x-iri-uri",$(_t).attr("data-uri"));
       
   215         	e.originalEvent.dataTransfer.setData("text/x-iri-image",$(_t).attr("data-image"));
   213         });
   216         });
   214     Rkns.$(window).resize(function() {
   217     Rkns.$(window).resize(function() {
   215         _this.resizeBins();
   218         _this.resizeBins();
   216     });
   219     });
   217     
   220     
   225         return false
   228         return false
   226     });
   229     });
   227 }
   230 }
   228 
   231 
   229 Rkns.Renkan.prototype.template = Rkns._.template(
   232 Rkns.Renkan.prototype.template = Rkns._.template(
   230     '<% if (show_bins) { %><div class="Rk-Title"><h1>Hyper Plateau</h1></div><div class="Rk-Bins">'
   233     '<% if (show_bins) { %><div class="Rk-Title"><h1><%- translate("Renkan") %></h1></div><div class="Rk-Bins">'
   231     + '<form class="Rk-Web-Search-Form Rk-Search-Form"><input class="Rk-Web-Search-Input Rk-Search-Input" type="search" placeholder="Search the Web" />'
   234     + '<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") %>" />'
   232     + '<div class="Rk-Search-Select"><div class="Rk-Search-Current"></div><ul class="Rk-Search-List"></ul></div>'
   235     + '<div class="Rk-Search-Select"><div class="Rk-Search-Current"></div><ul class="Rk-Search-List"></ul></div>'
   233     + '<input type="submit" value="" class="Rk-Web-Search-Submit Rk-Search-Submit" /></form>'
   236     + '<input type="submit" value="" class="Rk-Web-Search-Submit Rk-Search-Submit" /></form>'
   234     + '<form class="Rk-Bins-Search-Form Rk-Search-Form"><input class="Rk-Bins-Search-Input Rk-Search-Input" type="search" placeholder="Search in Bins" />'
   237     + '<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") %>" />'
   235     + '<input type="submit" value="" class="Rk-Bins-Search-Submit Rk-Search-Submit" /></form>'
   238     + '<input type="submit" value="" class="Rk-Bins-Search-Submit Rk-Search-Submit" /></form>'
   236     + '<ul class="Rk-Bin-List"></ul></div><% } %><div class="Rk-Render Rk-Render-<% if (show_bins) { %>Panel<% } else { %>Full<% } %>"></div>'
   239     + '<ul class="Rk-Bin-List"></ul></div><% } %><div class="Rk-Render Rk-Render-<% if (show_bins) { %>Panel<% } else { %>Full<% } %>"></div>'
   237 );
   240 );
   238 
   241 
   239 
   242