admin.js
655 lines
| 1 | /******/ (function(modules) { // webpackBootstrap |
| 2 | /******/ // The module cache |
| 3 | /******/ var installedModules = {}; |
| 4 | /******/ |
| 5 | /******/ // The require function |
| 6 | /******/ function __webpack_require__(moduleId) { |
| 7 | /******/ |
| 8 | /******/ // Check if module is in cache |
| 9 | /******/ if(installedModules[moduleId]) { |
| 10 | /******/ return installedModules[moduleId].exports; |
| 11 | /******/ } |
| 12 | /******/ // Create a new module (and put it into the cache) |
| 13 | /******/ var module = installedModules[moduleId] = { |
| 14 | /******/ i: moduleId, |
| 15 | /******/ l: false, |
| 16 | /******/ exports: {} |
| 17 | /******/ }; |
| 18 | /******/ |
| 19 | /******/ // Execute the module function |
| 20 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
| 21 | /******/ |
| 22 | /******/ // Flag the module as loaded |
| 23 | /******/ module.l = true; |
| 24 | /******/ |
| 25 | /******/ // Return the exports of the module |
| 26 | /******/ return module.exports; |
| 27 | /******/ } |
| 28 | /******/ |
| 29 | /******/ |
| 30 | /******/ // expose the modules object (__webpack_modules__) |
| 31 | /******/ __webpack_require__.m = modules; |
| 32 | /******/ |
| 33 | /******/ // expose the module cache |
| 34 | /******/ __webpack_require__.c = installedModules; |
| 35 | /******/ |
| 36 | /******/ // identity function for calling harmony imports with the correct context |
| 37 | /******/ __webpack_require__.i = function(value) { return value; }; |
| 38 | /******/ |
| 39 | /******/ // define getter function for harmony exports |
| 40 | /******/ __webpack_require__.d = function(exports, name, getter) { |
| 41 | /******/ if(!__webpack_require__.o(exports, name)) { |
| 42 | /******/ Object.defineProperty(exports, name, { |
| 43 | /******/ configurable: false, |
| 44 | /******/ enumerable: true, |
| 45 | /******/ get: getter |
| 46 | /******/ }); |
| 47 | /******/ } |
| 48 | /******/ }; |
| 49 | /******/ |
| 50 | /******/ // getDefaultExport function for compatibility with non-harmony modules |
| 51 | /******/ __webpack_require__.n = function(module) { |
| 52 | /******/ var getter = module && module.__esModule ? |
| 53 | /******/ function getDefault() { return module['default']; } : |
| 54 | /******/ function getModuleExports() { return module; }; |
| 55 | /******/ __webpack_require__.d(getter, 'a', getter); |
| 56 | /******/ return getter; |
| 57 | /******/ }; |
| 58 | /******/ |
| 59 | /******/ // Object.prototype.hasOwnProperty.call |
| 60 | /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; |
| 61 | /******/ |
| 62 | /******/ // __webpack_public_path__ |
| 63 | /******/ __webpack_require__.p = ""; |
| 64 | /******/ |
| 65 | /******/ // Load entry module and return exports |
| 66 | /******/ return __webpack_require__(__webpack_require__.s = 2); |
| 67 | /******/ }) |
| 68 | /************************************************************************/ |
| 69 | /******/ ([ |
| 70 | /* 0 */ |
| 71 | /***/ (function(module, exports, __webpack_require__) { |
| 72 | |
| 73 | /* global menuIcons:false */ |
| 74 | __webpack_require__(3); |
| 75 | |
| 76 | (function ($) { |
| 77 | var miPicker; |
| 78 | |
| 79 | if (!menuIcons.activeTypes || _.isEmpty(menuIcons.activeTypes)) { |
| 80 | return; |
| 81 | } |
| 82 | /** |
| 83 | * @namespace |
| 84 | * @property {object} templates - Cached templates for the item previews on the fields |
| 85 | * @property {string} wrapClass - Field wrapper's class |
| 86 | * @property {object} frame - Menu Icons' media frame instance |
| 87 | * @property {object} target - Frame's target model |
| 88 | */ |
| 89 | |
| 90 | |
| 91 | miPicker = { |
| 92 | templates: {}, |
| 93 | wrapClass: 'div.menu-icons-wrap', |
| 94 | frame: null, |
| 95 | target: new wp.media.model.IconPickerTarget(), |
| 96 | |
| 97 | /** |
| 98 | * Callback function to filter active icon types |
| 99 | * |
| 100 | * TODO: Maybe move to frame view? |
| 101 | * |
| 102 | * @param {string} type - Icon type. |
| 103 | */ |
| 104 | typesFilter: function (type) { |
| 105 | return $.inArray(type.id, menuIcons.activeTypes) >= 0; |
| 106 | }, |
| 107 | |
| 108 | /** |
| 109 | * Create Menu Icons' media frame |
| 110 | */ |
| 111 | createFrame: function () { |
| 112 | miPicker.frame = new wp.media.view.MediaFrame.MenuIcons({ |
| 113 | target: miPicker.target, |
| 114 | ipTypes: _.filter(iconPicker.types, miPicker.typesFilter), |
| 115 | SidebarView: wp.media.view.MenuIconsSidebar |
| 116 | }); |
| 117 | }, |
| 118 | |
| 119 | /** |
| 120 | * Pick icon for a menu item and open the frame |
| 121 | * |
| 122 | * @param {object} model - Menu item model. |
| 123 | */ |
| 124 | pickIcon: function (model) { |
| 125 | miPicker.frame.target.set(model, { |
| 126 | silent: true |
| 127 | }); |
| 128 | miPicker.frame.open(); |
| 129 | }, |
| 130 | |
| 131 | /** |
| 132 | * Set or unset icon |
| 133 | * |
| 134 | * @param {object} e - jQuery click event. |
| 135 | */ |
| 136 | setUnset: function (e) { |
| 137 | var $el = $(e.currentTarget), |
| 138 | $clicked = $(e.target); |
| 139 | e.preventDefault(); |
| 140 | |
| 141 | if ($clicked.hasClass('_select') || $clicked.hasClass('_icon')) { |
| 142 | miPicker.setIcon($el); |
| 143 | } else if ($clicked.hasClass('_remove')) { |
| 144 | miPicker.unsetIcon($el); |
| 145 | } |
| 146 | }, |
| 147 | |
| 148 | /** |
| 149 | * Set Icon |
| 150 | * |
| 151 | * @param {object} $el - jQuery object. |
| 152 | */ |
| 153 | setIcon: function ($el) { |
| 154 | var id = $el.data('id'), |
| 155 | frame = miPicker.frame, |
| 156 | items = frame.menuItems, |
| 157 | model = items.get(id); |
| 158 | |
| 159 | if (model) { |
| 160 | miPicker.pickIcon(model.toJSON()); |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | model = { |
| 165 | id: id, |
| 166 | $el: $el, |
| 167 | $title: $('#edit-menu-item-title-' + id), |
| 168 | $inputs: {} |
| 169 | }; // Collect menu item's settings fields and use them |
| 170 | // as the model's attributes. |
| 171 | |
| 172 | $el.find('div._settings input').each(function () { |
| 173 | var $input = $(this), |
| 174 | key = $input.attr('class').replace('_mi-', ''), |
| 175 | value = $input.val(); |
| 176 | |
| 177 | if (!value) { |
| 178 | if (_.has(menuIcons.menuSettings, key)) { |
| 179 | value = menuIcons.menuSettings[key]; |
| 180 | } else if (_.has(menuIcons.settingsFields, key)) { |
| 181 | value = menuIcons.settingsFields[key]['default']; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | model[key] = value; |
| 186 | model.$inputs[key] = $input; |
| 187 | }); |
| 188 | items.add(model); |
| 189 | miPicker.pickIcon(model); |
| 190 | }, |
| 191 | |
| 192 | /** |
| 193 | * Unset icon |
| 194 | * |
| 195 | * @param {object} $el - jQuery object. |
| 196 | */ |
| 197 | unsetIcon: function ($el) { |
| 198 | var id = $el.data('id'); |
| 199 | $el.find('div._settings input').val(''); |
| 200 | $el.trigger('mi:update'); |
| 201 | miPicker.frame.menuItems.remove(id); |
| 202 | }, |
| 203 | |
| 204 | /** |
| 205 | * Update valeus of menu item's setting fields |
| 206 | * |
| 207 | * When the type and icon is set, this will (re)generate the icon |
| 208 | * preview on the menu item field. |
| 209 | * |
| 210 | * @param {object} e - jQuery event. |
| 211 | */ |
| 212 | updateField: function (e) { |
| 213 | var $el = $(e.currentTarget), |
| 214 | $set = $el.find('a._select'), |
| 215 | $unset = $el.find('a._remove'), |
| 216 | type = $el.find('input._mi-type').val(), |
| 217 | icon = $el.find('input._mi-icon').val(), |
| 218 | url = $el.find('input._mi-url').val(), |
| 219 | template; |
| 220 | |
| 221 | if (type === '' || icon === '' || _.indexOf(menuIcons.activeTypes, type) < 0) { |
| 222 | $set.text(menuIcons.text.select).attr('title', ''); |
| 223 | $unset.addClass('hidden'); |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | if (miPicker.templates[type]) { |
| 228 | template = miPicker.templates[type]; |
| 229 | } else { |
| 230 | template = miPicker.templates[type] = wp.template('menu-icons-item-field-preview-' + iconPicker.types[type].templateId); |
| 231 | } |
| 232 | |
| 233 | $unset.removeClass('hidden'); |
| 234 | $set.attr('title', menuIcons.text.change); |
| 235 | $set.html(template({ |
| 236 | type: type, |
| 237 | icon: icon, |
| 238 | url: url |
| 239 | })); |
| 240 | }, |
| 241 | |
| 242 | /** |
| 243 | * Initialize picker functionality |
| 244 | * |
| 245 | * #fires mi:update |
| 246 | */ |
| 247 | init: function () { |
| 248 | miPicker.createFrame(); |
| 249 | $(document).on('click', miPicker.wrapClass, miPicker.setUnset).on('mi:update', miPicker.wrapClass, miPicker.updateField); // Trigger 'mi:update' event to generate the icons on the item fields. |
| 250 | |
| 251 | $(miPicker.wrapClass).trigger('mi:update'); |
| 252 | } |
| 253 | }; |
| 254 | miPicker.init(); |
| 255 | })(jQuery); |
| 256 | |
| 257 | /***/ }), |
| 258 | /* 1 */ |
| 259 | /***/ (function(module, exports) { |
| 260 | |
| 261 | (function ($) { |
| 262 | /** |
| 263 | * Settings box tabs |
| 264 | * |
| 265 | * We can't use core's tabs script here because it will clear the |
| 266 | * checkboxes upon tab switching |
| 267 | */ |
| 268 | $('#menu-icons-settings-tabs').on('click', 'a.mi-settings-nav-tab', function (e) { |
| 269 | var $el = $(this).blur(), |
| 270 | $target = $('#' + $el.data('type')); |
| 271 | e.preventDefault(); |
| 272 | e.stopPropagation(); |
| 273 | $el.parent().addClass('tabs').siblings().removeClass('tabs'); |
| 274 | $target.removeClass('tabs-panel-inactive').addClass('tabs-panel-active').show().siblings('div.tabs-panel').hide().addClass('tabs-panel-inactive').removeClass('tabs-panel-active'); |
| 275 | }).find('a.mi-settings-nav-tab').first().click(); // Settings meta box |
| 276 | |
| 277 | $('#menu-icons-settings-save').on('click', function (e) { |
| 278 | var $button = $(this).prop('disabled', true), |
| 279 | $spinner = $button.siblings('span.spinner'); |
| 280 | e.preventDefault(); |
| 281 | e.stopPropagation(); |
| 282 | $spinner.css({ |
| 283 | display: 'inline-block', |
| 284 | visibility: 'visible' |
| 285 | }); |
| 286 | $.ajax({ |
| 287 | type: 'POST', |
| 288 | url: window.menuIcons.ajaxUrls.update, |
| 289 | data: $('#menu-icons-settings :input').serialize(), |
| 290 | success: function (response) { |
| 291 | if (response.success && response.data.redirectUrl === true) { |
| 292 | window.location = response.data.redirectUrl; |
| 293 | } else { |
| 294 | $button.prop('disabled', false); |
| 295 | } |
| 296 | |
| 297 | $spinner.hide(); |
| 298 | }, |
| 299 | fail: function () { |
| 300 | $spinner.hide(); |
| 301 | } |
| 302 | }); |
| 303 | }); |
| 304 | })(jQuery); |
| 305 | |
| 306 | /***/ }), |
| 307 | /* 2 */ |
| 308 | /***/ (function(module, exports, __webpack_require__) { |
| 309 | |
| 310 | __webpack_require__(1); |
| 311 | |
| 312 | __webpack_require__(0); |
| 313 | |
| 314 | /***/ }), |
| 315 | /* 3 */ |
| 316 | /***/ (function(module, exports, __webpack_require__) { |
| 317 | |
| 318 | wp.media.model.MenuIconsItemSettingField = __webpack_require__(4); |
| 319 | wp.media.model.MenuIconsItemSettings = __webpack_require__(5); |
| 320 | wp.media.model.MenuIconsItem = __webpack_require__(6); |
| 321 | wp.media.view.MenuIconsItemSettingField = __webpack_require__(9); |
| 322 | wp.media.view.MenuIconsItemSettings = __webpack_require__(10); |
| 323 | wp.media.view.MenuIconsItemPreview = __webpack_require__(8); |
| 324 | wp.media.view.MenuIconsSidebar = __webpack_require__(11); |
| 325 | wp.media.view.MediaFrame.MenuIcons = __webpack_require__(7); |
| 326 | |
| 327 | /***/ }), |
| 328 | /* 4 */ |
| 329 | /***/ (function(module, exports) { |
| 330 | |
| 331 | /** |
| 332 | * wp.media.model.MenuIconsItemSettingField |
| 333 | * |
| 334 | * @class |
| 335 | * @augments Backbone.Model |
| 336 | */ |
| 337 | var MenuIconsItemSettingField = Backbone.Model.extend({ |
| 338 | defaults: { |
| 339 | id: '', |
| 340 | label: '', |
| 341 | value: '', |
| 342 | type: 'text' |
| 343 | } |
| 344 | }); |
| 345 | module.exports = MenuIconsItemSettingField; |
| 346 | |
| 347 | /***/ }), |
| 348 | /* 5 */ |
| 349 | /***/ (function(module, exports) { |
| 350 | |
| 351 | /** |
| 352 | * wp.media.model.MenuIconsItemSettings |
| 353 | * |
| 354 | * @class |
| 355 | * @augments Backbone.Collection |
| 356 | */ |
| 357 | var MenuIconsItemSettings = Backbone.Collection.extend({ |
| 358 | model: wp.media.model.MenuIconsItemSettingField |
| 359 | }); |
| 360 | module.exports = MenuIconsItemSettings; |
| 361 | |
| 362 | /***/ }), |
| 363 | /* 6 */ |
| 364 | /***/ (function(module, exports) { |
| 365 | |
| 366 | /** |
| 367 | * wp.media.model.MenuIconsItem |
| 368 | * |
| 369 | * @class |
| 370 | * @augments Backbone.Model |
| 371 | */ |
| 372 | var Item = Backbone.Model.extend({ |
| 373 | initialize: function () { |
| 374 | this.on('change', this.updateValues, this); |
| 375 | }, |
| 376 | |
| 377 | /** |
| 378 | * Update the values of menu item's settings fields |
| 379 | * |
| 380 | * #fires mi:update |
| 381 | */ |
| 382 | updateValues: function () { |
| 383 | _.each(this.get('$inputs'), function ($input, key) { |
| 384 | $input.val(this.get(key)); |
| 385 | }, this); // Trigger the 'mi:update' event to regenerate the icon on the field. |
| 386 | |
| 387 | |
| 388 | this.get('$el').trigger('mi:update'); |
| 389 | } |
| 390 | }); |
| 391 | module.exports = Item; |
| 392 | |
| 393 | /***/ }), |
| 394 | /* 7 */ |
| 395 | /***/ (function(module, exports) { |
| 396 | |
| 397 | /** |
| 398 | * wp.media.view.MediaFrame.MenuIcons |
| 399 | * |
| 400 | * @class |
| 401 | * @augments wp.media.view.MediaFrame.IconPicker |
| 402 | * @augments wp.media.view.MediaFrame.Select |
| 403 | * @augments wp.media.view.MediaFrame |
| 404 | * @augments wp.media.view.Frame |
| 405 | * @augments wp.media.View |
| 406 | * @augments wp.Backbone.View |
| 407 | * @augments Backbone.View |
| 408 | */ |
| 409 | var MenuIcons = wp.media.view.MediaFrame.IconPicker.extend({ |
| 410 | initialize: function () { |
| 411 | this.menuItems = new Backbone.Collection([], { |
| 412 | model: wp.media.model.MenuIconsItem |
| 413 | }); |
| 414 | wp.media.view.MediaFrame.IconPicker.prototype.initialize.apply(this, arguments); |
| 415 | |
| 416 | if (this.setMenuTabPanelAriaAttributes) { |
| 417 | this.off('open', this.setMenuTabPanelAriaAttributes, this); // Set the router ARIA tab panel attributes when the modal opens. |
| 418 | |
| 419 | this.off('open', this.setRouterTabPanelAriaAttributes, this); // Update the menu ARIA tab panel attributes when the content updates. |
| 420 | |
| 421 | this.off('content:render', this.setMenuTabPanelAriaAttributes, this); // Update the router ARIA tab panel attributes when the content updates. |
| 422 | |
| 423 | this.off('content:render', this.setRouterTabPanelAriaAttributes, this); |
| 424 | } |
| 425 | |
| 426 | this.listenTo(this.target, 'change', this.miUpdateItemProps); |
| 427 | this.on('select', this.miClearTarget, this); |
| 428 | }, |
| 429 | miUpdateItemProps: function (props) { |
| 430 | var model = this.menuItems.get(props.id); |
| 431 | model.set(props.changed); |
| 432 | }, |
| 433 | miClearTarget: function () { |
| 434 | this.target.clear({ |
| 435 | silent: true |
| 436 | }); |
| 437 | } |
| 438 | }); |
| 439 | module.exports = MenuIcons; |
| 440 | |
| 441 | /***/ }), |
| 442 | /* 8 */ |
| 443 | /***/ (function(module, exports) { |
| 444 | |
| 445 | /** |
| 446 | * wp.media.view.MenuIconsItemPreview |
| 447 | * |
| 448 | * @class |
| 449 | * @augments wp.media.View |
| 450 | * @augments wp.Backbone.View |
| 451 | * @augments Backbone.View |
| 452 | */ |
| 453 | var MenuIconsItemPreview = wp.media.View.extend({ |
| 454 | tagName: 'p', |
| 455 | className: 'mi-preview menu-item attachment-info', |
| 456 | events: { |
| 457 | 'click a': 'preventDefault' |
| 458 | }, |
| 459 | initialize: function () { |
| 460 | wp.media.View.prototype.initialize.apply(this, arguments); |
| 461 | this.model.on('change', this.render, this); |
| 462 | }, |
| 463 | render: function () { |
| 464 | var frame = this.controller, |
| 465 | state = frame.state(), |
| 466 | selected = state.get('selection').single(), |
| 467 | props = this.model.toJSON(), |
| 468 | data = _.extend(props, { |
| 469 | type: state.id, |
| 470 | icon: selected.id, |
| 471 | title: this.model.get('$title').val(), |
| 472 | url: state.ipGetIconUrl(selected, props.image_size) |
| 473 | }), |
| 474 | template = 'menu-icons-item-sidebar-preview-' + iconPicker.types[state.id].templateId + '-'; |
| 475 | |
| 476 | if (data.hide_label) { |
| 477 | template += 'hide_label'; |
| 478 | } else { |
| 479 | template += data.position; |
| 480 | } |
| 481 | |
| 482 | this.template = wp.media.template(template); |
| 483 | this.$el.html(this.template(data)); |
| 484 | return this; |
| 485 | }, |
| 486 | preventDefault: function (e) { |
| 487 | e.preventDefault(); |
| 488 | } |
| 489 | }); |
| 490 | module.exports = MenuIconsItemPreview; |
| 491 | |
| 492 | /***/ }), |
| 493 | /* 9 */ |
| 494 | /***/ (function(module, exports) { |
| 495 | |
| 496 | var $ = jQuery, |
| 497 | MenuIconsItemSettingField; |
| 498 | /** |
| 499 | * wp.media.view.MenuIconsItemSettingField |
| 500 | * |
| 501 | * @class |
| 502 | * @augments wp.media.View |
| 503 | * @augments wp.Backbone.View |
| 504 | * @augments Backbone.View |
| 505 | */ |
| 506 | |
| 507 | MenuIconsItemSettingField = wp.media.View.extend({ |
| 508 | tagName: 'label', |
| 509 | className: 'setting', |
| 510 | events: { |
| 511 | 'change :input': '_update' |
| 512 | }, |
| 513 | initialize: function () { |
| 514 | wp.media.View.prototype.initialize.apply(this, arguments); |
| 515 | this.template = wp.media.template('menu-icons-settings-field-' + this.model.get('type')); |
| 516 | this.model.on('change', this.render, this); |
| 517 | }, |
| 518 | prepare: function () { |
| 519 | return this.model.toJSON(); |
| 520 | }, |
| 521 | _update: function (e) { |
| 522 | var value = $(e.currentTarget).val(); |
| 523 | this.model.set('value', value); |
| 524 | this.options.item.set(this.model.id, value); |
| 525 | } |
| 526 | }); |
| 527 | module.exports = MenuIconsItemSettingField; |
| 528 | |
| 529 | /***/ }), |
| 530 | /* 10 */ |
| 531 | /***/ (function(module, exports) { |
| 532 | |
| 533 | /** |
| 534 | * wp.media.view.MenuIconsItemSettings |
| 535 | * |
| 536 | * @class |
| 537 | * @augments wp.media.view.PriorityList |
| 538 | * @augments wp.media.View |
| 539 | * @augments wp.Backbone.View |
| 540 | * @augments Backbone.View |
| 541 | */ |
| 542 | var MenuIconsItemSettings = wp.media.view.PriorityList.extend({ |
| 543 | className: 'mi-settings attachment-info', |
| 544 | prepare: function () { |
| 545 | _.each(this.collection.map(this.createField, this), function (view) { |
| 546 | this.set(view.model.id, view); |
| 547 | }, this); |
| 548 | }, |
| 549 | createField: function (model) { |
| 550 | var field = new wp.media.view.MenuIconsItemSettingField({ |
| 551 | item: this.model, |
| 552 | model: model, |
| 553 | collection: this.collection |
| 554 | }); |
| 555 | return field; |
| 556 | } |
| 557 | }); |
| 558 | module.exports = MenuIconsItemSettings; |
| 559 | |
| 560 | /***/ }), |
| 561 | /* 11 */ |
| 562 | /***/ (function(module, exports) { |
| 563 | |
| 564 | /** |
| 565 | * wp.media.view.MenuIconsSidebar |
| 566 | * |
| 567 | * @class |
| 568 | * @augments wp.media.view.IconPickerSidebar |
| 569 | * @augments wp.media.view.Sidebar |
| 570 | * @augments wp.media.view.PriorityList |
| 571 | * @augments wp.media.View |
| 572 | * @augments wp.Backbone.View |
| 573 | * @augments Backbone.View |
| 574 | */ |
| 575 | var MenuIconsSidebar = wp.media.view.IconPickerSidebar.extend({ |
| 576 | initialize: function () { |
| 577 | var title = new wp.media.View({ |
| 578 | tagName: 'h3', |
| 579 | priority: -10 |
| 580 | }); |
| 581 | var info = new wp.media.View({ |
| 582 | tagName: 'p', |
| 583 | className: '_info', |
| 584 | priority: 1000 |
| 585 | }); |
| 586 | wp.media.view.IconPickerSidebar.prototype.initialize.apply(this, arguments); |
| 587 | title.$el.text(window.menuIcons.text.preview); |
| 588 | this.set('title', title); |
| 589 | info.$el.html(window.menuIcons.text.settingsInfo); |
| 590 | this.set('info', info); |
| 591 | }, |
| 592 | createSingle: function () { |
| 593 | this.createPreview(); |
| 594 | this.createSettings(); |
| 595 | }, |
| 596 | disposeSingle: function () { |
| 597 | this.unset('preview'); |
| 598 | this.unset('settings'); |
| 599 | }, |
| 600 | createPreview: function () { |
| 601 | var self = this, |
| 602 | frame = self.controller, |
| 603 | state = frame.state(); // If the selected icon is still being downloaded (image or svg type), |
| 604 | // wait for it to complete before creating the preview. |
| 605 | |
| 606 | if (state.dfd && state.dfd.state() === 'pending') { |
| 607 | state.dfd.done(function () { |
| 608 | self.createPreview(); |
| 609 | }); |
| 610 | return; |
| 611 | } |
| 612 | |
| 613 | self.set('preview', new wp.media.view.MenuIconsItemPreview({ |
| 614 | controller: frame, |
| 615 | model: frame.target, |
| 616 | priority: 80 |
| 617 | })); |
| 618 | }, |
| 619 | createSettings: function () { |
| 620 | var frame = this.controller, |
| 621 | state = frame.state(), |
| 622 | fieldIds = state.get('data').settingsFields, |
| 623 | fields = []; |
| 624 | |
| 625 | _.each(fieldIds, function (fieldId) { |
| 626 | var field = window.menuIcons.settingsFields[fieldId], |
| 627 | model; |
| 628 | |
| 629 | if (!field) { |
| 630 | return; |
| 631 | } |
| 632 | |
| 633 | model = _.defaults({ |
| 634 | value: frame.target.get(fieldId) || field['default'] |
| 635 | }, field); |
| 636 | fields.push(model); |
| 637 | }); |
| 638 | |
| 639 | if (!fields.length) { |
| 640 | return; |
| 641 | } |
| 642 | |
| 643 | this.set('settings', new wp.media.view.MenuIconsItemSettings({ |
| 644 | controller: this.controller, |
| 645 | collection: new wp.media.model.MenuIconsItemSettings(fields), |
| 646 | model: frame.target, |
| 647 | type: this.options.type, |
| 648 | priority: 120 |
| 649 | })); |
| 650 | } |
| 651 | }); |
| 652 | module.exports = MenuIconsSidebar; |
| 653 | |
| 654 | /***/ }) |
| 655 | /******/ ]); |