added support for standard, cologneblue, nostalgia in mw.util.addPortletLink + update...
authorKrinkle <krinkle@users.mediawiki.org>
Sun, 24 Oct 2010 19:32:11 +0000 (19:32 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Sun, 24 Oct 2010 19:32:11 +0000 (19:32 +0000)
resources/mediawiki/mediawiki.util.js
resources/mediawiki/mediawiki.utiltest.js

index 28025c0..f7a6774 100644 (file)
@@ -12,7 +12,6 @@
                        if (this.initialised === false) {
                                this.initialised = true;
 
                        if (this.initialised === false) {
                                this.initialised = true;
 
-
                                // Set tooltipAccessKeyPrefix
                                if (is_opera) {
                                        this.tooltipAccessKeyPrefix = 'shift-esc-';
                                // Set tooltipAccessKeyPrefix
                                if (is_opera) {
                                        this.tooltipAccessKeyPrefix = 'shift-esc-';
 
                                // Any initialisation after the DOM is ready
                                $(function () {
 
                                // Any initialisation after the DOM is ready
                                $(function () {
+                               
+                                       // Enable CheckboxShiftClick
                                        $('input[type=checkbox]:not(.noshiftselect)').enableCheckboxShiftClick();
                                        $('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
                 *
                 * @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) {
                 */
                '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 $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(' &#124; ');
+                               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 {
                                } 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);
                }
 
        };
                }
 
        };
index 5431b12..5122dbf 100644 (file)
@@ -8,7 +8,6 @@
        mediaWiki.test = {
 
                /* Variables */
        mediaWiki.test = {
 
                /* Variables */
-               '$bodyContent' : null,
                '$table' : null,
                'addedTests' : [],
 
                '$table' : null,
                'addedTests' : [],
 
                * Adds a row to the test-table
                *
                * @param String code    Code of the test to be executed
                * 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>');
                },
 
                        this.$table.append('<tr><td>' + mw.util.htmlEscape(code) + '</td><td>' + mw.util.htmlEscape(result) + '<td></td></td><td>?</td></tr>');
                },
 
@@ -36,8 +39,7 @@
                                                // Build page
                                                document.title = 'mediaWiki.util JavaScript Test - ' + wgSiteName;
                                                $('#firstHeading').text('mediaWiki.util JavaScript Test');
                                                // 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>'
                                                        '<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)');
                                                        '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,
 
                                                // Run tests and compare results
                                                var     exec,
                                                        result,
                                                        resulttype,
                                                        numberoftests = 0,
+                                                       numberofpasseds = 0,
+                                                       numberofpartials = 0,
                                                        numberoferrors = 0,
                                                        $testrows;
                                                $testrows = mw.test.$table.find('tr');
                                                        numberoferrors = 0,
                                                        $testrows;
                                                $testrows = mw.test.$table.find('tr');
                                                                
                                                                exec = mw.test.addedTests[i][0];
                                                                shouldreturn = mw.test.addedTests[i][1];
                                                                
                                                                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);
                                                                
                                                                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++;
                                                                } 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>');
 
                                        }
                                });
 
                                        }
                                });