From 3dae99ac2771c73da2613c04dc219ea62b987ac4 Mon Sep 17 00:00:00 2001 From: Mathias Kresin Date: Tue, 16 Sep 2014 20:42:15 +0200 Subject: [PATCH] remove multiple definition of item id The item id exists as data attribute or as element.id postfix on multiple elements in an article. The basic idea is to traverse the DOM tree - starting from the event firing element - in reverse order till an article element is found. This article element is passed to the JavaScript functions. These JavaScript functions are getting the elements which they want to manipulate starting from the article utilizing the JavaScript querySelector function. The bootstrap themes had a conflicting and unused class style definied, which is removed by now. --- assets/js/all.min.js | 40 ++-- assets/js/event.js | 45 +++-- assets/js/item.js | 183 +++++++------------ assets/js/nav.js | 8 - templates/bookmark_links.php | 7 +- templates/item.php | 5 +- templates/show_item.php | 11 +- templates/status_links.php | 10 +- themes/bootstrap-light/css/app.css | 3 - themes/bootstrap-light/less/utilities.less | 3 - themes/bootswatch-cyborg/css/app.css | 3 - themes/bootswatch-cyborg/less/utilities.less | 3 - themes/cards/css/app.css | 12 +- themes/hello/css/app.css | 8 +- themes/hello/scss/_items.scss | 8 +- 15 files changed, 137 insertions(+), 212 deletions(-) diff --git a/assets/js/all.min.js b/assets/js/all.min.js index eb500b5..2fcad6e 100644 --- a/assets/js/all.min.js +++ b/assets/js/all.min.js @@ -1,21 +1,19 @@ -var Miniflux={};Miniflux.App=function(){return{BlinkIcon:function(){var e=document.querySelectorAll(".loading-icon");[].forEach.call(e,function(b){b.classList.toggle("loading-icon-blink")})},Run:function(){Miniflux.Event.ListenKeyboardEvents();Miniflux.Event.ListenMouseEvents()}}}(); -Miniflux.Feed=function(){function e(a){if(a=document.getElementById("loading-feed-"+a))a.appendChild(document.createTextNode("\u2600")),a.classList.add("loading-icon-blink");f||(f=setInterval(Miniflux.App.BlinkIcon,500))}function b(){for(var b=document.getElementsByTagName("a"),d=0,c=b.length;dd.length;){var b=a.shift();d.push(b);Miniflux.Feed.Update(b, -function(c){c=d.indexOf(c.feed_id);0<=c&&d.splice(c,1);0==a.length&&0==d.length&&(clearInterval(e),clearInterval(f),window.location.href="?action=unread")})}},100)}}}(); -Miniflux.Item=function(){function e(c){var a=document.getElementById("item-"+c);a||(a=document.getElementById("current-item"),a.getAttribute("data-item-id")!=c&&(a=!1));return a}function b(c){if(c&&c.getAttribute("data-reverse-label")){var a=c.innerHTML;c.innerHTML=c.getAttribute("data-reverse-label");c.setAttribute("data-reverse-label",a)}}function a(c){c=document.getElementById("status-"+c);b(c)}function d(c){"mouse"!=Miniflux.Event.lastEventType&&Miniflux.Nav.SelectNextItem();c.parentNode.removeChild(c); -var a=document.getElementById("page-counter");if(a){c=c.getAttribute("data-item-page");var b=parseInt(a.textContent,10)-1,d=document.getElementsByTagName("article");if(0===b||0===d.length)window.location=location.href;a.textContent=b;switch(c){case "unread":document.title="Miniflux ("+b+")";document.getElementById("nav-counter").textContent=b;break;case "feed-items":document.title="("+b+") "+a.parentNode.firstChild.nodeValue;break;default:document.title=a.parentNode.firstChild.nodeValue+" ("+b+")"}}} -function f(c){var b=new XMLHttpRequest;b.onload=function(){if(Miniflux.Nav.IsListing()){var b=e(c);b&&(b.getAttribute("data-hide")?d(b):(b.setAttribute("data-item-status","read"),a(c),(link=document.getElementById("status-"+c))&&link.setAttribute("data-action","mark-unread")))}};b.open("POST","?action=mark-item-read&id="+c,!0);b.send()}function h(c){var b=new XMLHttpRequest;b.onload=function(){if(Miniflux.Nav.IsListing()){var b=e(c);b&&(b.getAttribute("data-hide")?d(b):(b.setAttribute("data-item-status", -"unread"),a(c),(link=document.getElementById("status-"+c))&&link.setAttribute("data-action","mark-read")))}};b.open("POST","?action=mark-item-unread&id="+c,!0);b.send()}function k(c,a){var d=c.getAttribute("data-item-id"),e=new XMLHttpRequest;e.onload=function(){try{if(JSON.parse(this.responseText).result&&(c.setAttribute("data-item-bookmark",a),Miniflux.Nav.IsListing())){var e=document.getElementById("bookmark-"+d);b(e)}}catch(f){}};e.open("POST","?action=bookmark&id="+d+"&value="+a,!0);e.send()} -return{Get:e,MarkAsRead:f,MarkAsUnread:h,MarkAsRemoved:function(c){var a=new XMLHttpRequest;a.onload=function(){Miniflux.Nav.IsListing()&&d(e(c))};a.open("POST","?action=mark-item-removed&id="+c,!0);a.send()},SwitchBookmark:function(c){"1"==c.getAttribute("data-item-bookmark")?k(c,0):k(c,1)},SwitchStatus:function(c){var a=c.getAttribute("data-item-id");c=c.getAttribute("data-item-status");"read"==c?h(a):"unread"==c&&f(a)},Show:function(a){(a=document.getElementById("show-"+a))&&a.click()},OpenOriginal:function(a){var b= -document.getElementById("original-"+a);b&&("unread"==e(a).getAttribute("data-item-status")&&f(a),b.removeAttribute("data-action"),b.click())},DownloadContent:function(){var a=document.getElementById("download-item");if(a){var b=a.getAttribute("data-item-id"),d=a.getAttribute("data-before-message"),e=document.createElement("span");e.appendChild(document.createTextNode("\u2600"));e.className="loading-icon";a.innerHTML="";a.className="downloading";a.appendChild(e);a.appendChild(document.createTextNode(" "+ -d));var f=setInterval(Miniflux.App.BlinkIcon,250),g=new XMLHttpRequest;g.onload=function(){var b=JSON.parse(g.responseText);clearInterval(f);if(b.result){var d=document.getElementById("item-content");d&&(d.innerHTML=b.content);a&&(b=a.getAttribute("data-after-message"),a.innerHTML="",a.appendChild(document.createTextNode(" "+b)))}else a&&(b=a.getAttribute("data-failure-message"),a.innerHTML="",a.appendChild(document.createTextNode(" "+b)))};g.open("POST","?action=download-item&id="+b,!0);g.send()}}, -MarkListingAsRead:function(a){for(var b=document.getElementsByTagName("article"),d=[],e=0,f=b.length;eb-(a.offsetTop+a.offsetHeight)||b-a.offsetTop>document.documentElement.clientHeight)&&window.scrollTo(0,a.offsetTop-10)}function b(){return document.getElementById("listing")?!0:!1}return{GetCurrentItem:function(){return document.getElementById("current-item")},GetCurrentItemId:function(){var a=Miniflux.Nav.GetCurrentItem();return a?a.getAttribute("data-item-id"):null},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(b())if(a=document.getElementsByTagName("article"),document.getElementById("current-item"))for(var d=0,f=a.length;da.length;){var h=b.shift();a.push(h);Miniflux.Feed.Update(h, +function(h){h=a.indexOf(h.feed_id);0<=h&&a.splice(h,1);0==b.length&&0==a.length&&(clearInterval(d),clearInterval(g),window.location.href="?action=unread")})}},100)}}}(); +Miniflux.Item=function(){function e(d){return item_id=d.getAttribute("data-item-id")}function c(d){if(d&&d.hasAttribute("data-reverse-label")){var b=d.innerHTML;d.innerHTML=d.getAttribute("data-reverse-label");d.setAttribute("data-reverse-label",b)}}function b(d){"mouse"!==Miniflux.Event.lastEventType&&Miniflux.Nav.SelectNextItem();d.parentNode.removeChild(d);var b=document.getElementById("page-counter");if(b){d=d.getAttribute("data-item-page");var a=parseInt(b.textContent,10)-1,c=document.getElementsByTagName("article"); +if(0===a||0===c.length)window.location=location.href;b.textContent=a;switch(d){case "unread":document.title="Miniflux ("+a+")";document.getElementById("nav-counter").textContent=a;break;case "feed-items":document.title="("+a+") "+b.parentNode.firstChild.nodeValue;break;default:document.title=b.parentNode.firstChild.nodeValue+" ("+a+")"}}}function a(d){var a=e(d),f=new XMLHttpRequest;f.onload=function(){if(Miniflux.Nav.IsListing())if(d.getAttribute("data-hide"))b(d);else{d.setAttribute("data-item-status", +"read");var a=d.querySelector("a.mark");c(a);(a=d.querySelector("a.mark"))&&a.setAttribute("data-action","mark-unread")}};f.open("POST","?action=mark-item-read&id="+a,!0);f.send()}function g(d){var a=e(d),f=new XMLHttpRequest;f.onload=function(){if(Miniflux.Nav.IsListing())if(d.getAttribute("data-hide"))b(d);else{d.setAttribute("data-item-status","unread");var a=d.querySelector("a.mark");c(a);(a=d.querySelector("a.mark"))&&a.setAttribute("data-action","mark-read")}};f.open("POST","?action=mark-item-unread&id="+ +a,!0);f.send()}return{MarkAsRead:a,MarkAsUnread:g,MarkAsRemoved:function(a){var c=e(a),f=new XMLHttpRequest;f.onload=function(){Miniflux.Nav.IsListing()&&b(a)};f.open("POST","?action=mark-item-removed&id="+c,!0);f.send()},SwitchBookmark:function(a){var b=e(a),f="1"===a.getAttribute("data-item-bookmark")?"0":"1",k=new XMLHttpRequest;k.onload=function(){a.setAttribute("data-item-bookmark",f);if(Miniflux.Nav.IsListing()){var b=a.querySelector("a.bookmark");c(b)}};k.open("POST","?action=bookmark&id="+ +b+"&value="+f,!0);k.send()},SwitchStatus:function(b){var c=b.getAttribute("data-item-status");"read"===c?g(b):"unread"===c&&a(b)},Show:function(a){(a=a.querySelector("a.show"))&&a.click()},OpenOriginal:function(b){var c=b.querySelector("a.original");c&&("unread"===b.getAttribute("data-item-status")&&a(b),c.removeAttribute("data-action"),c.click())},DownloadContent:function(a){var b=document.getElementById("download-item");if(b){a=e(a);var c=b.getAttribute("data-before-message"),k=document.createElement("span"); +k.appendChild(document.createTextNode("\u2600"));k.className="loading-icon";b.innerHTML="";b.className="downloading";b.appendChild(k);b.appendChild(document.createTextNode(" "+c));var g=setInterval(Miniflux.App.BlinkIcon,250),l=new XMLHttpRequest;l.onload=function(){var a=JSON.parse(l.responseText);clearInterval(g);if(a.result){var c=document.getElementById("item-content");c&&(c.innerHTML=a.content);b&&(a=b.getAttribute("data-after-message"),b.innerHTML="",b.appendChild(document.createTextNode(" "+ +a)))}else b&&(a=b.getAttribute("data-failure-message"),b.innerHTML="",b.appendChild(document.createTextNode(" "+a)))};l.open("POST","?action=download-item&id="+a,!0);l.send()}},MarkListingAsRead:function(b){for(var a=document.getElementsByTagName("article"),c=[],g=0,m=a.length;ga-(b.offsetTop+b.offsetHeight)||a-b.offsetTop>document.documentElement.clientHeight)&&window.scrollTo(0,b.offsetTop-10)}function c(){return document.getElementById("listing")?!0:!1}return{OpenNextPage:function(){var b=document.getElementById("next-page");b&&b.click()},OpenPreviousPage:function(){var b=document.getElementById("previous-page");b&&b.click()},SelectNextItem:function(){var b=document.getElementById("next-item"); +if(b)b.click();else if(c())if(b=document.getElementsByTagName("article"),document.getElementById("current-item"))for(var a=0,g=b.length;a diff --git a/templates/item.php b/templates/item.php index d07d17d..a1b089e 100644 --- a/templates/item.php +++ b/templates/item.php @@ -12,8 +12,7 @@ @@ -37,7 +36,7 @@
  • - +
  • diff --git a/templates/show_item.php b/templates/show_item.php index 085e12f..78464e8 100644 --- a/templates/show_item.php +++ b/templates/show_item.php @@ -31,28 +31,24 @@

    $feed['rtl'])) ? 'dir="rtl"' : '' ?>> - +

    • @@ -74,7 +70,6 @@
    • diff --git a/templates/status_links.php b/templates/status_links.php index d0ed27a..00adfeb 100644 --- a/templates/status_links.php +++ b/templates/status_links.php @@ -2,26 +2,22 @@
    • diff --git a/themes/bootstrap-light/css/app.css b/themes/bootstrap-light/css/app.css index 70bc1e4..dd5ed50 100644 --- a/themes/bootstrap-light/css/app.css +++ b/themes/bootstrap-light/css/app.css @@ -4532,9 +4532,6 @@ article.item > .panel-footer + .panel-collapse .panel-body, .hide { display: none !important; } -.show { - display: block !important; -} .invisible { visibility: hidden; } diff --git a/themes/bootstrap-light/less/utilities.less b/themes/bootstrap-light/less/utilities.less index 3d310e6..babea6d 100644 --- a/themes/bootstrap-light/less/utilities.less +++ b/themes/bootstrap-light/less/utilities.less @@ -23,9 +23,6 @@ .hide { display: none !important; } -.show { - display: block !important; -} .invisible { visibility: hidden; } diff --git a/themes/bootswatch-cyborg/css/app.css b/themes/bootswatch-cyborg/css/app.css index 9a40a0b..0b4fa74 100644 --- a/themes/bootswatch-cyborg/css/app.css +++ b/themes/bootswatch-cyborg/css/app.css @@ -4532,9 +4532,6 @@ article.item > .panel-footer + .panel-collapse .panel-body, .hide { display: none !important; } -.show { - display: block !important; -} .invisible { visibility: hidden; } diff --git a/themes/bootswatch-cyborg/less/utilities.less b/themes/bootswatch-cyborg/less/utilities.less index 3d310e6..babea6d 100644 --- a/themes/bootswatch-cyborg/less/utilities.less +++ b/themes/bootswatch-cyborg/less/utilities.less @@ -23,9 +23,6 @@ .hide { display: none !important; } -.show { - display: block !important; -} .invisible { visibility: hidden; } diff --git a/themes/cards/css/app.css b/themes/cards/css/app.css index d8aaca6..3b5f176 100644 --- a/themes/cards/css/app.css +++ b/themes/cards/css/app.css @@ -159,9 +159,9 @@ nav .active a { color: #929292; } -.items .item-menu .item-bookmark, -.items .item-menu .item-delete, -.items .item-menu .item-mark{ +.items .item-menu .bookmark, +.items .item-menu .delete, +.items .item-menu .mark{ color: transparent; text-indent: -9999px; background-repeat: no-repeat; @@ -171,15 +171,15 @@ nav .active a { height: 15px; } -.items .item-menu .item-bookmark{ +.items .item-menu .bookmark{ background-image: url("../img/star.png"); } -.items .item-menu .item-delete{ +.items .item-menu .delete{ background-image: url("../img/cross.png"); } -.items .item-menu .item-mark{ +.items .item-menu .mark{ background-image: url("../img/tick.png"); } diff --git a/themes/hello/css/app.css b/themes/hello/css/app.css index 3982a23..5a89ffe 100755 --- a/themes/hello/css/app.css +++ b/themes/hello/css/app.css @@ -313,9 +313,9 @@ article[data-item-bookmark="0"] .bookmark-icon:before { background-color: rgba(153, 153, 153, 0.7); } .items article[data-item-status="read"] .read-icon:before { content: "✔"; } - .items article[data-item-bookmark="1"] .item-menu a[id*="bookmark-"]:before { + .items article[data-item-bookmark="1"] .item-menu a.bookmark:before { content: "\f088"; } - .items article[data-item-bookmark="0"] .item-menu a[id*="bookmark-"]:before { + .items article[data-item-bookmark="0"] .item-menu a.bookmark:before { content: "\f087"; } .items article h2 { display: block; @@ -350,7 +350,7 @@ article[data-item-bookmark="0"] .bookmark-icon:before { margin-right: 2px; } .items .item-menu li a:first-child:before { content: "\f0b0"; } - .items .item-menu li a[id*="original-"]:before { + .items .item-menu li a.original:before { content: "\f08e"; } .items .item-menu li a[href*="action=confirm-remove-feed"]:before { content: "\f014"; } @@ -361,7 +361,7 @@ article[data-item-bookmark="0"] .bookmark-icon:before { .items .item-menu li a[href*="action=mark-item-removed"]:before { content: "\f014"; margin-right: 2px; } - .items .item-menu li a[id*="status-"]:before { + .items .item-menu li a.mark:before { content: "\f058"; } .items .item-menu li a[href*="action=disable-grabber-feed"]:before { content: "\f057"; } diff --git a/themes/hello/scss/_items.scss b/themes/hello/scss/_items.scss index 68952fe..61e4195 100755 --- a/themes/hello/scss/_items.scss +++ b/themes/hello/scss/_items.scss @@ -33,7 +33,7 @@ article { &[data-item-bookmark="1"] { .item-menu { a { - &[id*="bookmark-"] { + &.bookmark { &:before { content: "\f088"; } @@ -45,7 +45,7 @@ article { &[data-item-bookmark="0"] { .item-menu { a { - &[id*="bookmark-"] { + &.bookmark { &:before { content: "\f087"; } @@ -107,7 +107,7 @@ article { content: "\f0b0"; } } - &[id*="original-"] { + &.original { &:before { content: "\f08e"; } @@ -135,7 +135,7 @@ article { } } - &[id*="status-"] { + &.mark { &:before { content: "\f058"; }