User:לערי ריינהארט/sandbox.js

From Wikidata
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
//<nowiki>
( function ( mw, $ )
{
  function init() {
    $('#p-search').append('<script type="text/javascript">' +

      'var my_prop = 1036;' +
      'var value_field_value = 700;' +

      'function collapse(my_prop,value_field_value) {' +
        'document.getElementById(\'prop_field\').style.display = \'none\';' +
        'document.getElementById(\'prop_field_value\').style.display = \'none\';' +
        'document.getElementById(\'value_field\').style.display = \'none\';' +
        'document.getElementById(\'value_field_value\').style.display = \'none\';' +
        'document.getElementById(\'do_btn_prop\').style.display = \'none\';' +
        'document.getElementById(\'show_btn_prop\').style.display = \'inline\';' +
      '}' +
/*
      'function add_prop(my_prop) {' +
        '$("#properties").selectbox();' +
        'var prop_div = document.getElementById(\'prop_box\');' +
        'if (prop_div) {' +
          'add_prop.opt = {' +
            'propTitleText: \'properties\',' +
            'offWhite: \'#f1f1f1\',' +
            'lightGrey: \'#d9d9d9\',' +
            'blue: \'#c0c0dd\',' +
            'go: \' select \',' +
            '}' +
            //form add_prop.addProp("property_name", "property_id");
            'add_prop.addProp(\'ISO 639-1\', 218);' +
            'add_prop.addProp(\'ISO 639-2\', 219);' +
            'add_prop.addProp(\'ISO 639-3\', 220);' +
            'add_prop.addProp(\'ISO 639-6\', 221);' +
            'add_prop.addProp(\'ISO 15924\', 506);' +
            'add_prop.addProp(\'Wikimedia language code\', 424);' +
            'add_prop.addProp(\'BNCF Thesaurus\', 508);' +
            'add_prop.addProp(\'Dewey Decimal Classification\', 1036);' +
            'add_prop.addProp(\'Freebase identifier\', 646);' +
            'add_prop.addProp(\'GND identifier\', 227);' +
            'add_prop.addProp(\'NDL identifier\', 349);' +
            'add_prop.addProp(\'GOST 7.75-97 code\', 278);' +
            'add_prop.addProp(\'OmegaWiki Defined Meaning\', 1245);' +
            'add_prop.addProp(\'VIAF identifier\', 214);' +
 
            'add_prop.con = { propSelect: \'propValueSelect\' };' +

            'var my_prop = new_element(\'select\', {name: \'property_name\', id: add_prop.con.propValueSelect, onchange: \'prop_propChange(this.selectedIndex);\'}, document.getElementById(\'property_id\'));' +
            'return my_prop;' +
          '}' +
      '}' +

       'function prop_selectionChange(my_prop) {' +
         'var my_prop = document.getElementById(add_prop.con.propValueSelect);' +
         'return my_prop;' +
      '}' +
**/
     'function show(my_prop,value_field_value) {' +
        'document.getElementById(\'prop_field\').style.display = \'inline\';' +
        'document.getElementById(\'prop_field_value\').style.display = \'inline\';' +
        'document.getElementById(\'value_field\').style.display = \'inline\';' +
        'document.getElementById(\'value_field_value\').style.display = \'inline\';' +
        'document.getElementById(\'do_btn_prop\').style.display = \'inline\';' +
        'document.getElementById(\'show_btn_prop\').style.display = \'none\';' +
      '}' +

      'function submit(my_prop) {' +
        'var search_value = document.getElementById(\'value_field_value\').value;' +
        'var lang = \'' + mw.user.options.get( 'language' ) + 'wiki\';' +
        'document.location.href = \'http://tools.wmflabs.org/wikidata-todo/autolist.html?lang=\' + lang + \'&q=string%5B\' + my_prop + \'%3A%22\' + search_value + \'%22%5D\' ;' +
        'document.location.target = \'_blank\';' +
      '}' +

      'function onKeypress(e) {' +
        'if (e.keyCode == 13) {' +
          'submit();' +
        '}' +
      '}' +

      'function checkButton(value_field_value) {' +
        'if(document.getElementById(\'value_field_value\').value != \'\') {' +
          'document.getElementById(\'do_btn_prop\').disabled = false;' +
        '}' +
        'else {' +
          'document.getElementById(\'do_btn_prop\').disabled = true;' +
          'return value_field_value;' +
        '}' +
      '}' +
      '</script>' +
      '<button style="margin: 0; padding: 0; display: none;" onclick="javascript:show(my_prop,value_field_value);" id="show_btn_prop">↓</button>' +
      '<div id="value_field" style="background-color: white; border: 1px solid #AAAAAA; color: black; display: block; height: 1.4em; margin-top: 7px; min-height: 1px; width: 14em;">' +
      '<input type="text" style="font-family: sans-serif; display: inline; background-color: transparent; border: medium none; direction: ltr; font-size: 13px; left: 0; margin: 0; outline: medium none; padding: 0.2em 0 0.2em 0.2em; top: 0; width: 84%; position: relative;" id="value_field_value" onkeypress="return onKeypress(event);" onkeyup="javascript:checkButton();">' +
//    '<input type="textbox" style="font-family: sans-serif; display: inline; background-color: transparent; border: medium none; direction: ltr; font-size: 13px; left: 0; margin: 0; outline: medium none; padding: 0.2em 0 0.2em 0.2em; top: 0; width: 84%; position: relative;" id="prop_field_value" /* onkeypress="return onKeypress(event);" onkeyup="javascript:checkButton() */;">' +
      '<button style="margin: 0; padding: 0;"  id="do_btn_prop" onclick="javascript:submit(my_prop,value_field_value);" disabled>Autolist</button>' +
      '<button style="margin: 0; padding: 0;" onclick="javascript:collapse(my_prop,value_field_value);" id="collapsebutton">↕' + /* ☼ 🐵 ☀ */ '</button>' +
      '</div>'
    );

    var my_prop = 1036;
    var value_field_value = 700;
/*
    alert('sandbox.js');
*/
    // new_element("span", {id: 'ietest'}, prop_div).appendChild(document.createComment("innerHTML can not be blank")); //needed for ie browser detection
//  add_prop(my_prop);
    
    $('#do_btn_prop').onclick = function(my_prop,value_field_value) {
      var search_value = document.getElementById('value_field_value').value;
      var lang = 'en';
      document.location.href = 'http://tools.wmflabs.org/wikidata-todo/autolist.html?lang=' + lang + '&q=string%5B' + my_prop + '%3A%22' + search_value + '%22%5D';
      document.location.target = '_blank';
    }
  }

  $( document ).ready( init );
} ( mediaWiki, jQuery ) );
//</nowiki>