field-bar.js
2 months ago
field-settings.js
2 months ago
main-layout.js
2 months ago
metabox.js
2 months ago
sidebar-layout.js
2 months ago
metabox.js
50 lines
| 1 | import Backbone from 'backbone'; |
| 2 | import $ from 'jquery'; |
| 3 | |
| 4 | export default Backbone.View.extend({ |
| 5 | el: '#pp-form-builder-metabox', |
| 6 | |
| 7 | events: { |
| 8 | "click .pp_upload_button": "media_upload", |
| 9 | }, |
| 10 | |
| 11 | initialize() { |
| 12 | |
| 13 | new jBox('Tooltip', { |
| 14 | attach: '.pp-form-builder-help-tip', |
| 15 | maxWidth: 200, |
| 16 | theme: 'TooltipDark' |
| 17 | }); |
| 18 | |
| 19 | // Makes tooltip close to the color picker field |
| 20 | $('.form-field .wp-picker-container', this.$el).parent('.pp-field-row-content').css('width', 'auto'); |
| 21 | }, |
| 22 | |
| 23 | media_upload(e) { |
| 24 | |
| 25 | e.preventDefault(); |
| 26 | |
| 27 | let frame, _this = $(e.target); |
| 28 | |
| 29 | if (frame) { |
| 30 | frame.open(); |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | frame = wp.media.frames.file_frame = wp.media({ |
| 35 | frame: 'select', |
| 36 | multiple: false, |
| 37 | library: { |
| 38 | type: 'image' // limits the frame to show only images |
| 39 | }, |
| 40 | }); |
| 41 | |
| 42 | frame.on('select', function () { |
| 43 | let attachment = frame.state().get('selection').first().toJSON(); |
| 44 | _this.parents('.pp_upload_field_container').find('.pp_upload_field').val(attachment.url); |
| 45 | |
| 46 | }); |
| 47 | |
| 48 | frame.open(); |
| 49 | } |
| 50 | }); |