| 91 | | // jQuery extensions |
| 92 | | $.fn.extend({ |
| 93 | | menuItemDepth : function() { |
| 94 | | return pxToDepth( this.eq(0).css('margin-left').slice(0, -2) ); |
| 95 | | }, |
| 96 | | updateDepthClass : function(current, prev) { |
| 97 | | return this.each(function(){ |
| 98 | | var t = $(this); |
| 99 | | prev = prev || t.menuItemDepth(); |
| 100 | | $(this).removeClass('menu-item-depth-'+ prev ) |
| 101 | | .addClass('menu-item-depth-'+ current ); |
| 102 | | }); |
| 103 | | }, |
| 104 | | shiftDepthClass : function(change) { |
| 105 | | return this.each(function(){ |
| 106 | | var t = $(this), |
| 107 | | depth = t.menuItemDepth(); |
| 108 | | $(this).removeClass('menu-item-depth-'+ depth ) |
| 109 | | .addClass('menu-item-depth-'+ (depth + change) ); |
| 110 | | }); |
| 111 | | }, |
| 112 | | childMenuItems : function() { |
| 113 | | var result = $(); |
| 114 | | this.each(function(){ |
| 115 | | var t = $(this), depth = t.menuItemDepth(), next = t.next(); |
| 116 | | while( next.length && next.menuItemDepth() > depth ) { |
| 117 | | result = result.add( next ); |
| 118 | | next = next.next(); |
| 119 | | } |
| 120 | | }); |
| 121 | | return result; |
| 122 | | }, |
| 123 | | updateParentMenuItemDBId : function() { |
| 124 | | return this.each(function(){ |
| 125 | | var item = $(this), |
| 126 | | input = item.find('.menu-item-data-parent-id'), |
| 127 | | depth = item.menuItemDepth(), |
| 128 | | parent = item.prev(); |
| 129 | | |
| 130 | | if( depth == 0 ) { // Item is on the top level, has no parent |
| 131 | | input.val(0); |
| 132 | | } else { // Find the parent item, and retrieve its object id. |
| 133 | | while( parent.menuItemDepth() != depth - 1 ) { |
| 134 | | parent = parent.prev(); |
| 135 | | } |
| 136 | | input.val( parent.find('.menu-item-data-db-id').val() ); |
| 137 | | } |
| 138 | | }); |
| 139 | | }, |
| 140 | | hideAdvancedMenuItemFields : function() { |
| 141 | | return this.each(function(){ |
| 142 | | var that = $(this); |
| 143 | | $('.hide-column-tog').not(':checked').each(function(){ |
| 144 | | that.find('.field-' + $(this).val() ).addClass('hidden-field'); |
| 145 | | }); |
| 146 | | }); |
| 147 | | }, |
| 148 | | selectItem : function() { |
| 149 | | return this.each(function(){ |
| 150 | | $(this).addClass('selected-menu-item') |
| 151 | | .next().children('input').attr('checked','checked'); |
| 152 | | }); |
| 153 | | }, |
| 154 | | deselectItem : function() { |
| 155 | | return this.each(function(){ |
| 156 | | $(this).removeClass('selected-menu-item') |
| 157 | | .next().children('input').removeAttr('checked'); |
| 158 | | }); |
| 159 | | }, |
| 160 | | toggleItem : function() { |
| 161 | | return this.each(function(){ |
| 162 | | var t = $(this); |
| 163 | | if( t.hasClass('selected-menu-item') ) |
| 164 | | t.deselectItem(); |
| 165 | | else |
| 166 | | t.selectItem(); |
| 167 | | }); |
| 168 | | }, |
| 169 | | /** |
| 170 | | * Adds selected menu items to the menu. |
| 171 | | * |
| 172 | | * @param jQuery metabox The metabox jQuery object. |
| 173 | | */ |
| 174 | | addSelectedToMenu : function(processMethod) { |
| 175 | | return this.each(function() { |
| 176 | | var t = $(this), |
| 177 | | checked = t.find('.tabs-panel-active .categorychecklist li input:checked'), |
| 178 | | re = new RegExp('menu-item\\[(\[^\\]\]*)'); |
| 179 | | |
| 180 | | processMethod = processMethod || api.addMenuItemToBottom; |
| 181 | | |
| 182 | | // If no items are checked, bail. |
| 183 | | if ( !checked.length ) |
| 184 | | return false; |
| 185 | | |
| 186 | | // Show the ajax spinner |
| 187 | | t.find('img.waiting').show(); |
| 188 | | |
| 189 | | // Retrieve menu item data |
| 190 | | $(checked).each(function(){ |
| 191 | | var checkbox = $(this), |
| 192 | | item = checkbox.parent().prev(); |
| 193 | | listItemDBIDMatch = re.exec( checkbox.attr('name') ); |
| 194 | | listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10); |
| 195 | | listItemData = getListDataFromID(listItemDBID); |
| 196 | | |
| 197 | | menuItem = {}; |
| 198 | | menuItem[listItemDBID] = listItemData; |
| 199 | | |
| 200 | | api.addItemToMenu(menuItem, processMethod, function(){ |
| 201 | | item.deselectItem(); |
| 202 | | }); |
| 203 | | }); |
| 204 | | |
| 205 | | // Remove the ajax spinner |
| 206 | | t.find('img.waiting').hide(); |
| 207 | | }); |
| 208 | | }, |
| 209 | | }); |
| 210 | | |
| | 121 | |
| | 122 | jQueryExtensions : function() { |
| | 123 | // jQuery extensions |
| | 124 | $.fn.extend({ |
| | 125 | menuItemDepth : function() { |
| | 126 | return pxToDepth( this.eq(0).css('margin-left').slice(0, -2) ); |
| | 127 | }, |
| | 128 | updateDepthClass : function(current, prev) { |
| | 129 | return this.each(function(){ |
| | 130 | var t = $(this); |
| | 131 | prev = prev || t.menuItemDepth(); |
| | 132 | $(this).removeClass('menu-item-depth-'+ prev ) |
| | 133 | .addClass('menu-item-depth-'+ current ); |
| | 134 | }); |
| | 135 | }, |
| | 136 | shiftDepthClass : function(change) { |
| | 137 | return this.each(function(){ |
| | 138 | var t = $(this), |
| | 139 | depth = t.menuItemDepth(); |
| | 140 | $(this).removeClass('menu-item-depth-'+ depth ) |
| | 141 | .addClass('menu-item-depth-'+ (depth + change) ); |
| | 142 | }); |
| | 143 | }, |
| | 144 | childMenuItems : function() { |
| | 145 | var result = $(); |
| | 146 | this.each(function(){ |
| | 147 | var t = $(this), depth = t.menuItemDepth(), next = t.next(); |
| | 148 | while( next.length && next.menuItemDepth() > depth ) { |
| | 149 | result = result.add( next ); |
| | 150 | next = next.next(); |
| | 151 | } |
| | 152 | }); |
| | 153 | return result; |
| | 154 | }, |
| | 155 | updateParentMenuItemDBId : function() { |
| | 156 | return this.each(function(){ |
| | 157 | var item = $(this), |
| | 158 | input = item.find('.menu-item-data-parent-id'), |
| | 159 | depth = item.menuItemDepth(), |
| | 160 | parent = item.prev(); |
| | 162 | if( depth == 0 ) { // Item is on the top level, has no parent |
| | 163 | input.val(0); |
| | 164 | } else { // Find the parent item, and retrieve its object id. |
| | 165 | while( parent.menuItemDepth() != depth - 1 ) { |
| | 166 | parent = parent.prev(); |
| | 167 | } |
| | 168 | input.val( parent.find('.menu-item-data-db-id').val() ); |
| | 169 | } |
| | 170 | }); |
| | 171 | }, |
| | 172 | hideAdvancedMenuItemFields : function() { |
| | 173 | return this.each(function(){ |
| | 174 | var that = $(this); |
| | 175 | $('.hide-column-tog').not(':checked').each(function(){ |
| | 176 | that.find('.field-' + $(this).val() ).addClass('hidden-field'); |
| | 177 | }); |
| | 178 | }); |
| | 179 | }, |
| | 180 | selectItem : function() { |
| | 181 | return this.each(function(){ |
| | 182 | $(this).addClass('selected-menu-item') |
| | 183 | .next().children('input').attr('checked','checked'); |
| | 184 | }); |
| | 185 | }, |
| | 186 | deselectItem : function() { |
| | 187 | return this.each(function(){ |
| | 188 | $(this).removeClass('selected-menu-item') |
| | 189 | .next().children('input').removeAttr('checked'); |
| | 190 | }); |
| | 191 | }, |
| | 192 | toggleItem : function() { |
| | 193 | return this.each(function(){ |
| | 194 | var t = $(this); |
| | 195 | if( t.hasClass('selected-menu-item') ) |
| | 196 | t.deselectItem(); |
| | 197 | else |
| | 198 | t.selectItem(); |
| | 199 | }); |
| | 200 | }, |
| | 201 | /** |
| | 202 | * Adds selected menu items to the menu. |
| | 203 | * |
| | 204 | * @param jQuery metabox The metabox jQuery object. |
| | 205 | */ |
| | 206 | addSelectedToMenu : function(processMethod) { |
| | 207 | return this.each(function() { |
| | 208 | var t = $(this), menuItems = {}, |
| | 209 | checkboxes = t.find('.tabs-panel-active .categorychecklist li input:checked'), |
| | 210 | re = new RegExp('menu-item\\[(\[^\\]\]*)'); |
| | 211 | |
| | 212 | processMethod = processMethod || api.addMenuItemToBottom; |
| | 213 | |
| | 214 | // If no items are checked, bail. |
| | 215 | if ( !checkboxes.length ) |
| | 216 | return false; |
| | 217 | |
| | 218 | // Show the ajax spinner |
| | 219 | t.find('img.waiting').show(); |
| | 220 | |
| | 221 | // Retrieve menu item data |
| | 222 | $(checkboxes).each(function(){ |
| | 223 | var listItemDBIDMatch = re.exec( $(this).attr('name') ), |
| | 224 | listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10); |
| | 225 | menuItems[listItemDBID] = getListDataFromID(listItemDBID); |
| | 226 | }); |
| | 227 | // Add the items |
| | 228 | api.addItemToMenu(menuItems, processMethod, function(){ |
| | 229 | // Deselect the items and hide the ajax spinner |
| | 230 | checkboxes.parent().prev().deselectItem(); |
| | 231 | t.find('img.waiting').hide(); |
| | 232 | }); |
| | 233 | }); |
| | 234 | }, |
| | 235 | }); |
| | 236 | }, |
| | 237 | |