User:Avron/monobook.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
function cat_a_lot_alter_label ( title , mode ) {
  var divs = document.getElementsByTagName ( cat_a_lot_divtype ) ;
  for ( i = 0 ; i < divs.length ; i++ ) {
    if ( divs[i].className != cat_a_lot_classname ) continue ;
    var files = divs[i].getElementsByTagName ( "a" ) ;
    if ( files.length == 0 ) continue ;
    
    //if ( files[0].title != title ) continue ; OLD
    //----START NEW--------
    if ( cat_a_lot_searchmode ){
      if ( files[1].title != title ) continue ;
    }
    else 
    {
      if ( files[0].title != title ) continue ;
    }
    //----END NEW----------   

    if ( mode == "move" ) {
      divs[i].innerHTML = "<div style='width:100%;color:white;background-color:red;text-align:center'>Moved to new category</div>" ;
      divs[i].style.backgroundColor = "#FF0000" ;
    } else if ( mode == "remove" ) {
      divs[i].innerHTML = "<div style='width:100%;color:white;background-color:red;text-align:center'>Removed from category</div>" ;
      divs[i].style.backgroundColor = "#FF0000" ;
    } else if ( mode == "copy" ) {
      divs[i].innerHTML += "<br/><b>Copied to new category!</b>" ;
    }
 
    // Clicked on this element
    if ( divs[i].style.backgroundColor != "" ) {
      divs[i].style.backgroundColor = "" ;
    } else {
      divs[i].style.backgroundColor = cat_a_lot_mark_color ;
    }
    cat_a_lot_update_selection_counter () ;
    return ;
  }
}

function cat_a_lot_mark_all ( how ) {
  var divs = document.getElementsByTagName ( cat_a_lot_divtype ) ;
  var title ="";
  for ( i = 0 ; i < divs.length ; i++ ) {
    if ( divs[i].className != cat_a_lot_classname ) continue ;

    var files = divs[i].getElementsByTagName ( "a" ) ;
    if ( files.length == 0 ) continue ;
    
    divs[i].style.backgroundColor = "" ; // Deselect
    if ( how == 1 ) { // Activate  
      if ( cat_a_lot_searchmode ) 
        divs[i] = divs[i].getElementsByTagName('div')[0] ;

      if ( cat_a_lot_searchmode )
        title=files[1].title;
      else 
        title=files[0].title;

      //eval("divs[i].onclick = function () { cat_a_lot_on_click_label('" + cat_a_lot_fix_quotes ( files[0].title , "'" ) + "'); };") ; //OLD
      eval("divs[i].onclick = function () { cat_a_lot_on_click_label('" + cat_a_lot_fix_quotes ( title , "'" ) + "'); };") ; //NEW    
    } else if ( how == 2 ) { // Select
      divs[i].style.backgroundColor = cat_a_lot_mark_color ;
    } else if ( how == 0 ) { // Deactivate
      divs[i].onclick = "" ;
    }
  }
  cat_a_lot_update_selection_counter () ;
}

function cat_a_lot_get_marked_labels () {
  var ret = new Array () ;
  var divs = document.getElementsByTagName ( cat_a_lot_divtype ) ;
  for ( i = 0 ; i < divs.length ; i++ ) {
    if ( divs[i].className != cat_a_lot_classname ) continue ;
    if ( divs[i].style.backgroundColor == "" ) continue ;
    var files = divs[i].getElementsByTagName ( "a" ) ;
    var t = files[0].title ;
    // if ( cat_a_lot_searchmode ) t = "File:" + t ; OLD    
    if ( cat_a_lot_searchmode ) t = files[1].title ; //NEW

    ret.push ( t ) ;
  }
  return ret ;
}