Fandom

Wikia Developers Wiki

Code

889pages on
this wiki
Add New Page
Talk40 Share
Ambox octogon stop Do not use this script.

This script does not work in its current state. Installing this script will cause errors and may cause other scripts to malfunction. If you have it installed, it is recommended that you remove it.

If you are the author of this script, or are interested in restarting development, you may remove this message when the errors have been fixed.


Code is a script for editing JavaScript and CSS codes.

Installation

Add this JavaScript on your wiki:

Global Personal
w:Special:Mypage/global.js Special:Mypage/common.js
importArticles({
    type: 'script',
    articles: [
        'u:dev:Code/code.js'
    ]
});
importArticles — Best Practices for installing JavaScript on Fandom
The importArticles statement is designed to combine multiple HTTP requests into a single data transfer, allowing multiple scripts to load and execute faster. If you've been installing several different scripts, your JavaScript file has probably accumulated unnecessary import statements. Click "Expand" to learn how to efficiently batch import scripts to speed up performance and make your code look cleaner. One other approach is by using the MediaWiki:ImportJS.
If your JavaScript file has several lines of code that say importScript, importScriptPage, or importArticles, you may be able to combine them! By batch importing a collection of scripts with a single import, your JavaScript code will load faster and look cleaner. Consider the example below. On the left is an example of what your JavaScript file might currently look like. On the right is how you could improve that code.
Multiple imports — messy and slow One import — clean and efficient
importScriptPage('AjaxRC/code.js','dev');
 
importScript('MediaWiki:localScript.js');
 
importArticle({
  type: 'script',
  article: 'u:dev:FloatingToc/code.js'
});
 
importScriptPage('page1.js', 'wikiname');
 
importScriptPage('page2.js', 'wikiname');
importArticles({
    type: 'script',
    articles: [
        'u:dev:AjaxRC/code.js',
        'MediaWiki:localScript.js',
        'u:dev:FloatingToc/code.js',
        'u:wikiname:page1.js',
        'u:wikiname:page2.js'
    ]
});
Note: In this example, pay close attention to the placement of commas and other punctuation. For people who aren't familiar with programming (and even those who are!), a common mistake when writing code is to accidentally delete, forget, or misplace critical symbols like commas or quotation marks. This can cause a syntax error that breaks the code. Carefully follow the convention shown here when using importArticles.
But there's much more to importArticles than just this! For more examples and advanced usage, see the help page at Help:Including additional JavaScript and CSS.


Note: When you use the script for the first time, refresh the page, or cleared the cache, it will take a while to load all external scripts.

Sources

CodeMirror Code viewer and editor
Pretty Diff JavaScript beautifier
CSS beautifier and minifier
Closure Compiler JavaScript minifier
JSHint Live JavaScript syntax checker
CSS Lint Live CSS syntax checker

Features

  • Character count
  • Purge cache when saving
  • Save (and load) content
  • Syntax highlight while editing
JavaScript CSS
Auto-close brackets and quotes
Auto-indent
Beautify
Code folding
Comment folding
Detect unnecessary whitespace
Find and replace (text and RegExp)
Full screen mode
Go to line
Highlight active line
Highlight brackets
Hints
Line numbers
Live syntax checker
Minify

Usage

Once the script is installed, when browsing a JavaScript or CSS code page, a "View code" button will appear. Clicking the button will change the appearance of the code. The number of pages of the wiki will change into the number of characters of the code.

To edit the code, click on the "Edit" button.

To publish the code, click on the "Publish" button. Beside the button is a drop-down arrow. Clicking the arrow will open a drop-down menu. The options in the menu are "Shortcuts," "Show changes," and "Save."

Clicking the "Shortcuts" option will open a popup that displays the following:

Alt → Go to last character of selected line
Alt ← Go to first character of selected line
Alt L Go to line
Ctrl [ Indent less
Ctrl ] Indent more
Ctrl B Beautify
Ctrl D Remove line
Ctrl F Search
Ctrl G Find next
Ctrl M[1] Minify
Ctrl Space[2] Open hints
F11 Go to (or exit from) full screen mode
Shift Ctrl F Replace
Shift Ctrl G Find previous
Shift Ctrl R Replace all

Clicking the "Show changes" option will open a popup that displays the changes you made in the code.

Clicking the "Save" option will store the code in your browser using localStorage. To continue where you left off, click the "Load" option. These options are browser-dependent (i.e., if you saved a code in browser X, you can load that saved code in that browser only).

  1. Three buttons will appear: one for selecting the minified code, one for transferring the minified code to the code editor, and the other for publishing a page that contains the minified code.
  2. A popup menu will appear. It displays auto-completion suggestions, as well as the list of variable names, functions, and methods.

Translations

The following messages are used by the script:

changes Changes
characters characters
editing Editing
goToLine Go to line
load Load
minorEdit Minor edit
newVersion There is a new version of this code. Would you like to replace the existing code with the new one?
no No
paste Paste to editor
publish Publish
publishAs Publish as
replace Replace
save Save
search Search this wiki
selectAll Select all
shortcut Shortcuts
showChanges Show changes
summary Summary
unpublished You have made some unpublished edits. Are you sure you want to leave without publishing them?
view View code
yes Yes

If you would like to help out, please post translations for those messages on the script's talk page or add them directly to MediaWiki:Code/code.js.

Updates

25 January 2014
Added shortcuts dialog
Fixed script error
24 December 2013
Added the ability to show changes
5 December 2013
Bug fix
4 December 2013
Added button so that script will not immediately start
22 November 2013
Bug fix
16 November 2013
Added throbber to show that the script is loading
15 November 2013
Added Polish translation
9 November 2013
Used mw.loader.implement rather than $.getScript in loading external scripts (thanks Cqm!)
8 November 2013
Initial release

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.