Difference between revisions of "User:King of Herdaz/Toolbar customization"

From The Coppermind
Jump to navigation Jump to search
(→‎Buttons: gave a summary/description for each button and made the code collapsible for each one.)
Line 139: Line 139:
 
|}
 
|}
   
  +
==== Signature ====
<pre> // Adding signature button to the "main" section
 
  +
Pastes <code><nowiki>~~~~</nowiki></code> into the page to generate your signature with a timestamp. This useful for commenting on talk pages.
  +
  +
{| class="mw-collapsible mw-collapsed" width=100%
  +
|-
  +
|
  +
|-
  +
|
  +
<pre>
 
// Adding signature button to the "main" section
 
$('#wpTextbox1').wikiEditor('addToToolbar', {
 
$('#wpTextbox1').wikiEditor('addToToolbar', {
 
section: 'main',
 
section: 'main',
Line 157: Line 166:
 
}
 
}
 
});
 
});
  +
</pre>
  +
|}
  +
  +
==== Break Tag ====
  +
Inserts <code><nowiki><br /></nowiki></code> into the page. This is the preferred syntax on the Coppermind for creating line breaks.
   
  +
{| class="mw-collapsible mw-collapsed" width=100%
  +
|-
  +
|
  +
|-
  +
|
  +
<pre>
 
// Adding <br/> button to the "main" section
 
// Adding <br/> button to the "main" section
 
$('#wpTextbox1').wikiEditor('addToToolbar', {
 
$('#wpTextbox1').wikiEditor('addToToolbar', {
Line 176: Line 196:
 
}
 
}
 
});
 
});
  +
</pre>
  +
|}
  +
  +
==== Simple Link ====
  +
Simply encases the highlighted text within <code><nowiki>[[</nowiki></code> and <code><nowiki>]]</nowiki></code> to generate a link.
   
  +
{| class="mw-collapsible mw-collapsed" width=100%
  +
|-
  +
|
  +
|-
  +
|
  +
<pre>
 
// Adding link button to the "main" section
 
// Adding link button to the "main" section
 
$('#wpTextbox1' ).wikiEditor( 'addToToolbar', {
 
$('#wpTextbox1' ).wikiEditor( 'addToToolbar', {
Line 196: Line 227:
 
}
 
}
 
});
 
});
  +
</pre>
  +
|}
  +
  +
==== Hidden Text ====
  +
Encases the highlighted text between <code><nowiki><!--</nowiki></code> and <code><nowiki>--></nowiki></code> to prevent it from appearing in the viewable page.
   
  +
{| class="mw-collapsible mw-collapsed" width=100%
  +
|-
  +
|
  +
|-
  +
|
  +
<pre>
 
// Adding hidden text button to the "main" section
 
// Adding hidden text button to the "main" section
 
$('#wpTextbox1' ).wikiEditor( 'addToToolbar', {
 
$('#wpTextbox1' ).wikiEditor( 'addToToolbar', {
Line 216: Line 258:
 
}
 
}
 
});
 
});
  +
</pre>
  +
|}
  +
  +
==== Columns ====
  +
Encases your text, which should a bulleted (<code><nowiki>*</nowiki></code>) or numbered (<code><nowiki>#</nowiki></code>) list, inside of the {{t|columns}} template to columnize the list.
   
  +
{| class="mw-collapsible mw-collapsed" width=100%
  +
|-
  +
|
  +
|-
  +
|
  +
<pre>
 
// Adding columns button to the "main" section
 
// Adding columns button to the "main" section
 
$('#wpTextbox1' ).wikiEditor( 'addToToolbar', {
 
$('#wpTextbox1' ).wikiEditor( 'addToToolbar', {
Line 236: Line 289:
 
}
 
}
 
});
 
});
  +
</pre>
  +
|}
  +
  +
==== <nowiki><code></nowiki> ====
  +
Encases your highlighted text between <code><nowiki><code></nowiki></code> and <code><nowiki></code></nowiki></code>.
   
  +
{| class="mw-collapsible mw-collapsed" width=100%
  +
|-
  +
|
  +
|-
  +
|
  +
<pre>
 
// Adding a <code> button to the "main" section
 
// Adding a <code> button to the "main" section
 
$('#wpTextbox1' ).wikiEditor( 'addToToolbar', {
 
$('#wpTextbox1' ).wikiEditor( 'addToToolbar', {
Line 257: Line 321:
 
});
 
});
 
</pre>
 
</pre>
  +
|}
   
 
== Removing default elements ==
 
== Removing default elements ==

Revision as of 18:15, 24 October 2021

The editing toolbar is a versatile and very useful tool that can be used to make working on the wiki much easier. While the basic version (which is an option in your preferences) has some use, the main benefit comes when you customize your toolbar. In this guide there is a list of premade buttons that you can use as is as well as a guide to creating and modifying your own buttons and dropdowns.

Basic

Before you can customize your toolbar you need to have the "Enable the editing toolbar" option in your preferences selected. Once you have done this you are ready to begin.

Add the following to your /common.js page:

//customize toolbar
var customizeToolbar = function() {
  /* Your code goes here */

Followed by this:

};
/* 
 * Check if view is in edit mode and that the required modules are available. Then, customize the toolbar...
 * Don't touch below this line!
 */
if (['edit', 'submit'].indexOf(mw.config.get('wgAction')) !== -1) {
  mw.loader.using('user.options').then(function() {
    // This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]])
    if (mw.user.options.get('usebetatoolbar') == 1) {
      $.when(
        mw.loader.using('ext.wikiEditor'), $.ready
      ).then(customizeToolbar);
    }
  });
}

You will place any modifications to the toolbar that you make between these two sections.

Buttons

Premade Buttons

Simply paste any of these premade buttons into your /common.js page between the two #Basic sections to add it to the left side of the main section of your toolbar (which is the top row that is always showing).

Image template

Clicking this button will paste the {{image}} template on to the page, encapsulating your cursor or whatever you have highlighted.

For example, if you have Shallan.jpg highlighted when you press the button it will result in this: {{image|Shallan.jpg|side=|width=|caption}}

  // Adding image template button to the "main" section
  $('#wpTextbox1').wikiEditor('addToToolbar', {
    section: 'main',
    group: 'insert',
    tools: {
      "category": {
        label: 'Image template',
        type: 'button',
        icon: '//upload.wikimedia.org/wikipedia/commons/d/d8/Vector_toolbar_insert_image_button.png',
        action: {
          type: 'encapsulate',
          options: {
            pre:  '{' + '{image|',
            post: '|side=|width=|caption}}'
          }
        }
      }
    }
  });

Category

This button will paste [[Category: and ]] around your highlighted text.

  // Adding category button to the "main" section
  $('#wpTextbox1').wikiEditor('addToToolbar', {
    section: 'main',
    group: 'insert',
    tools: {
      "category": {
        label: 'Category',
        type: 'button',
        icon: '//upload.wikimedia.org/wikipedia/commons/2/2d/Button_clipboard_category.png',
        action: {
          type: 'encapsulate',
          options: {
            pre:  "[[Category: ",
            post: "]]"
          }
        }
      }
    }
  });

Wikipedia Link

This button will paste [[Wikipedia: and |]] around your highlighted text. This generates a link to that Wikipedia page and hides the prefix. For example, if you highlight Brandon Sanderson and click this button it will generate this: [[Wikipedia: Brandon Sanderson|]] which produces Brandon Sanderson on the page.

  //  Adding Wikipedia link button to the "main" section
  $('#wpTextbox1').wikiEditor('addToToolbar', {
    section: 'main',
    group: 'insert',
    tools: {
      "category": {
        label: 'Wikipedia',
        type: 'button',
        icon: '//upload.wikimedia.org/wikipedia/commons/c/cb/Button_wikipedia.png',
        action: {
          type: 'encapsulate',
          options: {
            pre:  "[[Wikipedia: ",
            post: "|]]"
          }
        }
      }
    }
  });

Signature

Pastes ~~~~ into the page to generate your signature with a timestamp. This useful for commenting on talk pages.

  // Adding signature button to the "main" section
  $('#wpTextbox1').wikiEditor('addToToolbar', {
    section: 'main',
    group: 'format',
    tools: {
      "category": {
        label: 'Signature',
        type: 'button',
        icon: '//upload.wikimedia.org/wikipedia/commons/6/6d/Button_sig.png',
        action: {
          type: 'encapsulate',
          options: {
            pre:  '~~' + '~~'
          }
        }
      }
    }
  });

Break Tag

Inserts <br /> into the page. This is the preferred syntax on the Coppermind for creating line breaks.

  // Adding <br/> button to the "main" section
  $('#wpTextbox1').wikiEditor('addToToolbar', {
    section: 'main',
    group: 'insert',
    tools: {
      "category": {
        label: 'Break tag',
        type: 'button',
        icon: '//upload.wikimedia.org/wikipedia/commons/1/13/Button_enter.png',
        action: {
          type: 'encapsulate',
          options: {
            pre:  '<' + 'br />',
          }
        }
      }
    }
  });

Simple Link

Simply encases the highlighted text within [[ and ]] to generate a link.

  // Adding link button to the "main" section
  $('#wpTextbox1' ).wikiEditor( 'addToToolbar', {
    section: 'main',
    group: 'format',
    tools: {
     "comment": {
	label: 'Link',
	type: 'button',
	icon: '//upload.wikimedia.org/wikipedia/commons/9/97/Button_int_link.png',
	action: {
	  type: 'encapsulate',
	  options: {
	    pre: "[[",
	    post: "]]"
	  }
	}
      }
    }
  });

Hidden Text

Encases the highlighted text between <!-- and --> to prevent it from appearing in the viewable page.

  // Adding hidden text button to the "main" section
  $('#wpTextbox1' ).wikiEditor( 'addToToolbar', {
    section: 'main',
    group: 'format',
    tools: {
     "comment": {
	label: 'Hidden text',
	type: 'button',
	icon: '//upload.wikimedia.org/wikipedia/commons/1/1b/Button_hide_wiki_tag.png',
	action: {
	  type: 'encapsulate',
	  options: {
	    pre: "<!--",
	    post: "-->"
	  }
	}
      }
    }
  });

Columns

Encases your text, which should a bulleted (*) or numbered (#) list, inside of the {{columns}} template to columnize the list.

  // Adding columns button to the "main" section
  $('#wpTextbox1' ).wikiEditor( 'addToToolbar', {
    section: 'main',
    group: 'format',
    tools: {
     "comment": {
	label: 'Columns',
	type: 'button',
	icon: '//upload.wikimedia.org/wikipedia/commons/2/25/Vector_toolbar_bulleted_list_button.png',
	action: {
	  type: 'encapsulate',
	  options: {
	    pre: '{' + '{columns|' + '\n',
	    post: '\n' + '}}'
	  }
	}
      }
    }
  });

<code>

Encases your highlighted text between <code> and </code>.

  // Adding a <code> button to the "main" section
  $('#wpTextbox1' ).wikiEditor( 'addToToolbar', {
    section: 'main',
    group: 'format',
    tools: {
     "comment": {
	label: 'Code',
	type: 'button',
	icon: '//upload.wikimedia.org/wikipedia/commons/2/23/Button_code.png',
	action: {
	  type: 'encapsulate',
	  options: {
	    pre: '<' + 'code>',
	    post: '</' + 'code>'
	  }
	}
      }
    }
  });

Removing default elements

This can be a little tricky since in order to remove an element you need to know what it is named. To find the name you will have to comb through the page source or look through the code for the default version.

Fortunately, the names of many of the elements are known. Here are premade sections (I think there's a better word for this) of code for many of the elements in the default toolbar. Paste any one of them into your Common.js page within the two #Basic sections to remove that element.

<ref> Button

  //Remove the default <ref> button
   $( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', {
 	  'section': 'main',
 	  'group': 'insert',
 	  'tool': 'reference'
   });

Bulleted List Button

 //remove the bulleted list button
  $( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', {
        'section': 'advanced',
        'group': 'format',
        'tool': 'ulist'
  });

Numbered List Button

  //remove the numbered list button
  $( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', {
        'section': 'advanced',
        'group': 'format',
        'tool': 'olist'
  });

Default Break Tag Button (<br>)

  //remove the default <br> button (to replace it with a <br/> button which is preferred on the Coppermind)
  $( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', {
        'section': 'advanced',
        'group': 'format',
        'tool': 'newline'
  });

Table Button

  //remove table button
  $( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', {
        'section': 'advanced',
        'group': 'insert',
        'tool': 'table'
  });

[[File:]] Button

  //remove File button
  $( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', {
        'section': 'main',
        'group': 'insert',
        'tool': 'file'
  });

Link Button

  //remove original link button
  $( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', {
        'section': 'main',
        'group': 'insert',
        'tool': 'link'
  });

Others

For elements not on this list take this code and replace XXXX with the name of the section the element is in, replace YYYY with the name of the group the element is part of, and replace ZZZZ with the name of the element. You you can find these names by looking through the code for the default version.

  $( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', {
        'section': 'XXXX',
        'group': 'YYYY',
        'tool': 'ZZZZ'
  });