User:Saftzie/ui.wall.js

/* * Description: * Hide the wall notifications in the personal portlet if there aren't any * Wikia only sets visibility to hidden, so it still takes up space * * Version 1.0: 17 July 2014 */

window.user = window.user || {}; window.user.ui = window.user.ui || {}; window.user.ui.wall = (function ($) { 'use strict';

var self = {}, domLi, domSpan;

function onTimer {   if (domSpan.innerHTML === '(0)') {     domLi.style.display = 'none'; }   else {     domLi.style.display = 'inline'; } }

// keep trying to init the globals until success $(function init {    var i,        bFound;

self.idTimeout = undefined; self.idInterval = undefined;

domLi = document.getElementById('pt-wall-notifications'); if (!domLi) {     self.idTimeout = window.setTimeout(init, 1000); return; }   domSpan = domLi.getElementsByTagName('span'); if (domSpan.length === 0) {     self.idTimeout = window.setTimeout(init, 1000); return; }   bFound = false; for (i = 0 ; (!bFound) && (i < domSpan.length) ; ++i) {     if (domSpan[i].className === 'count') {       bFound = true; domSpan = domSpan[i]; }   }    if (!bFound) {     self.idTimeout = window.setTimeout(init, 1000); return; }   // globals are init'ed    self.idInterval = window.setInterval(onTimer, 1000); });

self.onTimer = onTimer;

return self; }(jQuery));