Commit graph

27 commits

Author SHA1 Message Date
Krinkle
0e82a6cfd0 Applying whitespace conventions in core JS files.
* Mostly whitespace in callers: $('foo').bar(baz,quux) => $( 'foo' ).bar( baz, quux )
* Also several occurrences of mixes spaces and tabs in the indention in front of a line, converted to tabs.
* And double spaces -> single spaces at random.
2011-08-12 21:48:10 +00:00
Daniel Friesen
7e8f5f1e8f Fix usage of the jQuery global in a few spots.
- jQuery changed to $ in some files because there is a closure that creates a locally scoped $, but the jQuery var is globally scoped, meaning using jQuery instead of $ inside that closure could result in interacting with a different instance of jQuery than the uses of $ in that same closure.
- In mwExtension wrap the code inside a closure which it is missing. Also take this chance to fix the whitespace style `fn( arg )` instead of `fn(arg)` on the isArray I added.
This is partially a followup to r94331.

Note: The jquery plugins inside the jquery/ folder look fine for use of jQuery within closures, except for mockjax.
2011-08-12 09:27:16 +00:00
Mark A. Hershberger
a0d7b9b71c Followup r90239: Move return till after the toggle is executed. 2011-06-26 20:00:20 +00:00
Mark A. Hershberger
9cbcb3be0c Fix Bug #28344 - “Links doesn't work inside collapsible toggles”
Patch from mybugs.mail

    If a link is added inside of a collapsible toggle and a user click on it, the
    target page should be opened.
    …
    The attached patch was tested locally and fixes this bug (clicking outside the
    link toogles the collapsed content, and clicking on the link opens the target
    page).

    PS: It is the same code which was used to fix the problem on Commons.

    http://commons.wikimedia.org/w/index.php?diff=45383826&oldid=45265712
2011-06-16 22:27:22 +00:00
Krinkle
3345eee6ad makeCollapsible fix for jQuery 1.6.1
* Pre 1.6, jQuery returned an empty string for attributes that were not set. Although in a way that was wrong, it was the way it was. From jQuery documentation: "As of jQuery 1.6, the .attr() method returns <code>undefined</code> for attributes that have not been set." [1]
** Fixing makeCollapsible by removing empty-string checks and casting to boolean instead
* Wrapped a long line

[1] http://api.jquery.com/attr/

(jQuery 1.6.1 upgrade was in r89866)
2011-06-14 21:20:30 +00:00
Krinkle
66e64cb2f0 Moving check higher up in case there's a premade toggle _but_ no .wm-collapsible-content premade. This way the link will be caught before it's inner-wrapped, after which it would no longer be a direct child. 2011-05-23 19:08:26 +00:00
Krinkle
ac354d7ca3 .length has the same number of characters as length and saves a function all. whatever 2011-05-09 17:24:07 +00:00
Krinkle
447670a769 jquery.makeCollapsible improvements
* Check for validness of $defaultToggle only needed once (Follow-up r83309 CR)
* The new jQuery sortable plugin caused a minor breakage in other actions bound within table cells. Since, in contrary to the old wikibits script, the entire <th> is clickable and the triangle is a background image. This means anything that is clickable inside the <th> (such as [<a>Collapse</a>] propagates/bubbles up to the <th> and causes the column to be re-sorted. In other words, collapsing a table caused the last column to be sorted, and when expanded again in the opposite order. Fixed by adding event.stopPropagation(); (note, not "return false" as there may be custom events bound to the anchor tag which should be fired as well. We just need to stop propagation not all other event, such as for customToggles).
2011-05-09 17:21:35 +00:00
Krinkle
db8f2328c2 per r83658 CR: mw.log.prefix is for identifying windows, not context. Using string concat instead 2011-03-18 22:16:12 +00:00
Krinkle
6fd85d1cd0 removing fallback, not needed (messages are in-core and defined in Resources.php). FU: r78966 2011-03-07 21:17:47 +00:00
Krinkle
27b5c803d7 Fix bug in makeCollapsible.
* The instantHide implementation (added in r82471) didn't cover the case where a table is collapsed by default, it needs to pass the toggle to the function so that the row it is in can be excluded.
* The bug was found by user Helder.wiki, also reproducable on the demonstration page (I guess it was cached for everyone, since nobody noticed?)
* Demonstration page has been refreshed and all tests are passed now.
2011-03-05 19:00:19 +00:00
Krinkle
86d10b8ce0 Closing tags in jQuery-element creation. Bug in jQuery, using the shortcut doens't work in IE8, it needs to be <open></close> 2011-02-28 21:20:23 +00:00
Krinkle
d2a23f2e22 Improving jquery.makeCollapsible & small fixed mw.util
* Making makeCollapsible more DRY. 
* Small optimalizations and fixes in mw.util
2011-02-19 17:46:30 +00:00
Krinkle
2e6b0c5fa1 Fixing issue with multiple premade toggles in a non-custom collapsible element.
The problem is that when one of the toggles is clicked the classname is only changed on the toggle that was clicked. The others will stil have the wrong class. On of the areas in which this may lead to weird behaviour is the :hover styles for the up- and downarrow cursors.

Previously would bind to all of them :

<pre>
 = .find( '> .mw-collapsible-toggle' );
// ^ may match multiple ones
</pre>

...  which is good. But in the click handler:

<pre>
[..].bind( 'click.mw-collapse', function( e ){
toggleLinkPremade( this, e );
} );
</pre>

... only called the function with 'this'. This has been changed to pass all of  instead.

This problem was discovered in the following scenario. Where an .mw-collapsible has three children. The first two are clickable and are the togglers for the third child.
http://translatewiki.net/w/i.php?title=Sandbox&oldid=2692006
2011-02-11 22:30:14 +00:00
Krinkle
bc0f9cac32 Wrapping core modules (FIXME from r79929)
(Touch: r74088, r73046)
2011-01-31 19:33:16 +00:00
Krinkle
8fad46e6ad * Toggle entire element if no .mw-collapsible-content is found
* Bug fixed in which a single customtoggle should trigger multiple customcollapsible elements

If no .mw-collapsible-content element is found when the toggleElement() function is called, assume that the user wants the mw-collapsible itself to be toggled. This enables custom use with table rows (in which we dont want something inside to toggle but the entire table row) - with a remote toggle.

This change makes it possible to have a togglable table-row.

The intial "collapsed" state for a mw-customtoggle is no longer executed by performing a click on the mw-customtoggle. Instead by calling the toggle function directly.
Reason being that an mw-customtoggle could have any number of special functions bound to it (be it the function to toggle another mw-customcollapsible, or perhaps a totally different function).

I considered using this method for 'normal' default togglers as well. However default togglers have more actions involved aside from just 'toggling' the element. Namely changing the innerText to the localized message and swapping classes. Those stay as they are by simply simulating a click() event on them (if the initial state should be collapsed).
2011-01-02 04:46:44 +00:00
Krinkle
0f8d4d4481 Treat premade toggle links as a custom instead of default case (ie. dont change the text) (Follow-up r78989 CR) 2010-12-27 17:37:19 +00:00
Krinkle
31c71dbdb4 The toggle link may be in any of the cells of the first row. The default will stick to the last cell but when detecting premade links, it now scans the entire first row instead of just the last cell. 2010-12-27 16:43:50 +00:00
Krinkle
d4ff136244 Added remote binding for custom collapsibles and minor improvements
* Fixed JSLint errors
* Added support for custom collapsibles that can have togglelink(s) anywhere in the document
* To prevent people from making secret toggle links (vandalism?) for things like '#content', prefix 'mw-customcollapsible-' is required
* Merged a few comments (bit less verbose)
* Adding extra check when fixing li-value. Value-attribute of an ordered list items defaults to '-1' instead of '' in Mozilla Firefox 3.
2010-12-25 03:26:09 +00:00
Krinkle
fd7afe8b90 Fixing typo from r78944 2010-12-24 16:08:42 +00:00
Krinkle
61c52fcdd5 Adding fallback for collapsible messages 2010-12-24 15:27:11 +00:00
Krinkle
ed5d9a08b0 Forgot to namespace the click handler. Unbinding all click handlers is indeed risky (Follow-up r78935 CR) 2010-12-24 15:24:28 +00:00
Krinkle
5a8133d6d9 Removing debug call. Follow-up r78935 CR 2010-12-24 14:34:27 +00:00
Krinkle
6c83eee8ac Fixing TODO from r78915
* Removed old "kr-" prefix for the plugin
* Moved function call from the bottom of the script to mw init function
2010-12-24 01:30:23 +00:00
Krinkle
1a827a0984 Improving jquery.makeCollapsible:
* Setting toggle function in a variable to easier reuse it through the plugin
* Replace "-hide" and "-show" classes with "expanded" and "collapsed" respectively
* For more flexibility, if there's a toggle-element already, bind the function to it and use it instead. Otherwise, just create one as usual. See [[betawiki:User:Krinkle/CollapsingTestpageKr#footer|CollapsingTestpageKr#Combination example]]
** It's more likely that the source has a custom position of the togglelink waiting for it to be bound, then it to be already bound.
* Some comments improved
* Message key "hide" to "collapsible-collapse" (Follow-up r78915 CR)
* Message key "show" to "collapsible-expand"
* Changed toggle-link content filling from html() to text() (message errors like <keyname> caused an HTML-element to be created)
2010-12-23 23:34:32 +00:00
Krinkle
9ba8bf97fa whitespace according to mw conventions + using mw.msg instead of english hardcoding 2010-12-23 19:26:30 +00:00
Krinkle
eb18151c7a adding jQuery.makeCollapsible plugin 2010-12-23 19:25:16 +00:00