From e0fd734c64ac4e789fb4975aa7a77d9f20c5353f Mon Sep 17 00:00:00 2001 From: Mathias Kresin Date: Tue, 27 Jan 2015 19:01:21 +0100 Subject: [PATCH] use javascript advanced optimizations, improve make-js script Major benefit, beside a smaller file size, is the possibility to remove debug informations from the minified javascript. make-js script: - take care of any warnings and errors - raise warning level to verbose js/* - switch to Array-Access Property Notation for external data (prevents renaming by the closure compiler) --- assets/js/all.min.js | 37 ++++++++++++++++--------------------- assets/js/feed.js | 8 ++++---- assets/js/item.js | 28 ++++++++++++++-------------- scripts/make-js.sh | 23 +++++++++++++++++------ 4 files changed, 51 insertions(+), 45 deletions(-) diff --git a/assets/js/all.min.js b/assets/js/all.min.js index fe52903..4025a77 100644 --- a/assets/js/all.min.js +++ b/assets/js/all.min.js @@ -1,21 +1,16 @@ -var Miniflux={};Miniflux.App=function(){return{Run:function(){Miniflux.Event.ListenKeyboardEvents();Miniflux.Event.ListenMouseEvents()}}}(); -Miniflux.Feed=function(){var e=[];return{Update:function(d,a){var b=d.querySelector("span.items-count");if(b){var c=d.getAttribute("data-feed-id"),e=d.querySelector("h2:first-of-type");e.className="loading-icon";var h=new XMLHttpRequest;h.onload=function(){e.className="";d.removeAttribute("data-feed-error");var c=d.querySelector(".feed-last-checked");c&&(c.innerHTML=c.getAttribute("data-after-update"));c=JSON.parse(this.responseText);c.result?b.innerHTML=c.items_count.items_unread+"/"+c.items_count.items_total: -d.setAttribute("data-feed-error","1");a&&a(c)};h.open("POST","?action=refresh-feed&feed_id="+c,!0);h.send()}},UpdateAll:function(){var d=Array.prototype.slice.call(document.querySelectorAll("article:not([data-feed-disabled])")),a=setInterval(function(){for(;0e.length;){var b=d.shift();e.push(parseInt(b.getAttribute("data-feed-id")));Miniflux.Feed.Update(b,function(b){b=e.indexOf(b.feed_id);0<=b&&e.splice(b,1);0===d.length&&0===e.length&&(clearInterval(a),window.location.href="?action=unread")})}}, -100)}}}(); -Miniflux.Item=function(){function e(a){return item_id=a.getAttribute("data-item-id")}function d(a){if(a&&a.hasAttribute("data-reverse-label")){var b=a.innerHTML;a.innerHTML=a.getAttribute("data-reverse-label");a.setAttribute("data-reverse-label",b)}}function a(a){"mouse"!==Miniflux.Event.lastEventType&&Miniflux.Nav.SelectNextItem();a.parentNode.removeChild(a);l--}function b(){0===l&&window.location.reload();var a=document.getElementById("page-counter");a.textContent=l||"";document.getElementById("nav-counter").textContent=h|| -"";switch(document.querySelector("section.page").getAttribute("data-item-page")){case "unread":document.title="Miniflux ("+h+")";break;case "feed-items":document.title="("+l+") "+a.parentNode.firstChild.nodeValue;break;default:document.title=a.parentNode.firstChild.nodeValue+" ("+l+")"}}function c(g){var f=e(g),c=new XMLHttpRequest;c.onload=function(){if(Miniflux.Nav.IsListing()){if(g.getAttribute("data-hide"))a(g);else{g.setAttribute("data-item-status","read");var c=g.querySelector("a.mark");d(c); -(c=g.querySelector("a.mark"))&&c.setAttribute("data-action","mark-unread")}h--;b()}};c.open("POST","?action=mark-item-read&id="+f,!0);c.send()}function n(g){var c=e(g),k=new XMLHttpRequest;k.onload=function(){if(Miniflux.Nav.IsListing()){if(g.getAttribute("data-hide"))a(g);else{g.setAttribute("data-item-status","unread");var c=g.querySelector("a.mark");d(c);(c=g.querySelector("a.mark"))&&c.setAttribute("data-action","mark-read")}h++;b()}};k.open("POST","?action=mark-item-unread&id="+c,!0);k.send()} -var h=function(){var a=document.getElementById("nav-counter");if(a)return counter=parseInt(a.textContent,10)||0}(),l=function(){var a=document.getElementById("page-counter");if(a)return counter=parseInt(a.textContent,10)||0}();return{MarkAsRead:c,MarkAsUnread:n,MarkAsRemoved:function(c){var f=e(c),d=new XMLHttpRequest;d.onload=function(){Miniflux.Nav.IsListing()&&(a(c),"unread"===c.getAttribute("data-item-status")&&h--,b())};d.open("POST","?action=mark-item-removed&id="+f,!0);d.send()},SwitchBookmark:function(c){var f= -e(c),k="1"===c.getAttribute("data-item-bookmark")?"0":"1",m=new XMLHttpRequest;m.onload=function(){var f=document.querySelector("section.page");if(Miniflux.Nav.IsListing()&&"bookmarks"===f.getAttribute("data-item-page"))a(c),b();else if(c.setAttribute("data-item-bookmark",k),Miniflux.Nav.IsListing())f=c.querySelector("a.bookmark"),d(f);else if((f=c.querySelector("a.bookmark-icon"))&&f.hasAttribute("data-reverse-title")){var e=f.getAttribute("title");f.setAttribute("title",f.getAttribute("data-reverse-title")); -f.setAttribute("data-reverse-title",e)}};m.open("POST","?action=bookmark&id="+f+"&value="+k,!0);m.send()},SwitchStatus:function(a){var b=a.getAttribute("data-item-status");"read"===b?n(a):"unread"===b&&c(a)},Show:function(a){(a=a.querySelector("a.show"))&&a.click()},OpenOriginal:function(a){var b=a.querySelector("a.original");b&&("unread"===a.getAttribute("data-item-status")&&c(a),b.removeAttribute("data-action"),"mouse"!==Miniflux.Event.lastEventType&&b.click())},DownloadContent:function(a){var b= -document.getElementById("download-item");if(b){b.innerHTML=" "+b.getAttribute("data-before-message");b.className="loading-icon";var c=new XMLHttpRequest;c.onload=function(){var a=JSON.parse(c.responseText);b.className="";if(a.result){var d=document.getElementById("item-content");d&&(d.innerHTML=a.content);b.innerHTML=b.getAttribute("data-after-message")}else b.innerHTML=b.getAttribute("data-failure-message")};a=e(a);c.open("POST","?action=download-item&id="+a,!0);c.send()}},MarkListingAsRead:function(a){for(var b= -document.getElementsByTagName("article"),c=[],d=0,h=b.length;db-(a.offsetTop+a.offsetHeight)||b-a.offsetTop>document.documentElement.clientHeight)&&window.scrollTo(0,a.offsetTop-10)}function d(){return document.getElementById("listing")?!0:!1}return{OpenNextPage:function(){var a=document.getElementById("next-page");a&&a.click()},OpenPreviousPage:function(){var a=document.getElementById("previous-page");a&&a.click()},SelectNextItem:function(){var a=document.getElementById("next-item"); -if(a)a.click();else if(d())if(a=document.getElementsByTagName("article"),document.getElementById("current-item"))for(var b=0,c=a.length;be.length;){var b=d.shift();e.push(parseInt(b.getAttribute("data-feed-id"),10));g.i(b,function(b){b=e.indexOf(b.feed_id);0<=b&&e.splice(b,1);0===d.length&&0===e.length&&(clearInterval(a),window.location.href="?action=unread")})}},100)}}}(), +q=function(){function e(a){return item_id=a.getAttribute("data-item-id")}function d(a){if(a&&a.hasAttribute("data-reverse-label")){var b=a.innerHTML;a.innerHTML=a.getAttribute("data-reverse-label");a.setAttribute("data-reverse-label",b)}}function a(a){"mouse"!==k.b&&m.c();a.parentNode.removeChild(a);p--}function b(){0===p&&window.location.reload();var a=document.getElementById("page-counter");a.textContent=p||"";document.getElementById("nav-counter").textContent=l||"";switch(document.querySelector("section.page").getAttribute("data-item-page")){case "unread":document.title= +"Miniflux ("+l+")";break;case "feed-items":document.title="("+p+") "+a.parentNode.firstChild.nodeValue;break;default:document.title=a.parentNode.firstChild.nodeValue+" ("+p+")"}}function c(h){var f=e(h),c=new XMLHttpRequest;c.onload=function(){if(m.a()){if(h.getAttribute("data-hide"))a(h);else{h.setAttribute("data-item-status","read");var c=h.querySelector("a.mark");d(c);(c=h.querySelector("a.mark"))&&c.setAttribute("data-action","mark-unread")}l--;b()}};c.open("POST","?action=mark-item-read&id="+ +f,!0);c.send()}function t(h){var c=e(h),n=new XMLHttpRequest;n.onload=function(){if(m.a()){if(h.getAttribute("data-hide"))a(h);else{h.setAttribute("data-item-status","unread");var c=h.querySelector("a.mark");d(c);(c=h.querySelector("a.mark"))&&c.setAttribute("data-action","mark-read")}l++;b()}};n.open("POST","?action=mark-item-unread&id="+c,!0);n.send()}var l=function(){var a=document.getElementById("nav-counter");if(a)return counter=parseInt(a.textContent,10)||0}(),p=function(){var a=document.getElementById("page-counter"); +if(a)return counter=parseInt(a.textContent,10)||0}();return{m:c,o:t,n:function(c){var f=e(c),d=new XMLHttpRequest;d.onload=function(){m.a()&&(a(c),"unread"===c.getAttribute("data-item-status")&&l--,b())};d.open("POST","?action=mark-item-removed&id="+f,!0);d.send()},h:function(c){var f=e(c),n="1"===c.getAttribute("data-item-bookmark")?"0":"1",r=new XMLHttpRequest;r.onload=function(){var f=document.querySelector("section.page");if(m.a()&&"bookmarks"===f.getAttribute("data-item-page"))a(c),b();else if(c.setAttribute("data-item-bookmark", +n),m.a())f=c.querySelector("a.bookmark"),d(f);else if((f=c.querySelector("a.bookmark-icon"))&&f.hasAttribute("data-reverse-title")){var e=f.getAttribute("title");f.setAttribute("title",f.getAttribute("data-reverse-title"));f.setAttribute("data-reverse-title",e)}};r.open("POST","?action=bookmark&id="+f+"&value="+n,!0);r.send()},t:function(a){var b=a.getAttribute("data-item-status");"read"===b?t(a):"unread"===b&&c(a)},r:function(a){(a=a.querySelector("a.show"))&&a.click()},f:function(a){var b=a.querySelector("a.original"); +b&&("unread"===a.getAttribute("data-item-status")&&c(a),b.removeAttribute("data-action"),"mouse"!==k.b&&b.click())},d:function(a){var b=document.getElementById("download-item");if(b){b.innerHTML=" "+b.getAttribute("data-before-message");b.className="loading-icon";var c=new XMLHttpRequest;c.onload=function(){var a=JSON.parse(c.responseText);b.className="";if(a.result){var d=document.getElementById("item-content");d&&(d.innerHTML=a.content);b.innerHTML=b.getAttribute("data-after-message")}else b.innerHTML= +b.getAttribute("data-failure-message")};a=e(a);c.open("POST","?action=download-item&id="+a,!0);c.send()}},e:function(a){for(var b=document.getElementsByTagName("article"),c=[],d=0,l=b.length;db-(a.offsetTop+a.offsetHeight)||b-a.offsetTop>document.documentElement.clientHeight)&&window.scrollTo(0,a.offsetTop-10)}function d(){return document.getElementById("listing")?!0:!1}return{p:function(){var a=document.getElementById("next-page");a&&a.click()},q:function(){var a=document.getElementById("previous-page"); +a&&a.click()},c:function(){var a=document.getElementById("next-item");if(a)a.click();else if(d())if(a=document.getElementsByTagName("article"),document.getElementById("current-item"))for(var b=0,c=a.length;b 0 && queue.length < queue_length) { var feed = feeds.shift(); - queue.push(parseInt(feed.getAttribute('data-feed-id'))); + queue.push(parseInt(feed.getAttribute('data-feed-id'), 10)); Miniflux.Feed.Update(feed, function(response) { - var index = queue.indexOf(response.feed_id); + var index = queue.indexOf(response['feed_id']); if (index >= 0) queue.splice(index, 1); if (feeds.length === 0 && queue.length === 0) { diff --git a/assets/js/item.js b/assets/js/item.js index d9e1867..c34fd98 100644 --- a/assets/js/item.js +++ b/assets/js/item.js @@ -2,7 +2,7 @@ Miniflux.Item = (function() { var nbUnreadItems = function() { var navCounterElement = document.getElementById("nav-counter"); - + if (navCounterElement) { counter = parseInt(navCounterElement.textContent, 10) || 0; return counter; @@ -11,7 +11,7 @@ Miniflux.Item = (function() { var nbPageItems = function() { var pageCounterElement = document.getElementById("page-counter"); - + if (pageCounterElement) { counter = parseInt(pageCounterElement.textContent, 10) || 0; return counter; @@ -58,7 +58,7 @@ Miniflux.Item = (function() { var link = item.querySelector("a.mark"); if (link) link.setAttribute("data-action", "mark-unread"); } - + nbUnreadItems--; updateCounters(); } @@ -76,7 +76,7 @@ Miniflux.Item = (function() { var link = item.querySelector("a.mark"); if (link) link.setAttribute("data-action", "mark-read"); } - + nbUnreadItems++; updateCounters(); } @@ -100,9 +100,9 @@ Miniflux.Item = (function() { var pageCounterElement = document.getElementById("page-counter"); pageCounterElement.textContent = nbPageItems || ''; - + var navCounterElement = document.getElementById("nav-counter"); - navCounterElement.textContent = nbUnreadItems || ''; + navCounterElement.textContent = nbUnreadItems || ''; // pagetitle depends on current page var sectionElement = document.querySelector("section.page"); @@ -151,7 +151,7 @@ Miniflux.Item = (function() { request.onload = function() { if (Miniflux.Nav.IsListing()) { hideItem(item); - + if (item.getAttribute("data-item-status") === "unread") nbUnreadItems--; updateCounters(); } @@ -171,7 +171,7 @@ Miniflux.Item = (function() { request.onload = function() { var sectionElement = document.querySelector("section.page"); - + if (Miniflux.Nav.IsListing() && sectionElement.getAttribute("data-item-page") === "bookmarks") { hideItem(item); updateCounters(); @@ -229,24 +229,24 @@ Miniflux.Item = (function() { container.innerHTML = " " + container.getAttribute("data-before-message"); container.className = "loading-icon"; - + var request = new XMLHttpRequest(); request.onload = function() { var response = JSON.parse(request.responseText); container.className = ""; - - if (response.result) { + + if (response['result']) { var content = document.getElementById("item-content"); - if (content) content.innerHTML = response.content; - + if (content) content.innerHTML = response['content']; + container.innerHTML = container.getAttribute("data-after-message"); } else { container.innerHTML = container.getAttribute("data-failure-message"); } }; - + var item_id = getItemID(item); request.open("POST", "?action=download-item&id=" + item_id, true); request.send(); diff --git a/scripts/make-js.sh b/scripts/make-js.sh index a4ab70f..b5fa10d 100755 --- a/scripts/make-js.sh +++ b/scripts/make-js.sh @@ -9,11 +9,22 @@ rm -f $out 2>/dev/null cat assets/js/app.js assets/js/feed.js assets/js/item.js assets/js/event.js assets/js/nav.js > $in echo "Miniflux.App.Run();" >> $in -curl -s \ --d compilation_level=SIMPLE_OPTIMIZATIONS \ --d output_format=text \ --d output_info=compiled_code \ ---data-urlencode "js_code@${in}" \ -https://closure-compiler.appspot.com/compile > $out +output=$(curl -s \ + -d compilation_level=ADVANCED_OPTIMIZATIONS \ + -d output_format=text \ + -d output_info=warnings \ + -d output_info=errors \ + -d warning_level=verbose \ + -d output_file_name=all.min.js \ + --data-urlencode "js_code@${in}" \ + https://closure-compiler.appspot.com/compile) + +if [ $(echo "$output" | wc -l) -gt 1 ]; then + echo -e "NOTHING DONE. There are issues:\n" + echo "$output" + exit 1 +fi + +curl -s "https://closure-compiler.appspot.com/$output" -o "$out"; rm -f $in