if (this.initialised === false) {
this.initialised = true;
-
// Set tooltipAccessKeyPrefix
if (is_opera) {
this.tooltipAccessKeyPrefix = 'shift-esc-';
// Any initialisation after the DOM is ready
$(function () {
+
+ // Enable CheckboxShiftClick
$('input[type=checkbox]:not(.noshiftselect)').enableCheckboxShiftClick();
+
+ // Fill bodyContant var
+ if ($('#bodyContent').length) {
+ mw.util.$content = $('#bodyContent');
+ } else if ($('#article').length) {
+ mw.util.$content = $('#article');
+ } else {
+ mw.util.$content = $('#content');
+ }
});
}
});
},
+
+ // jQuery object that refers to the page-content element
+ // Populated by init()
+ '$content' : null,
/**
* @param String accesskey accesskey to activate this link (one character, try to avoid conflicts. Use $('[accesskey=x').get() in the console to see if 'x' is already used.
* @param mixed nextnode DOM node or jQuery-selector of the item that the new item should be added before, should be another item in the same list will be ignored if not the so
*
- * @return Node the DOM node of the new item (a LI element) or null
+ * @return Node the DOM node of the new item (a LI element, or A element for older skins) or null
*/
'addPortletLink' : function (portlet, href, text, id, tooltip, accesskey, nextnode) {
- var $portlet = $('#' + portlet);
- if ($portlet.length === 0) {
- return null;
- }
- var $ul = $portlet.find('ul').eq(0);
- if ($ul.length === 0) {
- if ($portlet.find('div').length === 0) {
- $portlet.append('<ul />');
- } else {
- $portlet.find('div').eq(-1).append('<ul />');
- }
- $ul = $portlet.find('ul').eq(0);
- }
- if ($ul.length === 0) {
- return null;
- }
-
- // unhide portlet if it was hidden before
- $portlet.removeClass('emptyPortlet');
-
var $link = $('<a />').attr('href', href).text(text);
- var $item = $link.wrap('<li><span /></li>').parent().parent();
-
- if (id) {
- $item.attr('id', id);
- }
- if (accesskey) {
- $link.attr('accesskey', accesskey);
- tooltip += ' [' + accesskey + ']';
- }
- if (tooltip) {
- $link.attr('title', tooltip);
- }
- if (accesskey && tooltip) {
- this.updateTooltipAccessKeys($link);
- }
-
- // Append using DOM-element passing
- if (nextnode && nextnode.parentNode == $ul.get(0)) {
- $(nextnode).before($item);
- } else {
- // If the jQuery selector isn't found within the <ul>, just append it at the end
- if ($ul.find(nextnode).length === 0) {
- $ul.append($item);
+
+ // Some skins don't have portlets
+ // Just add it to the bottom of their 'sidebar' element ignoring the specified portlet target
+ switch (skin) {
+ case 'standard' :
+ case 'cologneblue' :
+ $("#quickbar").append($link.after('<br />'));
+ return $link.get(0);
+ case 'nostalgia' :
+ $("#searchform").before($link).before(' | ');
+ return $link.get(0);
+ default : // chick, modern, monobook, myskin, simple, vector...
+
+ var $portlet = $('#' + portlet);
+ if ($portlet.length === 0) {
+ return null;
+ }
+ var $ul = $portlet.find('ul').eq(0);
+ if ($ul.length === 0) {
+ if ($portlet.find('div').length === 0) {
+ $portlet.append('<ul />');
+ } else {
+ $portlet.find('div').eq(-1).append('<ul />');
+ }
+ $ul = $portlet.find('ul').eq(0);
+ }
+ if ($ul.length === 0) {
+ return null;
+ }
+
+ // unhide portlet if it was hidden before
+ $portlet.removeClass('emptyPortlet');
+
+ var $item = $link.wrap('<li><span /></li>').parent().parent();
+
+ if (id) {
+ $item.attr('id', id);
+ }
+ if (accesskey) {
+ $link.attr('accesskey', accesskey);
+ tooltip += ' [' + accesskey + ']';
+ }
+ if (tooltip) {
+ $link.attr('title', tooltip);
+ }
+ if (accesskey && tooltip) {
+ this.updateTooltipAccessKeys($link);
+ }
+
+ // Append using DOM-element passing
+ if (nextnode && nextnode.parentNode == $ul.get(0)) {
+ $(nextnode).before($item);
} else {
- // Append using jQuery CSS selector
- $ul.find(nextnode).eq(0).before($item);
+ // If the jQuery selector isn't found within the <ul>, just append it at the end
+ if ($ul.find(nextnode).length === 0) {
+ $ul.append($item);
+ } else {
+ // Append using jQuery CSS selector
+ $ul.find(nextnode).eq(0).before($item);
+ }
}
+
+ return $item.get(0);
}
-
- return $item.get(0);
}
};
mediaWiki.test = {
/* Variables */
- '$bodyContent' : null,
'$table' : null,
'addedTests' : [],
* Adds a row to the test-table
*
* @param String code Code of the test to be executed
- * @param String result Expected result in 'var (vartype)' form.
+ * @param String result Expected result in 'var (vartype)' form
+ * @param String contain Important part of the result, if result is different but does contain this it will not return ERROR but PARTIALLY
*/
- 'addTest' : function (code, result) {
- this.addedTests.push([code, result]);
+ 'addTest' : function (code, result, contain) {
+ if (!contain) {
+ contain = result;
+ }
+ this.addedTests.push([code, result, contain]);
this.$table.append('<tr><td>' + mw.util.htmlEscape(code) + '</td><td>' + mw.util.htmlEscape(result) + '<td></td></td><td>?</td></tr>');
},
// Build page
document.title = 'mediaWiki.util JavaScript Test - ' + wgSiteName;
$('#firstHeading').text('mediaWiki.util JavaScript Test');
- mw.test.bodyContent = $('#bodyContent');
- mw.test.bodyContent.html(
+ mw.util.$content.html(
'<p>Below is a list of tests to confirm proper functionality of the mediaWiki.util functions</p>' +
'<hr />' +
'<table id="mw-mwutiltest-table" class="wikitable sortable"><tr><th>Exec</th><th>Should return</th><th>Does return</th><th>Equal ?</th></tr></table>'
'function (string)');
mw.test.addTest('typeof mw.util.addPortletLink("p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print")',
'object (string)');
- mw.test.addTest('mw.util.addPortletLink("p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print").outerHTML',
- '<li id="t-mworg"><span><a href="http://mediawiki.org/" accesskey="m" title="Go to MediaWiki.org [ctrl-alt-m]">MediaWiki.org</a></span></li> (string)');
+ mw.test.addTest('a = mw.util.addPortletLink("p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print"); if(a){ a.outerHTML; }',
+ '<li id="t-mworg"><span><a href="http://mediawiki.org/" accesskey="m" title="Go to MediaWiki.org [ctrl-alt-m]">MediaWiki.org</a></span></li> (string)',
+ 'href="http://mediawiki.org/"');
// Run tests and compare results
var exec,
result,
resulttype,
numberoftests = 0,
+ numberofpasseds = 0,
+ numberofpartials = 0,
numberoferrors = 0,
$testrows;
$testrows = mw.test.$table.find('tr');
exec = mw.test.addedTests[i][0];
shouldreturn = mw.test.addedTests[i][1];
+ shouldcontain = mw.test.addedTests[i][2];
doesreturn = eval(exec);
doesreturn = doesreturn + ' (' + typeof doesreturn + ')';
$thisrow = $testrows.eq(i + 1);
$thisrow.find('> td').eq(2).text(doesreturn);
- if (shouldreturn === doesreturn) {
- $thisrow.find('> td').eq(3).css('background', '#EFE').text('OK');
+ if (doesreturn.indexOf(shouldcontain) !== -1) {
+ if (doesreturn == shouldreturn){
+ $thisrow.find('> td').eq(3).css('background', '#EFE').text('OK');
+ numberofpasseds++;
+ } else {
+ $thisrow.find('> td').eq(3).css('background', '#FFE').html('<small>PARTIALLY</small>');
+ numberofpartials++;
+ }
} else {
$thisrow.find('> td').eq(3).css('background', '#FEE').text('ERROR');
numberoferrors++;
})
);
- mw.test.$table.before('<p><strong>Ran ' + numberoftests + ' tests. ' + numberoferrors + ' error(s). </p>');
+ mw.test.$table.before('<p><strong>Ran ' + numberoftests + ' tests. ' + numberofpasseds + ' passed test(s). ' + numberoferrors + ' error(s). ' + numberofpartials + ' partially passed test(s). </p>');
}
});