Wikia


//
////////////////////////////////////////////////////////////////////////////////////////////////////
// Module: Instructive Form
// This is a WYSIWYG form editor with integrated help, validation and guidelines.
//
// Documentation
// http://documentalists-sandbox.wikia.com/wiki/Instructive_Form
//
// Dependencies
// These files shall be included before this file is included:
// - Utilities
// - Localization
// - HTML
////////////////////////////////////////////////////////////////////////////////////////////////////

/***************************************************************************************************
User-defined object: Rule
***************************************************************************************************
function Rule(Id) {
  mId = Id;  
}

/***************************************************************************************************
User-defined object: Rules
***************************************************************************************************
function Rules() {
  mIndex = 0;
  mRules = new Array();
  /*------------------------------------------------------------------------------------------------
  Publications:                                                                                   *
  this.first = first;
  this.insert = insert;
  this.next = next;
  /*----------------------------------------------------------------------------------------------*
  function first() {
    mIndex = 0;
    if (mIndex < mRules.size()) return mRules.at(i);
    return null;
  }
  /*----------------------------------------------------------------------------------------------*
  function insert(rule) {
    var iRule = first();
    while (iRule) {
      if (rule.mId === iRule.mId); break;
      iRule = next();
    }
    if (iRule) log.error('Attempt to store duplicate rule.');
    mRules.push_back(rule);
  }
  /*----------------------------------------------------------------------------------------------*
  function next() {
    ++mIndex;
    if (mIndex < mRules.size()) return mRules.at(i);
    return null;
  }
}

/***************************************************************************************************
User-defined object: DescriptionRule
***************************************************************************************************
function DescriptionRule() {
  mRule = new Rule('description');
}

/***************************************************************************************************
User-defined object: NumberOfServingsRul
***************************************************************************************************
function NumberOfServingsRule() {
  mRule = new Rule('number of servings');
}

/***************************************************************************************************
User-defined object: DurationRule()
***************************************************************************************************
function DurationRule() {
  mRule = new Rule('duration');
}

/***************************************************************************************************
User-defined object: IngredientRule()
***************************************************************************************************
function IngredientRule() {
  mRule = new Rule('ingredient');
}

/***************************************************************************************************
User-defined object: StepRule()
***************************************************************************************************
function StepRule() {
  mRule = new Rule('step');
}

/***************************************************************************************************
User-defined object: InstructiveForm
***************************************************************************************************/
function InstructiveForm() {
  track.enter('InstructiveForm()');
  this.mIgnoreNextActivation = false;
  var mIdOfLastElementThatHadFocus;
  var mLastUsedId = 0;
  /*------------------------------------------------------------------------------------------------
  Publications:                                                                                   */
  this.activate = activate;
  this.exit = exit;
  this.handleOnClick = handleOnClick;
  this.handleOnFocus = handleOnFocus;
  this.handleOnKeyPress = handleOnKeyPress;
  /*------------------------------------------------------------------------------------------------
  This function transforms this InstructiveForm to HMTL that suits the current view.              */
//  function transform() {
//    track.enter('InstructiveForm.transform()');
//    /*1. Determine view.*/
//    var View = (document.URL.indexOf('?action=edit')? 'edit': 'read';
//    /*2. Insert missing rules.*/
//    //for each rule in template-code: insert when missing.
//    /*3. Remove superfluous rules.*/
//    //getElementsByClassName('if_rule');
//    //for each rule: remove if a rule with this id is not present in template-code.
//    /*4. Apply rules for this view.*/
//    
//    track.leave('InstructiveForm.transform()');
//  }
  /*------------------------------------------------------------------------------------------------*/
  function activate() {
    track.enter('InstructiveForm.activate()');
    mIdOfLastElementThatHadFocus = null;
    if (this.mIgnoreNextActivation) {
      track.log('Ignoring this activation.');
      this.mIgnoreNextActivation = false;
    } else {
      if (document.URL.indexOf('?action=edit') !== -1) {
        track.log('Edit view.');
        var editform = document.getElementById('WikiaMainContent');                        //rename
        var wpTextbox1 = document.getElementById('wpTextbox1');
        if (editform && wpTextbox1) {
          track.log('editform && wpTextbox1 found.');
          var root = document.createElement('div');
          root.setAttribute('id', 'if-root');
          root.setAttribute('class', 'WikiaArticle');
          root.style.display= 'none';
          root.style.backgroundColor = '#e6e6e6';
          /*Determine title.*/
          track.log('determine title.');
          var url = document.URL;
          var begin = url.length - 1;
          while (url[begin - 1] !== '/') {
            --begin;
            track.log ("begin: " + begin);
          }
          var end = begin;
          while (url[end] != '?') ++end;
          var title = '';
          for (var i = begin; i != end; ++i) {
            if (url[i] === '_') {
              title += ' ';
            } else if (url.substr(i, 3) === '%22') {
              title += '"';
              i += 2;
            } else {
              title += url[i];
            }
          }
          /*Determine HTML.*/
          var HTML = '<h1>' + title + '</h1>';
          if (wpTextbox1.value.substr(0, 9) === '__NOTOC__') {
            HTML += wpTextbox1.value.substr(9);
          } else {
            HTML += wpTextbox1.value;
          }
          root.innerHTML = HTML;
          editform.parentNode.insertBefore(root, editform);
          var editables = document.getElementsByClassName('if-editable');
          if (editables.length === 0) {
            track.log('This page is no if-form.');
          } else {
            root.style.display = 'block';
            editform.style.display = 'none';
            insertToolbar();
            initializeLists();
            initializeEditables();
            var lists = document.getElementsByClassName('if-list');
            for (var i = 0; i < lists.length; ++i) {
              setDisabledOfButtons(lists[i]);
            }
            initializeInstructions();
            hideEAHides();
            showEAShows();
          }
        } else {
          track.log('Textbox1 not found.');
        }
      }
    }
  }
  /*----------------------------------------------------------------------------------------------*/
  function exit(saveForm, saveSource) {
    track.enter('InstructiveForm.exit()');
    assert('exit01', true, saveForm === true || saveForm === false);
    assert('exit02', true, saveSource === true || saveSource === false);
    var root = document.getElementById('if-root');
    var editform = document.getElementById('WikiaMainContent');                        //rename
    var wpTextbox1 = document.getElementById('wpTextbox1');
    //Save form data to the wiki editor's text box.
    if (saveForm) {
      //Change the form to a wiki source page.
      hideEAShows();
      showEAHides();
      finalizeInstructions();
      finalizeEditables();
      finalizeLists();
      removeToolbar();
      //Save form data to the wiki editor's text box.
      wpTextbox1.innerHTML = '__NOTOC__' + root.innerHTML.substr(root.innerHTML.indexOf('</h1>') + 5);
      root.style.display= 'none';
      editform.style.display = "block";
    }
    //Save wiki data to the server.
    if (saveSource) {
      //Create a dummy button inside editform.
      var button = document.getElementById('wpSave'); //createElement('button');
      //button.setAttribute('onclick', 'console.log(\'byebye\')');
      //button.innerHTML = 'Exit';
      //root.style.display= 'block';
      //root.appendChild(button);
      //Click it to save and exit the wiki editor.
      var event = new MouseEvent('click', {'view': window, 'bubbles': true, 'cancelable': true});
      var canceled = !button.dispatchEvent(event);
      this.mIgnoreNextActivation = true;
    }
    track.leave('InstructiveForm.exit()');
  }
  /*----------------------------------------------------------------------------------------------*/
  function finalizeEditable(editable) {
    track.enter('InstructiveForm.finalizeEditable()');
    assert('finalizeEditable01', 'P', editable.tagName);
    var input = editable.previousSibling;
    assert('finalizeEditable02', 'INPUT', input.tagName);
    editable.innerHTML = input.value;
    input.parentNode.removeChild(input);
    if (editable.parentNode.parentNode.tagName === 'OL') {
      var downButton = editable.nextSibling;
      assert('finalizeEditable03', 'down', downButton.getAttribute('caption'));
      downButton.parentNode.removeChild(downButton);
      var upButton = editable.nextSibling;
      assert('finalizeEditable04', 'up', upButton.getAttribute('caption'));
      upButton.parentNode.removeChild(upButton);
    }
    if (editable.parentNode.tagName === 'LI') {
      var deleteButton = editable.nextSibling;
      assert('finalizeEditable05', 'delete', deleteButton.getAttribute('caption'));
      deleteButton.parentNode.removeChild(deleteButton);
    }
    editable.removeAttribute('id');
    editable.style.display = 'inline';
  }
  /*----------------------------------------------------------------------------------------------*/
  function finalizeEditables() {
    track.enter('InstructiveForm.finalizeEditables()');
    var editables = document.getElementsByClassName("if-editable");
    for (var i = 0; i < editables.length; ++i) {
      finalizeEditable(editables[i]);
    }
  }
  /*----------------------------------------------------------------------------------------------*/
  function hideEAShows() {
    track.enter('InstructiveForm.hideEAshows()');
    var shows = document.getElementsByClassName("if-show");
    for (var i = 0; i < shows.length; ++i) {
      shows[i].style.display = 'none';
    }
  }
  /*----------------------------------------------------------------------------------------------*/
  function finalizeInstructions() {
    track.enter('InstructiveForm.finalizeInstructions()');
    var instructions = document.getElementsByClassName("if-instruction");
    for (var i = 0; i < instructions.length; ++i) {
      instructions[i].removeAttribute('style');
      instructions[i].style.display = 'none';
    }
  }
  /*----------------------------------------------------------------------------------------------*/
  function finalizeLists() {
    track.enter('InstructiveForm.finalizeLists()');
    var lists = document.getElementsByClassName("if-list");
    for (var iList = 0; iList < lists.length; ++iList) {
      var buttons = lists[iList].getElementsByClassName('if-button');
      for (var i = 0; i < buttons.length; ++i) {
        if (buttons[i].getAttribute('caption') === 'new') {
          buttons[i].parentNode.removeChild(buttons[i]);
        }
      }
    }
  }
  /*----------------------------------------------------------------------------------------------*/
  function handleOnClick(id) {
    track.enter('InstructiveForm.handleOnClick(id: "' + id + '")');
    var button = document.getElementById(id);
    var caption = button.getAttribute('caption');
    assert('handleOnClick01', true, caption != null);
    if (caption === 'cancel') {
      track.log('cancel');
      exit(false, true);
    } else if (caption === 'delete') {
      track.log('delete');
      if (button.parentNode.parentNode.childNodes.length === 2) {
        showOrHideButtonsAndInstructionForEditable(id, false);
        button.parentNode.parentNode.lastChild.style.display = 'inline-block';
      } else {
        if (button.parentNode.nextSibling.getElementsByTagName('INPUT').length === 0) {
          button.parentNode.previousSibling.getElementsByTagName('INPUT')[0].focus();
        } else {
          button.parentNode.nextSibling.getElementsByTagName('INPUT')[0].focus();
        }
      }
      button.parentNode.parentNode.removeChild(button.parentNode);
    } else if (caption === 'down') {
      track.log('down');
      if (!button.disabled) {
        var list = button.parentNode.parentNode;
        var newNode = button.parentNode.cloneNode(true);
        list.insertBefore(newNode, button.parentNode.nextSibling.nextSibling);
        list.removeChild(button.parentNode);
        setDisabledOfButtons(list);
        newNode.getElementsByTagName('INPUT')[0].focus();
      }
    } else if (caption === 'new') {
      track.log('new');
      insertRow(button);
    } else if (caption === 'save') {
      track.log('save');
      exit(true, true);
    } else if (caption.substr(0, 6) === 'symbol' && mIdOfLastElementThatHadFocus !== null) {
      track.log('mIdOfLastElementThatHadFocus: ' + mIdOfLastElementThatHadFocus);
      var editBox = document.getElementById(mIdOfLastElementThatHadFocus).previousSibling;
      var cursorPosition;
      if (editBox.selectionStart) { 
        cursorPosition = editBox.selectionStart; 
      } else if (document.selection) { 
        editBox.focus(); 
        var r = document.selection.createRange(); 
        if (r == null) { 
          cursorPosition = 0; 
        } else {
          var re = el.createTextRange(), 
          rc = re.duplicate(); 
          re.moveToBookmark(r.getBookmark()); 
          rc.setEndPoint('EndToStart', re); 
          cursorPosition = rc.text.length; 
        }  
        cursorPosition = 0; 
      }
      editBox.value = (cursorPosition? editBox.value.substr(0, cursorPosition): "") + button.innerHTML + editBox.value.substr(cursorPosition);
    } else if (caption === 'up') {
      track.log('up');
      if (!button.disabled) {
        var list = button.parentNode.parentNode;
        var newNode = button.parentNode.cloneNode(true);
        list.insertBefore(newNode, button.parentNode.previousSibling);
        list.removeChild(button.parentNode);
        setDisabledOfButtons(list);
        newNode.getElementsByTagName('INPUT')[0].focus();
      }
    } else if (caption === 'view source') {
      track.log('view source');
      exit(true, false);
    }
    track.leave('InstructiveForm.handleOnClick()');
  }
  /*----------------------------------------------------------------------------------------------*/
  function handleOnFocus(id) {
    track.enter('InstructiveForm.handleOnFocus(id: "' + id + '")');
    if (mIdOfLastElementThatHadFocus != null) {
      showOrHideButtonsAndInstructionForEditable(mIdOfLastElementThatHadFocus, false);
      mIdOfLastElementThatHadFocus = null;
    }
    showOrHideButtonsAndInstructionForEditable(id, true);
    var editable = document.getElementById(editableId);
    setDisabledOfButtons(editabble.parentNode.parentNode);
    mIdOfLastElementThatHadFocus = id;
    track.leave('InstructiveForm.handleOnFocus()');
  }
  /*----------------------------------------------------------------------------------------------*/
  function handleOnKeyPress(event, editableId) {
    track.enter('InstructiveForm.handleOnKeyPress(event: "' + event + '", editableId: "' +
      editableId + '")');
    if (event.key === 'Enter') {
      var editable = document.getElementById(editableId);
      insertRow(editable.parentNode.parentNode.lastChild);
    }
    if (event.key === 'Down') {
      var editable = document.getElementById(editableId);
      if (editable.parentNode.nextSibling !== null) {
        editable.parentNode.nextSibling.getElementsByTagName('INPUT')[0].focus();
      }
    }
    if (event.key === 'Up') {
      var editable = document.getElementById(editableId);
      if (editable.parentNode.previousSibling !== null) {
        editable.parentNode.previousSibling.getElementsByTagName('INPUT')[0].focus();
      }
    }
  }
  /*----------------------------------------------------------------------------------------------*/
  function hideEAHides() {
    track.enter('InstructiveForm.hideEAHides()');
    var hides = document.getElementsByClassName("if-hide");
    for (var i = 0; i < hides.length; ++i) {
      hides[i].style.display = 'none';
    }
  }
  /*------------------------------------------------------------------------------------------------
  This function initializes the specified button.                                                 */
  function initializeButton(button, caption) {
    track.enter('InstructiveForm.initializeButton(button: "' + button + '", caption: "' + caption +
      '")');
    var id = ++mLastUsedId;
    button.setAttribute('id', id);
    button.setAttribute('class', 'if-button');
    button.setAttribute('caption', caption);
    button.setAttribute('onclick', 'editingAssistant.handleOnClick(' + id + ')');
    button.style.display = 'inline-block';
    button.style.paddingTop = '0';
    button.style.paddingRight = '5px';
    button.style.paddingBottom = '0';
    button.style.paddingLeft = '5px';
    button.style.borderRadius = '5px';
    button.style.marginTop = '2px';
    button.style.marginRight = '5px';
    button.style.marginBottom = '2px';
    button.style.marginLeft = '5px';
    button.style.color = 'white';
    button.style.cursor = 'pointer';
    button.style.fontFamily = 'Helvetica,Arial,sans-serif';
    button.style.fontSize = '14px';
    button.style.lineHeight = '22px';
    button.style.backgroundColor = '#008BE3';
    button.style.backgroundImage = '-moz-linear-gradient(center top , #008BE3 35%, #006CB0 65%)';
    button.style.textAlign = 'center';
    if (caption === 'cancel') button.innerHTML = localization.translate('Exit without saving');
    if (caption === 'delete') button.innerHTML = localization.translate('Delete');
    if (caption === 'down') button.innerHTML = localization.translate('Move down');
    if (caption === 'new') button.innerHTML = localization.translate('Insert row');
    if (caption === 'save') button.innerHTML = localization.translate('Save and exit');
    if (caption === 'up') button.innerHTML = localization.translate('Move up');
    if (caption === 'view source') button.innerHTML = localization.translate('View source');
    if (caption === 'symbol01') button.innerHTML = localization.translate('à');
    if (caption === 'symbol02') button.innerHTML = localization.translate('á');
    if (caption === 'symbol03') button.innerHTML = localization.translate('â');
    if (caption === 'symbol04') button.innerHTML = localization.translate('ä');
    if (caption === 'symbol05') button.innerHTML = localization.translate('è');
    if (caption === 'symbol06') button.innerHTML = localization.translate('é');
    if (caption === 'symbol07') button.innerHTML = localization.translate('ê');
    if (caption === 'symbol08') button.innerHTML = localization.translate('ë');
    if (caption === 'symbol09') button.innerHTML = localization.translate('ì');
    if (caption === 'symbol10') button.innerHTML = localization.translate('í');
    if (caption === 'symbol11') button.innerHTML = localization.translate('î');
    if (caption === 'symbol12') button.innerHTML = localization.translate('ï');
    if (caption === 'symbol13') button.innerHTML = localization.translate('℃');
    if (caption === 'symbol14') button.innerHTML = localization.translate('●');
    track.leave('InstructiveForm.initializeButton()');
  }
  /*----------------------------------------------------------------------------------------------*/
  function initializeEditable(editable) {
    track.enter('InstructiveForm.initializeEditable()');
    assert('initializeEditable01', 'P', editable.tagName);
    var id = ++mLastUsedId;
    track.log('id: ' + id);
    editable.setAttribute('id', id);
    var input;
    if (editable.previousSibling && editable.previousSibling.tagName == 'INPUT') {
      input = editable.previousSibling;
    } else {
      input = document.createElement('input');
    }
    input.setAttribute('value', editable.innerHTML);
    input.setAttribute('onfocus', 'editingAssistant.handleOnFocus(' + id + ')');
    input.setAttribute('onkeypress', 'editingAssistant.handleOnKeyPress(event, ' + id + ')');
    input.style.height = '22px';
    input.style.width = editable.style.width;
    input.style.margin = editable.style.margin;
    input.style.fontFamily = 'Helvetica,Arial,sans-serif';
    input.style.fontSize = '14px';
    input.style.lineHeight = '22px';
    editable.parentNode.insertBefore(input, editable);
    if (editable.parentNode.tagName === 'LI') {
      track.log('parent = LI-element');
      var deleteButton = document.createElement('div');
      initializeButton(deleteButton, 'delete');
      deleteButton.style.display = 'none';
      editable.parentNode.insertBefore(deleteButton, editable.nextSibling);
      if (editable.parentNode.parentNode.tagName === 'OL' )
      {
        var upButton = document.createElement('div');
        editable.parentNode.insertBefore(upButton, editable.nextSibling);
        initializeButton(upButton, 'up');
        upButton.style.display = 'none';
        var downButton = document.createElement('div');
        editable.parentNode.insertBefore(downButton, editable.nextSibling);
        initializeButton(downButton, 'down');
        downButton.style.display = 'none';
      }
    }
    editable.style.display = 'none';
    track.leave('InstructiveForm.initializeEditable()');
  }
  /*----------------------------------------------------------------------------------------------*/
  function initializeEditables() {
    track.enter('InstructiveForm.initializeEditables()');
    var editables = document.getElementsByClassName("if-editable");
    for (var i = 0; i < editables.length; ++i) {
      initializeEditable(editables[i]);
    }
  }
  /*----------------------------------------------------------------------------------------------*/
  function initializeInstructions() {
    track.enter('InstructiveForm.initializeInstructions()');
    var instructions = document.getElementsByClassName("if-instruction");
    for (var i = 0; i < instructions.length; ++i) {
      instructions[i].style.display = 'none';
      instructions[i].style.width = 'auto';
      instructions[i].style.paddingTop = '0';
      instructions[i].style.paddingRight = '5px';
      instructions[i].style.paddingBottom = '0';
      instructions[i].style.paddingLeft = '5px';
      instructions[i].style.borderWidth = '1px';
      instructions[i].style.borderStyle = 'solid';
      instructions[i].style.borderColor = 'grey';
      instructions[i].style.borderRadius = '5px';
      instructions[i].style.marginTop = '0';
      instructions[i].style.marginRight = '5px';
      instructions[i].style.marginBottom = '0';
      instructions[i].style.marginLeft = '5px';
      instructions[i].style.backgroundColor = 'khaki';
      instructions[i].style.fontFamily = 'Helvetica,Arial,sans-serif';
      instructions[i].style.fontSize = '14px';
      instructions[i].style.lineHeight = '22px';
    }
  }
  /*----------------------------------------------------------------------------------------------*/
  function initializeLists() {
    track.enter('InstructiveForm.initializeLists()');
    var lists = document.getElementsByClassName("if-list");
    for (var i = 0; i < lists.length; ++i) {
      var button = document.createElement('div');
      initializeButton(button, 'new');
      lists[i].appendChild(button);
    }
  }
  /*----------------------------------------------------------------------------------------------*/
  function insertRow(insertButton) {
    track.enter('InstructiveForm.insertRow()');
    var newParagraph = document.createElement('P');
    newParagraph.setAttribute('class', 'if-editable');
    newParagraph.style.width = '500px';
    var newItem = document.createElement('LI');
    newItem.style.width = 'auto';
    newItem.appendChild(newParagraph);
    var list = insertButton.parentNode;
    list.insertBefore(newItem, insertButton);
    initializeEditable(newParagraph);
    newItem.getElementsByTagName('INPUT')[0].focus();
    setDisabledOfButtons(list);
    track.leave('InstructiveForm.insertRow()');
  }
  /*----------------------------------------------------------------------------------------------*/
  function insertToolbar() {
    track.enter('InstructiveForm.insertToolbar()');

    /*Special symbols-----------------------------------------------------------------------------*/
    var label = document.createElement('div');
    label.style.display = 'inline-block';
    label.innerHTML = localization.translate('Insert symbol');
    label.style.cssFloat = 'left';
    var symbol01Button = document.createElement('div');
    initializeButton(symbol01Button, 'symbol01');
    symbol01Button.style.cssFloat = 'left';
    var symbol02Button = document.createElement('div');
    initializeButton(symbol02Button, 'symbol02');
    symbol02Button.style.cssFloat = 'left';
    var symbol03Button = document.createElement('div');
    initializeButton(symbol03Button, 'symbol03');
    symbol03Button.style.cssFloat = 'left';
    var symbol04Button = document.createElement('div');
    initializeButton(symbol04Button, 'symbol04');
    symbol04Button.style.cssFloat = 'left';
    var symbol05Button = document.createElement('div');
    initializeButton(symbol05Button, 'symbol05');
    symbol05Button.style.cssFloat = 'left';
    var symbol06Button = document.createElement('div');
    initializeButton(symbol06Button, 'symbol06');
    symbol06Button.style.cssFloat = 'left';
    var symbol07Button = document.createElement('div');
    initializeButton(symbol07Button, 'symbol07');
    symbol07Button.style.cssFloat = 'left';
    var symbol08Button = document.createElement('div');
    initializeButton(symbol08Button, 'symbol08');
    symbol08Button.style.cssFloat = 'left';
    var symbol09Button = document.createElement('div');
    initializeButton(symbol09Button, 'symbol09');
    symbol09Button.style.cssFloat = 'left';
    var symbol10Button = document.createElement('div');
    initializeButton(symbol10Button, 'symbol10');
    symbol10Button.style.cssFloat = 'left';
    var symbol11Button = document.createElement('div');
    initializeButton(symbol11Button, 'symbol11');
    symbol11Button.style.cssFloat = 'left';
    var symbol12Button = document.createElement('div');
    initializeButton(symbol12Button, 'symbol12');
    symbol12Button.style.cssFloat = 'left';
    var symbol13Button = document.createElement('div');
    initializeButton(symbol13Button, 'symbol13');
    symbol13Button.style.cssFloat = 'left';
    var symbol14Button = document.createElement('div');
    initializeButton(symbol14Button, 'symbol14');
    symbol14Button.style.cssFloat = 'left';
    
    var specialSymbols = document.createElement('div');
    specialSymbols.style.display = 'inline-block';
    specialSymbols.style.marginLeft = '0px';
    specialSymbols.appendChild(label);
    specialSymbols.appendChild(symbol01Button);
    specialSymbols.appendChild(symbol02Button);
    specialSymbols.appendChild(symbol03Button);
    specialSymbols.appendChild(symbol04Button);
    specialSymbols.appendChild(symbol05Button);
    specialSymbols.appendChild(symbol06Button);
    specialSymbols.appendChild(symbol07Button);
    specialSymbols.appendChild(symbol08Button);
    specialSymbols.appendChild(symbol09Button);
    specialSymbols.appendChild(symbol10Button);
    specialSymbols.appendChild(symbol11Button);
    specialSymbols.appendChild(symbol12Button);
    specialSymbols.appendChild(symbol13Button);
    specialSymbols.appendChild(symbol14Button);

    var viewSourceButton = document.createElement('div');
    initializeButton(viewSourceButton, 'view source');
    viewSourceButton.style.cssFloat = 'right';

    var cancelButton = document.createElement('div');
    initializeButton(cancelButton, 'cancel');
    cancelButton.style.cssFloat = 'right';

    var saveButton = document.createElement('div');
    initializeButton(saveButton, 'save');
    saveButton.style.cssFloat = 'right';

    var toolbar = document.createElement('div');
    toolbar.setAttribute('id', 'if-toolbar');
    toolbar.style.display = 'block';
    toolbar.style.width = '100%';
    toolbar.style.paddingTop = '0';
    toolbar.style.paddingRight = '5px';
    toolbar.style.paddingBottom = '0';
    toolbar.style.paddingLeft = '5px';
    toolbar.style.borderWidth = '1px';
    toolbar.style.borderStyle = 'solid';
    toolbar.style.borderColor = 'gray';
    toolbar.style.marginTop = '0';
    toolbar.style.marginRight = '0';
    toolbar.style.marginBottom = '0';
    toolbar.style.marginLeft = '0';
    toolbar.style.fontStyle = 'inherit';
    toolbar.style.fontWeight = 'inherit';
    toolbar.appendChild(specialSymbols);
    toolbar.appendChild(viewSourceButton);
    toolbar.appendChild(cancelButton);
    toolbar.appendChild(saveButton);
    var root = document.getElementById('if-root');
    root.insertBefore(toolbar, root.firstChild);
  }
  /*----------------------------------------------------------------------------------------------*/
  function removeToolbar() {
    track.enter('InstructiveForm.removeToolbar()');
    var toolbar = document.getElementById("if-toolbar");
    toolbar.parentNode.removeChild(toolbar);
    track.leave('InstructiveForm.removeToolbar()');
  }
  /*------------------------------------------------------------------------------------------------
  This function enables all up and down buttons of the given list, except the up button of the first
  item and the down button of the last item.                                                      */
  function setDisabledOfButtons(list) {
    track.enter('InstructiveForm.setDisabledOfButtons(list : ' + list + ')');
    if (list.tagName === 'OL') {
      var items = list.getElementsByTagName('LI');
      for (var iItem = 0; iItem < items.length; ++iItem) {
        var buttons = items[iItem].getElementsByClassName('if-button');
        for (var i = 0; i < buttons.length; ++i) {
          var caption = buttons[i].getAttribute('caption');
          if ((iItem === 0 && caption === 'up') ||
            (iItem === items.length - 1 && caption === 'down')
          ) {
            buttons[i].disable = true;
            buttons[i].style.color = 'grey';
          } else {
            buttons[i].disable = false;
            buttons[i].style.color = 'white';
          }
        }
      }
    }
    track.leave('InstructiveForm.setDisabledOfButtons()');
  }
  /*----------------------------------------------------------------------------------------------*/
  function showEAHides() {
    track.enter('InstructiveForm.showEAHides()');
    var hides = document.getElementsByClassName("if-hide");
    for (var i = 0; i < hides.length; ++i) {
      hides[i].style.display = 'inline';
    }
  }
  /*----------------------------------------------------------------------------------------------*/
  function showEAShows() {
    track.enter('InstructiveForm.showEAshows()');
    var shows = document.getElementsByClassName("if-show");
    for (var i = 0; i < shows.length; ++i) {
      shows[i].style.display = 'inline';
    }
  }
  /*------------------------------------------------------------------------------------------------
  This function shows (when show is true) or hides (when show is false) all buttons and
  instructions that are direct children of a parent of the editable with the specified id.        */
  function showOrHideButtonsAndInstructionForEditable(id, show) {
    track.enter('InstructiveForm.showOrHideButtonsAndInstructionForEditable(id: ' + id +
      ', show: ' + show + ').');
    assert('showOrHideButtonsAndInstructionForEditable01', true, show === true || show === false);
    var editable = document.getElementById(id);
    var parentOfEditable = editable.parentNode;
    for (;;) {
      var directChildren = parentOfEditable.childNodes;
      for (var i = 0; i < directChildren.length; ++i) {
        //track.log('nodeType:' + directChildren[i].nodeType);
        if (directChildren[i].nodeType != 1) continue;
        if ((directChildren[i].getAttribute('class') == 'if-button') ||
          (directChildren[i].getAttribute('class') == 'if-instruction')
        ) {
          if (show === true) {
            directChildren[i].style.display = 'inline-block';
          } else {
            directChildren[i].style.display = 'none';
          }
        }
      }
      if (parentOfEditable.getAttribute('class') == 'WikiaArticle') break;
      parentOfEditable = parentOfEditable.parentNode;
    }
  }
} //InstructiveForm
var editingAssistant = new InstructiveForm();
includer.moduleIncluded(1);
//

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Around Wikia's network

Random Wiki