User:V111P/js/msgDisplay.js

/*

* msgDisplay.js

* ver. 2013-12-02

* Home: http://en.wikipedia.org/wiki/User:V111P/js/msgDisplay

*

* This script can be used by other scripts to display messages to the MediaWiki editor.

* To get the default display, call msgDisplay() without parameters.

* To get another display, call msgDisplay(displayID).

* See the bottom of the file to see which methods you can call

* on the object returned by msgDisplay().

*

* CC0 Public Domain Dedication:

* http://creativecommons.org/publicdomain/zero/1.0/

* If you use large parts of this code, please let me know.

* You should also let others know where the code originates:

* http://en.wikipedia.org/wiki/User:V111P/js/msgDisplay.js

* Thanks.

*/

mediaWiki.libs.msgDisplay = mediaWiki.libs.msgDisplay || function (displayId) {

"use strict";

var smd = mediaWiki.libs.msgDisplay;

var displayId = displayId || 'top';

var d = smd.displays[displayId];

if (!d) {

d = smd.displays[displayId] = createDisplay(displayId);

}

return d;

function createDisplay(displayId) {

"use strict";

function prt(str) {

if (console && console.log)

console.log(str);

}

var domId = 'msgDisplay_' + displayId;

var ltr = (document.getElementsByTagName('html')[0].dir != 'rtl');

var miscStyle = {

emSizeInPx: 12, // to be set in show()

minDisplayHeight: '1.4em', // user config name: minHeight

displayDivExpandHeight: '11.5em', // user config name: expandHeight

// the enhanced editing toolbar has z-index:5, the (X) link in the siteNotice has 98

displayDivCollapsedZindex: 7,

displayDivExpandedZindex: 101,

innerResizeHandleHeightPx: 3,

floatingMenuPxFromBottom: 19 // updated according to emSizeInPx in show()

};

var commonsUrl = '//upload.wikimedia.org/wikipedia/commons/';

var elProps = {

staticParentDiv: {

id: domId + '_outerBox',

'class': 'msgDisplay_outerBox',

css: {

height: miscStyle.minDisplayHeight,

'margin-left': (ltr ? '0' : '-13px'),

'margin-right': (ltr ? '-13px' : '0'),

'padding-bottom': '2px', // to make up for displayDiv's border

'background-color': '#ddd'

}

},

displayDiv: {

id: domId,

'class': 'msgDisplay',

tabindex: 0,

css: {

height: miscStyle.minDisplayHeight, // original, collapsed height

width: '100%',

overflow: 'auto',

'overflow-x': 'hidden',

position: 'absolute',

'z-index': miscStyle.displayDivCollapsedZindex,

border: 'black solid 1px',

background: '#fed', // can be set by user through msgDisplayConfid[displayId].background

'line-height': 'normal' // to cancel .wikiEditor-ui .wikiEditor-ui-text {line-height: 0}

}

},

floatingMenu: {

'class': 'msgDisplay_floatingMenu',

css: {

position: 'absolute',

left: (ltr ? 'auto' : 0),

right: (ltr ? 0 : 'auto'),

cursor: 'pointer',

margin: '1px 2px',

background: 'inherit'

}

},

floatingMenuExpandedSection: {

'class': 'msgDisplay_expandedSection'

},

floatingMenuButtonImg: {

'class': 'msgDisplay_menuButton',

src: commonsUrl

+ 'thumb/8/8f/WMF-Agora-Settings_BCBCBC.svg/26px-WMF-Agora-Settings_BCBCBC.svg.png',

width: 13,

height: 13,

alt: '[*]',

title: '[*]',

css: {cursor: 'auto'}

},

okButtonImg: {

'class': 'msgDisplay_okButton',

src: commonsUrl + 'thumb/a/ac/Approve_icon.svg/26px-Approve_icon.svg.png',

width: 13,

height: 13,

alt: '[_]',

title: '[_]'

},

upButtonImg: {

'class': 'msgDisplay_upButton',

src: commonsUrl + '5/56/Icon_Arrow_Up_26x26.png',

width: 13,

height: 13,

alt: '[^]',

title: '[^]'

},

helpLink: {

'class': 'msgDisplay_helpLink',

href: helpLinkUrl, // reset in addTheFloatingMenu()

target: '_blank',

title: '?',

tabindex: -1

},

helpImg: {

src: commonsUrl + 'thumb/9/9e/Blue_Question.svg/26px-Blue_Question.svg.png',

width: 13,

height: 13,

alt: '[?]',

title: '[?]'

},

closeButtonImg: {

'class': 'msgDisplay_closeButton',

src: commonsUrl + 'thumb/d/d3/Button_hover.svg/26px-Button_hover.svg.png',

width: 13,

height: 13,

alt: '[X]',

title: '[X]',

tabindex: -1

}

};

var defaultHelpLinkUrl = '//en.wikipedia.org/wiki/User:V111P/js/msgDisplay/Help';

var helpLinkUrl = defaultHelpLinkUrl;

var defaultLocations = { // 'content' means mw.util.$content

top: {insertRelTo: 'content', insertRel: 'prepend'},

edit: {insertRelTo: '#wpTextbox1', insertRel: 'before'}

};

var defaultExpandCollapseChar = '!';

var defaultBlurChar = '`';

var defaultCloseChar = '^';

var keyPressFns = []; // use keypress() to register a keypress event handler

var onCloseOnUserActionFns = []; // use onCloseOnUserAction() to register an event handler

var onCollapseOnUserActionFns = []; // use onCollapseOnUserAction() to register an event handler

var $staticParentDiv;

var $displayDiv, $innerResizeHandle;

var $buffer = $('

');

var $menuDiv;

var $floatingMenu;

var configAll = window.msgDisplayConfig = window.msgDisplayConfig || {};

var cConfig = configAll._common || {};

var dConfig = configAll[displayId] || {};

var styleTagClass = 'msgDisplay_style';

$('style.' + styleTagClass).remove();

$(document.head).append('