User:Cacycle/editor

From wikishia
This software is no longer actively maintained. Please switch to its successor wikEd. This page is kept solely for historical reasons.

Change log

  • Maintenance update: fixed the summary field size. Press SHIFT-Reload to update! Cacycle 21:54, 21 October 2006 (UTC)
  • New functions: Find ahead, html-to-wikicode for tables, links, and images, horizontal cursor memory, jump to position of last change. Cacycle 20:46, 19 February 2006 (UTC)
  • A fullscreen editing mode has been added. Cacycle 22:30, 12 February 2006 (UTC)
  • SetupEditor(); is now called automatically, incompatibilities with Wikipedia:Tools/Navigation popups have been fixed. Cacycle 12:01, 8 February 2006 (UTC)
  • The diff code has been moved to User:Cacycle/diff and several options have been changed

The edit tool

User:Cacycle/editor.js is a script that adds extended editing functions to Wikipedia edit pages. Currently it works only for Mozilla Firefox, Mozilla, and Mozilla SeaMonkey browsers. Features include regular expression search and replace, server-independent Show preview and Show changes, one-click fixing of common mistakes, and undo/redo. Simply add one of the code snippet from below to your User:YourUsername/monobook.js page.

Features

Adds the following functions as buttons below the edit textarea:

  • Fullscreen editing area on a click
  • Comfortable find an replace with case insensitive find and regular expression support
  • Server-independent Show preview (uses Live Preview)
  • Server-independent Show changes, uses User:Cacycle/diff for the color-coded visualization of deletions, additions, and block movements
  • 20 level undo / redo for the editor buttons, undo-all button
  • History for summary, find, and replace fields from drop-down menus (history is not lost between browser sessions and is accessible from different windows)
  • Predefined and customizable summary texts
  • Find ahead as you type
  • Bold, italic, and lowercase buttons
  • Decrease and increase heading levels
  • Formatting functions can be restricted to selected text
  • Fixing common mistakes with one button:
    • Basic — spaces and empty lines
    • Dashes
    • Units
    • Math
    • HTML — change html to wikicode including tables
    • Capitalizing headers and lists
  • All buttons have popup descriptions (titles)
  • The cursor position and the selected text is kept visible in the textbox
  • Horizontal cursor memory
  • Jump to position of last change
  • Many custom options

Preview

File:Cacycle editor.png
Screenshot of the cacycle JavaScript editor in action

Source code

User:Cacycle/editor.js

Installation

Simply add one of the following code snippets to your User:YourUsername/monobook.js (or whatever skin used) page. After saving, you have to bypass your browser's cache to see the changes,  hold down Shift while clicking Reload (or press Ctrl-Shift-R).

Ultra-simple version (expands to the simple version upon saving the page):

{{subst:EditTool}}

Simple version:

// install [[User:Cacycle/diff]] text diff code
document.write('<script type="text/javascript" src="'
  + 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/diff.js' <!--wikEdSpaceLine-->
  + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

// install [[User:Pilaf/Live_Preview]] page preview tool
document.write('<script type="text/javascript" src="'
  + 'http://en.wikipedia.org/w/index.php?title=User:Pilaf/livepreview.js' <!--wikEdSpaceLine-->
  + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

// install [[User:Cacycle/editor]] edit tool
document.write('<script type="text/javascript" src="'
  + 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/editor.js' <!--wikEdSpaceLine-->
  + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

Version with all configuration options:

// include comfortable javascript editor by cacycle

// levels of undo (each level holds the whole text)
undoBufferMax = 20;

// style for preview box
stylePreviewBox = 'background-color: #f9f9f9;';

// style for custom edit buttons
styleButtons = 'font-size: smaller; padding-left: 0.1em; padding-right: 0.1em';

// presets for input field dropdown options
findHistoryLength = 10;

// preset for combo box select options
presetOptions = [];
presetOptions['summary'] = [
  'Copyedit',
  'Linkfix',
  'Reverting vandalism',
  'Formatting source text'
];

// expiration time span for history cookies in seconds
cookieExpireSec = (365 * 24 * 60 * 60);

// enable cursor horizontal position memory
cursorMemory = true;

// show at least this number of lines ahead of cursor movement
scrollMargin = 1;

// show at least this number of lines ahead of cursor movement for
findMargin = 2;

// find ahead checkbox selected by default
findAheadSelected = true;

// css for change indicators
styleDelete = 'font-weight: normal; text-decoration: none; color: #ffffff; background-color: #990033;';
styleInsert = 'font-weight: normal; text-decoration: none; color: #ffffff; background-color: #009933;';
styleMoved  = 'font-weight: bold; vertical-align: text-bottom; font-size: xx-small; padding: 0; border: solid 1px;';
styleBlock  = [
        'background-color: #ffff44;',
        'background-color: #b0ff90;',
        'background-color: #ffcc99;',
        'background-color: #99ffff;',
        'background-color: #99ccff;',
        'background-color: #cc99ff;',
        'background-color: #ff99cc;',
        'background-color: #ffd040;',
        'background-color: #d0d0d0;'
];

// html for change indicators, {number} is replaced by the block number, {block} is replaced by the block style
htmlMovedRight  = '<input type="button" value=">" style="' + styleMoved + ' {block}">';
htmlMovedLeft   = '<input type="button" value="<" style="' + styleMoved + ' {block}">';

htmlBlockStart  = '<span style="{block}">';
htmlBlockEnd    = '</span>';

htmlDeleteStart = '<span style="' + styleDelete + '">';
htmlDeleteEnd   = '</span>';

htmlInsertStart = '<span style="' + styleInsert + '">';
htmlInsertEnd   = '</span>';

// minimal number of real words for a moved block (0 for always displaying block move indicators)
blockMinLength = 3;

// exclude identical sequence starts and endings from change marking
wordDiff = true;

// enable recursive diff to resolve problematic sequences
recursiveDiff = true;

// enable block move display
showBlockMoves = true;

// install [[User:Cacycle/diff]] text diff code
document.write('<script type="text/javascript" src="'
  + 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/diff.js' <!--wikEdSpaceLine-->
  + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

// install [[User:Pilaf/Live_Preview]] page preview tool
document.write('<script type="text/javascript" src="'
  + 'http://en.wikipedia.org/w/index.php?title=User:Pilaf/livepreview.js' <!--wikEdSpaceLine-->
  + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

// install [[User:Cacycle/editor]] edit tool
document.write('<script type="text/javascript" src="'
  + 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/editor.js' <!--wikEdSpaceLine-->
  + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

Installation tips

  • SetupEditor() is called automatically and has not to be added to a window.onload function
  • The configuration parts are optional and can be omitted
  • If you already use User:Pilaf/livepreview.js then you should not call its installation routine LivePreviewInstall()
  • Do not forget to flush your cache after installation (hold down Shift while clicking Reload or press Ctrl-Shift-R).

Developer version

The developer version can be found under User:Cacycle/editor_dev.js.

License