Added Refresh button and Autorefresh
authorveltr
Tue, 13 Nov 2012 11:46:27 +0100
changeset 42 48d825187d67
parent 41 9b9aabbb83bb
child 43 90f6937c417e
Added Refresh button and Autorefresh
client/css/renkan.css
client/img/refresh.png
client/js/ldtjson-bin.js
client/js/main.js
client/js/twitter-bin.js
client/js/wikipedia-bin.js
--- a/client/css/renkan.css	Fri Sep 14 10:21:00 2012 +0900
+++ b/client/css/renkan.css	Tue Nov 13 11:46:27 2012 +0100
@@ -326,11 +326,12 @@
 }
 
 .Rk-Bin-Close {
-    float: right; font-size: 15px; font-weight: bold; margin: 3px 3px 0; color: #f0f0f0; cursor: pointer;
+    float: right; display: block; font-size: 16px; font-weight: bold; margin: 2px 3px 0; color: #f0f0f0; cursor: pointer;
+    text-shadow: -1px -1px 1px #999999, 1px 1px 1px #000000; text-decoration: none;
 }
 
-.Rk-Bin-Close:hover  {
-    color: #ffffe0;
+.Rk-Bin-Close:hover {
+    color: #ffff80;
 }
 
 .Rk-Bin-Title:hover {
@@ -339,6 +340,14 @@
     background: -webkit-linear-gradient(top, rgb(20,20,20) 20%, rgb(60,60,60) 80%);
 }
 
+.Rk-Bin-Refresh {
+    width: 18px; height: 17px; background: url(../img/refresh.png); display: block; float: right; margin-top: 4px;
+}
+
+.Rk-Bin-Refresh:hover {
+    background-position: -18px 0;
+}
+
 .Rk-Bin-Title-Icon {
     float: left; width: 25px; margin: 2px;
 }
Binary file client/img/refresh.png has changed
--- a/client/js/ldtjson-bin.js	Fri Sep 14 10:21:00 2012 +0900
+++ b/client/js/ldtjson-bin.js	Tue Nov 13 11:46:27 2012 +0100
@@ -16,6 +16,10 @@
     this.proj_id = _opts.project_id;
     this.ldt_platform = _opts.ldt_platform || "http://ldt.iri.centrepompidou.fr/";
     this.title_$.html(_opts.title);
+    this.refresh();
+}
+
+Rkns.Ldt.ProjectBin.prototype.refresh = function() {
     var _this = this;
     function convertTC(_ms) {
         function pad(_n) {
@@ -36,9 +40,10 @@
         _res += pad(_minutes) + ':' + pad(_seconds);
         return _res;
     }
-    Rkns.$.getJSON(
-        this.ldt_platform + 'ldtplatform/ldt/cljson/id/' + this.proj_id + '?callback=?',
-        function(_data) {
+    Rkns.$.ajax({
+        url: this.ldt_platform + 'ldtplatform/ldt/cljson/id/' + this.proj_id,
+        dataType: "jsonp",
+        success: function(_data) {
             var _html = '<li><h3>Tags</h3></li>',
                 _projtitle = _data.meta["dc:title"];
             _this.title_$.html('LDT Project: "' + _projtitle + '"');
@@ -76,5 +81,5 @@
             _this.main_$.html(_html);
             _renkan.resizeBins();
         }
-    );
+    });
 }
\ No newline at end of file
--- a/client/js/main.js	Fri Sep 14 10:21:00 2012 +0900
+++ b/client/js/main.js	Tue Nov 13 11:46:27 2012 +0100
@@ -36,13 +36,25 @@
         this.title_icon_$ = Rkns.$('<span>')
             .addClass("Rk-Bin-Title-Icon")
             .appendTo(this.$);
+            
         var _this = this;
-        Rkns.$('<span>')
+        
+        Rkns.$('<a>')
+            .attr("href","#")
             .addClass("Rk-Bin-Close")
             .html('&times;')
             .appendTo(this.$)
             .click(function() {
                 _this.destroy();
+                return false;
+            });
+        Rkns.$('<a>')
+            .attr("href","#")
+            .addClass("Rk-Bin-Refresh")
+            .appendTo(this.$)
+            .click(function() {
+                _this.refresh();
+                return false;
             });
         this.title_$ = Rkns.$('<h2>')
             .addClass("Rk-Bin-Title")
@@ -52,6 +64,12 @@
             .appendTo(this.$);
         this.title_$.html(_opts.title || '(new bin)');
         this.renkan.resizeBins();
+        
+        if (_opts.auto_refresh) {
+            window.setInterval(function() {
+                _this.refresh();
+            },_opts.auto_refresh)
+        }
     }
 }
 
@@ -133,22 +151,7 @@
     }
     Rkns._(_opts.bins).each(function(_bin) {
         _this.tabs.push(new _bin.bin(_this, _bin));
-    })
-    
-    /* The bins are not yet populated, but we want to bind dragging functions
-     * here, as it will be easier than in the bins. Therefore, we bind to Rk-Bins
-     * and look where the click was. */
-    function findItem(_event) {
-        var _t = Rkns.$(_event.target);
-        while (!_t.is(".Rk-Bins,.Rk-Bin-Item")) {
-            _t = _t.parent();
-        }
-        if (_t.is(".Rk-Bin-Item")) {
-            return _t
-        } else {
-            return null;
-        }
-    }
+    });
     
     this.$.find(".Rk-Bins")
         .on("click",".Rk-Bin-Title,.Rk-Bin-Title-Icon", function() {
--- a/client/js/twitter-bin.js	Fri Sep 14 10:21:00 2012 +0900
+++ b/client/js/twitter-bin.js	Tue Nov 13 11:46:27 2012 +0100
@@ -41,10 +41,15 @@
     this.search = _opts.search;
     this.title_icon_$.addClass('Rk-Twitter-Title-Icon');
     this.title_$.html(this.search).addClass("Rk-Twitter-Title");
+    this.refresh();
+}
+
+Rkns.Twitter.Bin.prototype.refresh = function() {
     var _this = this;
-    Rkns.$.getJSON(
-        "http://search.twitter.com/search.json?q=" + encodeURIComponent(this.search) + "&callback=?",
-        function(_data) {
+    Rkns.$.ajax({
+        url: "http://search.twitter.com/search.json?q=" + encodeURIComponent(this.search),
+        dataType: "jsonp",
+        success: function(_data) {
             var _rgxp = new RegExp('('+_this.search.replace(/(\W)/g,'\\$1')+')','gi');
             function highlight(_text) {
                 return _text.replace(_rgxp, "<span class='searchmatch'>$1</span>");
@@ -115,5 +120,5 @@
             _this.main_$.html(_html);
             _renkan.resizeBins();
         }
-    );
+    });
 }
--- a/client/js/wikipedia-bin.js	Fri Sep 14 10:21:00 2012 +0900
+++ b/client/js/wikipedia-bin.js	Tue Nov 13 11:46:27 2012 +0100
@@ -37,10 +37,15 @@
     this.lang = _opts.lang || "en";
     this.title_icon_$.addClass('Rk-Wikipedia-Title-Icon Rk-Wikipedia-Lang-' + this.lang);
     this.title_$.html(this.search).addClass("Rk-Wikipedia-Title");
+    this.refresh();
+}
+
+Rkns.Wikipedia.Bin.prototype.refresh = function() {
     var _this = this;
-    Rkns.$.getJSON(
-        "http://" + _this.lang + ".wikipedia.org/w/api.php?action=query&list=search&srsearch=" + encodeURIComponent(this.search) + "&format=json&callback=?",
-        function(_data) {
+    Rkns.$.ajax({
+        url: "http://" + _this.lang + ".wikipedia.org/w/api.php?action=query&list=search&srsearch=" + encodeURIComponent(this.search) + "&format=json",
+        dataType: "jsonp",
+        success: function(_data) {
             var _rgxp = new RegExp('('+_this.search.replace(/(\W)/g,'\\$1')+')','gi'),
                 _html = Rkns._(_data.query.search).map(function(_result) {
                 return _this.resultTemplate({
@@ -53,5 +58,5 @@
             _this.main_$.html(_html);
             _renkan.resizeBins();
         }
-    );
+    });
 }
\ No newline at end of file