Index: branches/wmf/1.19wmf1/extensions/CategoryTree/modules/ext.categoryTree.js |
— | — | @@ -27,7 +27,7 @@ |
28 | 28 | */ |
29 | 29 | handleNode: function( e ) { |
30 | 30 | var $link = $( this ); |
31 | | - if ( $link.data( 'ctState' ) === 'collapsed' ) { |
| 31 | + if ( $link.data( 'ct-state' ) === 'collapsed' ) { |
32 | 32 | categoryTree.expandNode( $link ); |
33 | 33 | } else { |
34 | 34 | categoryTree.collapseNode( $link ); |
— | — | @@ -48,9 +48,9 @@ |
49 | 49 | $link |
50 | 50 | .html( mw.msg( 'categorytree-collapse-bullet' ) ) |
51 | 51 | .attr( 'title', mw.msg( 'categorytree-collapse' ) ) |
52 | | - .data( 'ctState', 'expanded' ); |
| 52 | + .data( 'ct-state', 'expanded' ); |
53 | 53 | |
54 | | - if ( !$link.data( 'ctLoaded' ) ) { |
| 54 | + if ( !$link.data( 'ct-loaded' ) ) { |
55 | 55 | categoryTree.loadChildren( $link, $children ); |
56 | 56 | } |
57 | 57 | }, |
— | — | @@ -68,7 +68,7 @@ |
69 | 69 | $link |
70 | 70 | .html( mw.msg( 'categorytree-expand-bullet' ) ) |
71 | 71 | .attr( 'title', mw.msg( 'categorytree-expand' ) ) |
72 | | - .data( 'ctState', 'collapsed' ); |
| 72 | + .data( 'ct-state', 'collapsed' ); |
73 | 73 | }, |
74 | 74 | |
75 | 75 | /** |
— | — | @@ -78,26 +78,55 @@ |
79 | 79 | * @param {jQuery} $children |
80 | 80 | */ |
81 | 81 | loadChildren: function( $link, $children ) { |
82 | | - $link.data( 'ctLoaded', true ); |
| 82 | + var $linkParentCTTag, ctTitle, ctMode, ctOptions; |
| 83 | + |
| 84 | + /** |
| 85 | + * Error callback |
| 86 | + */ |
| 87 | + function error() { |
| 88 | + var $retryLink; |
| 89 | + |
| 90 | + $retryLink = $( '<a>' ) |
| 91 | + .text( mw.msg( 'categorytree-retry' ) ) |
| 92 | + .attr( 'href', '#' ) |
| 93 | + .click( function ( e ) { |
| 94 | + e.preventDefault(); |
| 95 | + categoryTree.loadChildren( $link, $children ); |
| 96 | + } ); |
| 97 | + |
| 98 | + $children |
| 99 | + .text( mw.msg( 'categorytree-error' ) + ' ' ) |
| 100 | + .append( $retryLink ); |
| 101 | + } |
| 102 | + |
| 103 | + $link.data( 'ct-loaded', true ); |
| 104 | + |
83 | 105 | $children.html( |
84 | 106 | $( '<i class="CategoryTreeNotice"></i>' ) |
85 | 107 | .text( mw.msg( 'categorytree-loading' ) ) |
86 | 108 | ); |
87 | 109 | |
88 | | - var $parentTag = $link.parents( '.CategoryTreeTag' ); |
| 110 | + $linkParentCTTag = $link.parents( '.CategoryTreeTag' ); |
89 | 111 | |
90 | | - if ( $parentTag.length === 0 ) { |
91 | | - // Probably a CategoryPage |
92 | | - $parentTag = $( '<div />' ) |
93 | | - .hide() |
94 | | - .data( 'ctOptions', mw.config.get( 'wgCategoryTreePageCategoryOptions' ) ); |
| 112 | + // Element may not have a .CategoryTreeTag parent, fallback to defauls |
| 113 | + // Probably a CategoryPage (@todo: based on what?) |
| 114 | + ctTitle = $link.data( 'ct-title' ); |
| 115 | + ctMode = $linkParentCTTag.data( 'ct-mode' ); |
| 116 | + ctMode = typeof ctMode === 'number' ? ctMode : undefined; |
| 117 | + ctOptions = $linkParentCTTag.data( 'ct-options' ) || mw.config.get( 'wgCategoryTreePageCategoryOptions' ); |
| 118 | + |
| 119 | + // Mode and options have defaults or fallbacks, title does not. |
| 120 | + // Don't make a request if there is no title. |
| 121 | + if ( typeof ctTitle !== 'string' ) { |
| 122 | + error(); |
| 123 | + return; |
95 | 124 | } |
96 | 125 | |
97 | 126 | $.get( |
98 | 127 | mw.util.wikiScript(), { |
99 | 128 | action: 'ajax', |
100 | 129 | rs: 'efCategoryTreeAjaxWrapper', |
101 | | - rsargs: [$link.data( 'ctTitle' ), $parentTag.data( 'ctOptions' ), 'json'] // becomes &rsargs[]=arg1&rsargs[]=arg2... |
| 130 | + rsargs: [ctTitle, ctOptions, 'json'] // becomes &rsargs[]=arg1&rsargs[]=arg2... |
102 | 131 | } |
103 | 132 | ) |
104 | 133 | .success( function ( data ) { |
— | — | @@ -105,16 +134,20 @@ |
106 | 135 | data = data.replace(/##LOAD##/g, mw.msg( 'categorytree-expand' ) ); |
107 | 136 | |
108 | 137 | if ( data === '' ) { |
109 | | - switch ( $parentTag.data( 'ctMode' ) ) { |
| 138 | + switch ( ctMode ) { |
| 139 | + // CT_MODE_CATEGORIES = 0 |
110 | 140 | case 0: |
111 | 141 | data = mw.msg( 'categorytree-no-subcategories' ); |
112 | 142 | break; |
| 143 | + // CT_MODE_PAGES = 10 |
113 | 144 | case 10: |
114 | 145 | data = mw.msg( 'categorytree-no-pages' ); |
115 | 146 | break; |
| 147 | + // CT_MODE_PARENTS = 100 |
116 | 148 | case 100: |
117 | 149 | data = mw.msg( 'categorytree-no-parent-categories' ); |
118 | 150 | break; |
| 151 | + // CT_MODE_ALL = 20 |
119 | 152 | default: |
120 | 153 | data = mw.msg( 'categorytree-nothing-found' ); |
121 | 154 | } |
— | — | @@ -126,17 +159,10 @@ |
127 | 160 | .html( data ) |
128 | 161 | .find( '.CategoryTreeToggle' ) |
129 | 162 | .click( categoryTree.handleNode ); |
| 163 | + |
130 | 164 | categoryTree.showToggles(); |
131 | 165 | } ) |
132 | | - .error( function() { |
133 | | - var $retryLink = $( '<a />' ) |
134 | | - .text( mw.msg( 'categorytree-retry' ) ) |
135 | | - .attr( 'href', '#' ) |
136 | | - .click( function() { categoryTree.loadChildren( $link, $children ); } ); |
137 | | - $children |
138 | | - .text( mw.msg( 'categorytree-error' ) ) |
139 | | - .append( $retryLink ); |
140 | | - } ); |
| 166 | + .error( error ); |
141 | 167 | } |
142 | 168 | }; |
143 | 169 | |
Index: branches/wmf/1.19wmf1/extensions/CategoryTree/CategoryTreeFunctions.php |
— | — | @@ -315,19 +315,19 @@ |
316 | 316 | } |
317 | 317 | |
318 | 318 | $attr['data-ct-mode'] = $this->mOptions['mode']; |
319 | | - $attr['data-ct-options'] = Xml::escapeTagsOnly( $this->getOptionsAsJsStructure() ); |
| 319 | + $attr['data-ct-options'] = $this->getOptionsAsJsStructure(); |
320 | 320 | |
321 | 321 | $html = ''; |
322 | | - $html .= Xml::openElement( 'div', $attr ); |
| 322 | + $html .= Html::openElement( 'div', $attr ); |
323 | 323 | |
324 | 324 | if ( !$allowMissing && !$title->getArticleID() ) { |
325 | | - $html .= Xml::openElement( 'span', array( 'class' => 'CategoryTreeNotice' ) ); |
| 325 | + $html .= Html::openElement( 'span', array( 'class' => 'CategoryTreeNotice' ) ); |
326 | 326 | if ( $parser ) { |
327 | 327 | $html .= $parser->recursiveTagParse( wfMsgNoTrans( 'categorytree-not-found', $category ) ); |
328 | 328 | } else { |
329 | 329 | $html .= wfMsgExt( 'categorytree-not-found', 'parseinline', htmlspecialchars( $category ) ); |
330 | 330 | } |
331 | | - $html .= Xml::closeElement( 'span' ); |
| 331 | + $html .= Html::closeElement( 'span' ); |
332 | 332 | } |
333 | 333 | else { |
334 | 334 | if ( !$hideroot ) { |
Property changes on: branches/wmf/1.19wmf1/extensions/CategoryTree/CategoryTreeFunctions.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
335 | 335 | Merged /trunk/extensions/CategoryTree/CategoryTreeFunctions.php:r112856,112859 |
Property changes on: branches/wmf/1.19wmf1/extensions/CategoryTree |
___________________________________________________________________ |
Modified: svn:mergeinfo |
336 | 336 | Merged /trunk/extensions/CategoryTree:r112849,112851,112856,112859 |
Property changes on: branches/wmf/1.19wmf1/extensions |
___________________________________________________________________ |
Modified: svn:mergeinfo |
337 | 337 | Merged /trunk/extensions:r112849,112851,112856,112859 |