admin.js
689 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 = 11); |
| 67 | /******/ }) |
| 68 | /************************************************************************/ |
| 69 | /******/ ([ |
| 70 | /* 0 */ |
| 71 | /***/ (function(module, exports, __webpack_require__) { |
| 72 | |
| 73 | /* global menuIcons:false */ |
| 74 | |
| 75 | __webpack_require__(2); |
| 76 | |
| 77 | (function ($) { |
| 78 | var miPicker; |
| 79 | |
| 80 | if (!menuIcons.activeTypes || _.isEmpty(menuIcons.activeTypes)) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @namespace |
| 86 | * @property {object} templates - Cached templates for the item previews on the fields |
| 87 | * @property {string} wrapClass - Field wrapper's class |
| 88 | * @property {object} frame - Menu Icons' media frame instance |
| 89 | * @property {object} target - Frame's target model |
| 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 typesFilter(type) { |
| 105 | return $.inArray(type.id, menuIcons.activeTypes) >= 0; |
| 106 | }, |
| 107 | |
| 108 | /** |
| 109 | * Create Menu Icons' media frame |
| 110 | */ |
| 111 | createFrame: function createFrame() { |
| 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 pickIcon(model) { |
| 125 | miPicker.frame.target.set(model, { silent: true }); |
| 126 | miPicker.frame.open(); |
| 127 | }, |
| 128 | |
| 129 | /** |
| 130 | * Set or unset icon |
| 131 | * |
| 132 | * @param {object} e - jQuery click event. |
| 133 | */ |
| 134 | setUnset: function setUnset(e) { |
| 135 | var $el = $(e.currentTarget), |
| 136 | $clicked = $(e.target); |
| 137 | |
| 138 | e.preventDefault(); |
| 139 | |
| 140 | if ($clicked.hasClass('_select') || $clicked.hasClass('_icon')) { |
| 141 | miPicker.setIcon($el); |
| 142 | } else if ($clicked.hasClass('_remove')) { |
| 143 | miPicker.unsetIcon($el); |
| 144 | } |
| 145 | }, |
| 146 | |
| 147 | /** |
| 148 | * Set Icon |
| 149 | * |
| 150 | * @param {object} $el - jQuery object. |
| 151 | */ |
| 152 | setIcon: function setIcon($el) { |
| 153 | var id = $el.data('id'), |
| 154 | frame = miPicker.frame, |
| 155 | items = frame.menuItems, |
| 156 | model = items.get(id); |
| 157 | |
| 158 | if (model) { |
| 159 | miPicker.pickIcon(model.toJSON()); |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | model = { |
| 164 | id: id, |
| 165 | $el: $el, |
| 166 | $title: $('#edit-menu-item-title-' + id), |
| 167 | $inputs: {} |
| 168 | }; |
| 169 | |
| 170 | // Collect menu item's settings fields and use them |
| 171 | // as the model's attributes. |
| 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 | |
| 189 | items.add(model); |
| 190 | miPicker.pickIcon(model); |
| 191 | }, |
| 192 | |
| 193 | /** |
| 194 | * Unset icon |
| 195 | * |
| 196 | * @param {object} $el - jQuery object. |
| 197 | */ |
| 198 | unsetIcon: function unsetIcon($el) { |
| 199 | var id = $el.data('id'); |
| 200 | |
| 201 | $el.find('div._settings input').val(''); |
| 202 | $el.trigger('mi:update'); |
| 203 | miPicker.frame.menuItems.remove(id); |
| 204 | }, |
| 205 | |
| 206 | /** |
| 207 | * Update valeus of menu item's setting fields |
| 208 | * |
| 209 | * When the type and icon is set, this will (re)generate the icon |
| 210 | * preview on the menu item field. |
| 211 | * |
| 212 | * @param {object} e - jQuery event. |
| 213 | */ |
| 214 | updateField: function updateField(e) { |
| 215 | var $el = $(e.currentTarget), |
| 216 | $set = $el.find('a._select'), |
| 217 | $unset = $el.find('a._remove'), |
| 218 | type = $el.find('input._mi-type').val(), |
| 219 | icon = $el.find('input._mi-icon').val(), |
| 220 | url = $el.find('input._mi-url').val(), |
| 221 | template; |
| 222 | |
| 223 | if (type === '' || icon === '' || _.indexOf(menuIcons.activeTypes, type) < 0) { |
| 224 | $set.text(menuIcons.text.select).attr('title', ''); |
| 225 | $unset.addClass('hidden'); |
| 226 | |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | if (miPicker.templates[type]) { |
| 231 | template = miPicker.templates[type]; |
| 232 | } else { |
| 233 | template = miPicker.templates[type] = wp.template('menu-icons-item-field-preview-' + iconPicker.types[type].templateId); |
| 234 | } |
| 235 | |
| 236 | $unset.removeClass('hidden'); |
| 237 | $set.attr('title', menuIcons.text.change); |
| 238 | $set.html(template({ |
| 239 | type: type, |
| 240 | icon: icon, |
| 241 | url: url |
| 242 | })); |
| 243 | }, |
| 244 | |
| 245 | /** |
| 246 | * Initialize picker functionality |
| 247 | * |
| 248 | * #fires mi:update |
| 249 | */ |
| 250 | init: function init() { |
| 251 | miPicker.createFrame(); |
| 252 | $(document).on('click', miPicker.wrapClass, miPicker.setUnset).on('mi:update', miPicker.wrapClass, miPicker.updateField); |
| 253 | |
| 254 | // Trigger 'mi:update' event to generate the icons on the item fields. |
| 255 | $(miPicker.wrapClass).trigger('mi:update'); |
| 256 | } |
| 257 | }; |
| 258 | |
| 259 | miPicker.init(); |
| 260 | })(jQuery); |
| 261 | |
| 262 | /***/ }), |
| 263 | /* 1 */ |
| 264 | /***/ (function(module, exports) { |
| 265 | |
| 266 | (function ($) { |
| 267 | /** |
| 268 | * Settings box tabs |
| 269 | * |
| 270 | * We can't use core's tabs script here because it will clear the |
| 271 | * checkboxes upon tab switching |
| 272 | */ |
| 273 | $('#menu-icons-settings-tabs').on('click', 'a.mi-settings-nav-tab', function (e) { |
| 274 | var $el = $(this).blur(), |
| 275 | $target = $('#' + $el.data('type')); |
| 276 | |
| 277 | e.preventDefault(); |
| 278 | e.stopPropagation(); |
| 279 | |
| 280 | $el.parent().addClass('tabs').siblings().removeClass('tabs'); |
| 281 | $target.removeClass('tabs-panel-inactive').addClass('tabs-panel-active').show().siblings('div.tabs-panel').hide().addClass('tabs-panel-inactive').removeClass('tabs-panel-active'); |
| 282 | }).find('a.mi-settings-nav-tab').first().click(); |
| 283 | |
| 284 | // Settings meta box |
| 285 | $('#menu-icons-settings-save').on('click', function (e) { |
| 286 | var $button = $(this).prop('disabled', true), |
| 287 | $spinner = $button.siblings('span.spinner'); |
| 288 | |
| 289 | e.preventDefault(); |
| 290 | e.stopPropagation(); |
| 291 | |
| 292 | $spinner.css({ |
| 293 | display: 'inline-block', |
| 294 | visibility: 'visible' |
| 295 | }); |
| 296 | |
| 297 | $.ajax({ |
| 298 | type: 'POST', |
| 299 | url: window.menuIcons.ajaxUrls.update, |
| 300 | data: $('#menu-icons-settings :input').serialize(), |
| 301 | |
| 302 | success: function success(response) { |
| 303 | if (response.success && response.data.redirectUrl === true) { |
| 304 | window.location = response.data.redirectUrl; |
| 305 | } else { |
| 306 | $button.prop('disabled', false); |
| 307 | } |
| 308 | }, |
| 309 | |
| 310 | always: function always() { |
| 311 | $spinner.hide(); |
| 312 | } |
| 313 | }); |
| 314 | }); |
| 315 | })(jQuery); |
| 316 | |
| 317 | /***/ }), |
| 318 | /* 2 */ |
| 319 | /***/ (function(module, exports, __webpack_require__) { |
| 320 | |
| 321 | wp.media.model.MenuIconsItemSettingField = __webpack_require__(3); |
| 322 | wp.media.model.MenuIconsItemSettings = __webpack_require__(4); |
| 323 | wp.media.model.MenuIconsItem = __webpack_require__(5); |
| 324 | |
| 325 | wp.media.view.MenuIconsItemSettingField = __webpack_require__(8); |
| 326 | wp.media.view.MenuIconsItemSettings = __webpack_require__(9); |
| 327 | wp.media.view.MenuIconsItemPreview = __webpack_require__(7); |
| 328 | wp.media.view.MenuIconsSidebar = __webpack_require__(10); |
| 329 | wp.media.view.MediaFrame.MenuIcons = __webpack_require__(6); |
| 330 | |
| 331 | /***/ }), |
| 332 | /* 3 */ |
| 333 | /***/ (function(module, exports) { |
| 334 | |
| 335 | /** |
| 336 | * wp.media.model.MenuIconsItemSettingField |
| 337 | * |
| 338 | * @class |
| 339 | * @augments Backbone.Model |
| 340 | */ |
| 341 | var MenuIconsItemSettingField = Backbone.Model.extend({ |
| 342 | defaults: { |
| 343 | id: '', |
| 344 | label: '', |
| 345 | value: '', |
| 346 | type: 'text' |
| 347 | } |
| 348 | }); |
| 349 | |
| 350 | module.exports = MenuIconsItemSettingField; |
| 351 | |
| 352 | /***/ }), |
| 353 | /* 4 */ |
| 354 | /***/ (function(module, exports) { |
| 355 | |
| 356 | /** |
| 357 | * wp.media.model.MenuIconsItemSettings |
| 358 | * |
| 359 | * @class |
| 360 | * @augments Backbone.Collection |
| 361 | */ |
| 362 | var MenuIconsItemSettings = Backbone.Collection.extend({ |
| 363 | model: wp.media.model.MenuIconsItemSettingField |
| 364 | }); |
| 365 | |
| 366 | module.exports = MenuIconsItemSettings; |
| 367 | |
| 368 | /***/ }), |
| 369 | /* 5 */ |
| 370 | /***/ (function(module, exports) { |
| 371 | |
| 372 | /** |
| 373 | * wp.media.model.MenuIconsItem |
| 374 | * |
| 375 | * @class |
| 376 | * @augments Backbone.Model |
| 377 | */ |
| 378 | var Item = Backbone.Model.extend({ |
| 379 | initialize: function initialize() { |
| 380 | this.on('change', this.updateValues, this); |
| 381 | }, |
| 382 | |
| 383 | /** |
| 384 | * Update the values of menu item's settings fields |
| 385 | * |
| 386 | * #fires mi:update |
| 387 | */ |
| 388 | updateValues: function updateValues() { |
| 389 | _.each(this.get('$inputs'), function ($input, key) { |
| 390 | $input.val(this.get(key)); |
| 391 | }, this); |
| 392 | |
| 393 | // Trigger the 'mi:update' event to regenerate the icon on the field. |
| 394 | this.get('$el').trigger('mi:update'); |
| 395 | } |
| 396 | }); |
| 397 | |
| 398 | module.exports = Item; |
| 399 | |
| 400 | /***/ }), |
| 401 | /* 6 */ |
| 402 | /***/ (function(module, exports) { |
| 403 | |
| 404 | /** |
| 405 | * wp.media.view.MediaFrame.MenuIcons |
| 406 | * |
| 407 | * @class |
| 408 | * @augments wp.media.view.MediaFrame.IconPicker |
| 409 | * @augments wp.media.view.MediaFrame.Select |
| 410 | * @augments wp.media.view.MediaFrame |
| 411 | * @augments wp.media.view.Frame |
| 412 | * @augments wp.media.View |
| 413 | * @augments wp.Backbone.View |
| 414 | * @augments Backbone.View |
| 415 | */ |
| 416 | var MenuIcons = wp.media.view.MediaFrame.IconPicker.extend({ |
| 417 | initialize: function initialize() { |
| 418 | this.menuItems = new Backbone.Collection([], { |
| 419 | model: wp.media.model.MenuIconsItem |
| 420 | }); |
| 421 | |
| 422 | wp.media.view.MediaFrame.IconPicker.prototype.initialize.apply(this, arguments); |
| 423 | |
| 424 | this.listenTo(this.target, 'change', this.miUpdateItemProps); |
| 425 | this.on('select', this.miClearTarget, this); |
| 426 | }, |
| 427 | |
| 428 | miUpdateItemProps: function miUpdateItemProps(props) { |
| 429 | var model = this.menuItems.get(props.id); |
| 430 | |
| 431 | model.set(props.changed); |
| 432 | }, |
| 433 | |
| 434 | miClearTarget: function miClearTarget() { |
| 435 | this.target.clear({ silent: true }); |
| 436 | } |
| 437 | }); |
| 438 | |
| 439 | module.exports = MenuIcons; |
| 440 | |
| 441 | /***/ }), |
| 442 | /* 7 */ |
| 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 | |
| 460 | initialize: function initialize() { |
| 461 | wp.media.View.prototype.initialize.apply(this, arguments); |
| 462 | this.model.on('change', this.render, this); |
| 463 | }, |
| 464 | |
| 465 | render: function render() { |
| 466 | var frame = this.controller, |
| 467 | state = frame.state(), |
| 468 | selected = state.get('selection').single(), |
| 469 | props = this.model.toJSON(), |
| 470 | data = _.extend(props, { |
| 471 | type: state.id, |
| 472 | icon: selected.id, |
| 473 | title: this.model.get('$title').val(), |
| 474 | url: state.ipGetIconUrl(selected, props.image_size) |
| 475 | }), |
| 476 | template = 'menu-icons-item-sidebar-preview-' + iconPicker.types[state.id].templateId + '-'; |
| 477 | |
| 478 | if (data.hide_label) { |
| 479 | template += 'hide_label'; |
| 480 | } else { |
| 481 | template += data.position; |
| 482 | } |
| 483 | |
| 484 | this.template = wp.media.template(template); |
| 485 | this.$el.html(this.template(data)); |
| 486 | |
| 487 | return this; |
| 488 | }, |
| 489 | |
| 490 | preventDefault: function preventDefault(e) { |
| 491 | e.preventDefault(); |
| 492 | } |
| 493 | }); |
| 494 | |
| 495 | module.exports = MenuIconsItemPreview; |
| 496 | |
| 497 | /***/ }), |
| 498 | /* 8 */ |
| 499 | /***/ (function(module, exports) { |
| 500 | |
| 501 | var $ = jQuery, |
| 502 | MenuIconsItemSettingField; |
| 503 | |
| 504 | /** |
| 505 | * wp.media.view.MenuIconsItemSettingField |
| 506 | * |
| 507 | * @class |
| 508 | * @augments wp.media.View |
| 509 | * @augments wp.Backbone.View |
| 510 | * @augments Backbone.View |
| 511 | */ |
| 512 | MenuIconsItemSettingField = wp.media.View.extend({ |
| 513 | tagName: 'label', |
| 514 | className: 'setting', |
| 515 | events: { |
| 516 | 'change :input': '_update' |
| 517 | }, |
| 518 | |
| 519 | initialize: function initialize() { |
| 520 | wp.media.View.prototype.initialize.apply(this, arguments); |
| 521 | |
| 522 | this.template = wp.media.template('menu-icons-settings-field-' + this.model.get('type')); |
| 523 | this.model.on('change', this.render, this); |
| 524 | }, |
| 525 | |
| 526 | prepare: function prepare() { |
| 527 | return this.model.toJSON(); |
| 528 | }, |
| 529 | |
| 530 | _update: function _update(e) { |
| 531 | var value = $(e.currentTarget).val(); |
| 532 | |
| 533 | this.model.set('value', value); |
| 534 | this.options.item.set(this.model.id, value); |
| 535 | } |
| 536 | }); |
| 537 | |
| 538 | module.exports = MenuIconsItemSettingField; |
| 539 | |
| 540 | /***/ }), |
| 541 | /* 9 */ |
| 542 | /***/ (function(module, exports) { |
| 543 | |
| 544 | /** |
| 545 | * wp.media.view.MenuIconsItemSettings |
| 546 | * |
| 547 | * @class |
| 548 | * @augments wp.media.view.PriorityList |
| 549 | * @augments wp.media.View |
| 550 | * @augments wp.Backbone.View |
| 551 | * @augments Backbone.View |
| 552 | */ |
| 553 | var MenuIconsItemSettings = wp.media.view.PriorityList.extend({ |
| 554 | className: 'mi-settings attachment-info', |
| 555 | |
| 556 | prepare: function prepare() { |
| 557 | _.each(this.collection.map(this.createField, this), function (view) { |
| 558 | this.set(view.model.id, view); |
| 559 | }, this); |
| 560 | }, |
| 561 | |
| 562 | createField: function createField(model) { |
| 563 | var field = new wp.media.view.MenuIconsItemSettingField({ |
| 564 | item: this.model, |
| 565 | model: model, |
| 566 | collection: this.collection |
| 567 | }); |
| 568 | |
| 569 | return field; |
| 570 | } |
| 571 | }); |
| 572 | |
| 573 | module.exports = MenuIconsItemSettings; |
| 574 | |
| 575 | /***/ }), |
| 576 | /* 10 */ |
| 577 | /***/ (function(module, exports) { |
| 578 | |
| 579 | /** |
| 580 | * wp.media.view.MenuIconsSidebar |
| 581 | * |
| 582 | * @class |
| 583 | * @augments wp.media.view.IconPickerSidebar |
| 584 | * @augments wp.media.view.Sidebar |
| 585 | * @augments wp.media.view.PriorityList |
| 586 | * @augments wp.media.View |
| 587 | * @augments wp.Backbone.View |
| 588 | * @augments Backbone.View |
| 589 | */ |
| 590 | var MenuIconsSidebar = wp.media.view.IconPickerSidebar.extend({ |
| 591 | initialize: function initialize() { |
| 592 | var title = new wp.media.View({ |
| 593 | tagName: 'h3', |
| 594 | priority: -10 |
| 595 | }); |
| 596 | |
| 597 | var info = new wp.media.View({ |
| 598 | tagName: 'div', |
| 599 | className: '_info', |
| 600 | priority: 1000 |
| 601 | }); |
| 602 | |
| 603 | wp.media.view.IconPickerSidebar.prototype.initialize.apply(this, arguments); |
| 604 | |
| 605 | title.$el.text(window.menuIcons.text.preview); |
| 606 | this.set('title', title); |
| 607 | |
| 608 | info.$el.html(window.menuIcons.text.settingsInfo); |
| 609 | this.set('info', info); |
| 610 | }, |
| 611 | |
| 612 | createSingle: function createSingle() { |
| 613 | this.createPreview(); |
| 614 | this.createSettings(); |
| 615 | }, |
| 616 | |
| 617 | disposeSingle: function disposeSingle() { |
| 618 | this.unset('preview'); |
| 619 | this.unset('settings'); |
| 620 | }, |
| 621 | |
| 622 | createPreview: function createPreview() { |
| 623 | var self = this, |
| 624 | frame = self.controller, |
| 625 | state = frame.state(); |
| 626 | |
| 627 | // If the selected icon is still being downloaded (image or svg type), |
| 628 | // wait for it to complete before creating the preview. |
| 629 | if (state.dfd && state.dfd.state() === 'pending') { |
| 630 | state.dfd.done(function () { |
| 631 | self.createPreview(); |
| 632 | }); |
| 633 | |
| 634 | return; |
| 635 | } |
| 636 | |
| 637 | self.set('preview', new wp.media.view.MenuIconsItemPreview({ |
| 638 | controller: frame, |
| 639 | model: frame.target, |
| 640 | priority: 80 |
| 641 | })); |
| 642 | }, |
| 643 | |
| 644 | createSettings: function createSettings() { |
| 645 | var frame = this.controller, |
| 646 | state = frame.state(), |
| 647 | fieldIds = state.get('data').settingsFields, |
| 648 | fields = []; |
| 649 | |
| 650 | _.each(fieldIds, function (fieldId) { |
| 651 | var field = window.menuIcons.settingsFields[fieldId], |
| 652 | model; |
| 653 | |
| 654 | if (!field) { |
| 655 | return; |
| 656 | } |
| 657 | |
| 658 | model = _.defaults({ |
| 659 | value: frame.target.get(fieldId) || field['default'] |
| 660 | }, field); |
| 661 | |
| 662 | fields.push(model); |
| 663 | }); |
| 664 | |
| 665 | if (!fields.length) { |
| 666 | return; |
| 667 | } |
| 668 | |
| 669 | this.set('settings', new wp.media.view.MenuIconsItemSettings({ |
| 670 | controller: this.controller, |
| 671 | collection: new wp.media.model.MenuIconsItemSettings(fields), |
| 672 | model: frame.target, |
| 673 | type: this.options.type, |
| 674 | priority: 120 |
| 675 | })); |
| 676 | } |
| 677 | }); |
| 678 | |
| 679 | module.exports = MenuIconsSidebar; |
| 680 | |
| 681 | /***/ }), |
| 682 | /* 11 */ |
| 683 | /***/ (function(module, exports, __webpack_require__) { |
| 684 | |
| 685 | __webpack_require__(1); |
| 686 | __webpack_require__(0); |
| 687 | |
| 688 | /***/ }) |
| 689 | /******/ ]); |