מדיה ויקי:Gadget-HotCat.js: הבדלים בין גרסאות בדף

מאין תקציר עריכה
Also enable HotCat when there are no categories yet. Code from User:TheDJ, adapted by User:Lupo
שורה 84: שורה 84:
   var form = document.getElementById ('upload');
   var form = document.getElementById ('upload');
   hotcat_old_onsubmit = form.onsubmit;
   hotcat_old_onsubmit = form.onsubmit;
   form.onsubmit =hotcat_on_upload;
   form.onsubmit = hotcat_on_upload;
  //var sub = document.getElementsByName("wpUpload")[0] ;
  //sub.onclick = hotcat_on_upload ;
  //sub.type = "button" ;
}
}


שורה 116: שורה 113:
   }
   }
   return true;
   return true;
  //var sub = document.getElementsByName("wpUpload")[0] ;
  //sub.onclick = "" ;
  //sub.type = "submit" ;
  //sub.click();
}
}


שורה 130: שורה 121:
   hotcat_check_upload () ;
   hotcat_check_upload () ;


   var catline =
   if(    document.getElementById('ca-viewsource' ) != null // User has no permission to edit
    document.getElementById ('mw-normal-catlinks') ||
      || wgAction != 'view'                        // User is editing or previewing or...
    getElementsByClassName ( document , "p" , "catlinks" ) [0];
      || wgNamespaceNumber == -1 && !hotcat_upload) // Special page other than Special:Upload
  if ( catline == null || typeof catline == 'undefined' ) return ;
  return;  


   // Do not add interface to protected pages, if user has no edit permission
   var visible_cats =
  // Also disable it on preview pages: on a prview, we *are* already editing,
    document.getElementById ('mw-normal-catlinks') ||          // MW 1.13alpha
  // and HotCat must not open the page for editing a second time. Lupo, 2008-02-27
    getElementsByClassName ( document , "p" , "catlinks" ) [0]; // MW < 1.13 && Special:Upload
  if(   document.getElementById('ca-viewsource' ) != null
  var hidden_cats =
       || wgAction == 'submit') return;  
    document.getElementById ('mw-hidden-catlinks');
  if (visible_cats == null) {
    // Insert an empty category line
    var footer = null;
    if (hidden_cats == null) {
      footer = getElementsByClassName (document , "div" , "printfooter")[0];
      if (!footer) return; // Don't know where to insert the category line
    }
    visible_cats = document.createElement ('div');
    visible_cats.setAttribute ('id', 'mw-normal-catlinks');
    var label = document.createElement ('a');
    label.setAttribute ('href', wgArticlePath.replace (/\$1/, 'Special:Categories'));
    label.setAttribute ('title', 'Special:Categories');
    label.appendChild (document.createTextNode ('Category'));
    visible_cats.appendChild (label);
    visible_cats.appendChild (document.createTextNode (':'));
    if (hidden_cats == null) {
      var container = document.createElement ('div');
       container.setAttribute ('id', 'catlinks');
      var tmp = document.createElement ('div');
      tmp.className = 'catlinks';
      tmp.appendChild (visible_cats);
      container.appendChild (tmp);
      footer.parentNode.insertBefore (container, footer.nextSibling);
    } else {
      hidden_cats.parentNode.insertBefore (visible_cats, hidden_cats);
    }
  } // end if no categories


   hotcat_modify_existing ( catline ) ;
   hotcat_modify_existing ( visible_cats ) ;
   hotcat_append_add_span ( catline ) ;
   hotcat_append_add_span ( visible_cats ) ;


   // Check for state restoration (Lupo, 2008-02-06)
   // Check for state restoration (Lupo, 2008-02-06)
שורה 154: שורה 172:
function hotcat_append_add_span ( catline ) {
function hotcat_append_add_span ( catline ) {
   var span_add = document.createElement ( "span" ) ;
   var span_add = document.createElement ( "span" ) ;
   var span_sep = document.createTextNode ( " | " ) ;
   if ( catline.getElementsByTagName('span')[0] )
   if ( catline.firstChild ) catline.appendChild ( span_sep ) ;
    catline.appendChild (document.createTextNode (" | "));
   catline.appendChild ( span_add ) ;
   else if (catline.firstChild)
   hotcat_create_span ( span_add ) ;
    catline.appendChild (document.createTextNode (' '));
   catline.appendChild ( span_add );
   hotcat_create_span ( span_add );
}
}