api-keys.js
5 years ago
api-keys.min.js
2 years ago
backbone-modal.js
2 years ago
backbone-modal.min.js
2 years ago
marketplace-suggestions.js
10 months ago
marketplace-suggestions.min.js
10 months ago
meta-boxes-coupon.js
1 year ago
meta-boxes-coupon.min.js
1 year ago
meta-boxes-order.js
1 month ago
meta-boxes-order.min.js
1 month ago
meta-boxes-product-variation.js
1 year ago
meta-boxes-product-variation.min.js
1 year ago
meta-boxes-product.js
1 month ago
meta-boxes-product.min.js
1 month ago
meta-boxes.js
4 months ago
meta-boxes.min.js
4 months ago
network-orders.js
8 years ago
network-orders.min.js
2 years ago
order-attribution-admin.js
2 years ago
order-attribution-admin.min.js
2 years ago
product-editor.js
11 months ago
product-editor.min.js
11 months ago
product-ordering.js
3 months ago
product-ordering.min.js
3 months ago
quick-edit.js
1 year ago
quick-edit.min.js
1 year ago
reports.js
1 year ago
reports.min.js
1 year ago
settings-views-html-settings-tax.js
1 year ago
settings-views-html-settings-tax.min.js
1 year ago
settings.js
1 year ago
settings.min.js
1 year ago
system-status.js
3 months ago
system-status.min.js
3 months ago
term-ordering.js
3 months ago
term-ordering.min.js
3 months ago
users.js
5 years ago
users.min.js
2 years ago
variation-gallery.js
1 month ago
variation-gallery.min.js
1 month ago
wc-brands-enhanced-select.js
1 year ago
wc-brands-enhanced-select.min.js
1 year ago
wc-clipboard.js
5 years ago
wc-clipboard.min.js
5 years ago
wc-customer-stock-notifications.js
10 months ago
wc-customer-stock-notifications.min.js
10 months ago
wc-enhanced-select.js
2 years ago
wc-enhanced-select.min.js
2 years ago
wc-orders.js
3 years ago
wc-orders.min.js
2 years ago
wc-product-export.js
1 year ago
wc-product-export.min.js
1 year ago
wc-product-import.js
3 years ago
wc-product-import.min.js
2 years ago
wc-recent-reviews-widget-async.js
4 months ago
wc-recent-reviews-widget-async.min.js
4 months ago
wc-setup.js
5 years ago
wc-setup.min.js
2 years ago
wc-shipping-classes.js
1 year ago
wc-shipping-classes.min.js
1 year ago
wc-shipping-providers.js
3 months ago
wc-shipping-providers.min.js
3 months ago
wc-shipping-zone-methods.js
5 months ago
wc-shipping-zone-methods.min.js
5 months ago
wc-shipping-zones.js
1 year ago
wc-shipping-zones.min.js
1 year ago
wc-status-widget-async.js
4 months ago
wc-status-widget-async.min.js
4 months ago
wc-status-widget.js
1 year ago
wc-status-widget.min.js
1 year ago
woocommerce_admin.js
1 month ago
woocommerce_admin.min.js
1 month ago
backbone-modal.js
171 lines
| 1 | /*global jQuery, Backbone, _ */ |
| 2 | ( function( $, Backbone, _ ) { |
| 3 | 'use strict'; |
| 4 | |
| 5 | /** |
| 6 | * WooCommerce Backbone Modal plugin |
| 7 | * |
| 8 | * @param {object} options |
| 9 | */ |
| 10 | $.fn.WCBackboneModal = function( options ) { |
| 11 | return this.each( function() { |
| 12 | ( new $.WCBackboneModal( $( this ), options ) ); |
| 13 | }); |
| 14 | }; |
| 15 | |
| 16 | /** |
| 17 | * Initialize the Backbone Modal |
| 18 | * |
| 19 | * @param {object} element [description] |
| 20 | * @param {object} options [description] |
| 21 | */ |
| 22 | $.WCBackboneModal = function( element, options ) { |
| 23 | // Set settings |
| 24 | var settings = $.extend( {}, $.WCBackboneModal.defaultOptions, options ); |
| 25 | |
| 26 | if ( settings.template ) { |
| 27 | new $.WCBackboneModal.View({ |
| 28 | target: settings.template, |
| 29 | string: settings.variable |
| 30 | }); |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | /** |
| 35 | * Set default options |
| 36 | * |
| 37 | * @type {object} |
| 38 | */ |
| 39 | $.WCBackboneModal.defaultOptions = { |
| 40 | template: '', |
| 41 | variable: {} |
| 42 | }; |
| 43 | |
| 44 | /** |
| 45 | * Create the Backbone Modal |
| 46 | * |
| 47 | * @return {null} |
| 48 | */ |
| 49 | $.WCBackboneModal.View = Backbone.View.extend({ |
| 50 | tagName: 'div', |
| 51 | id: 'wc-backbone-modal-dialog', |
| 52 | _target: undefined, |
| 53 | _string: undefined, |
| 54 | events: { |
| 55 | 'click .modal-close': 'closeButton', |
| 56 | 'click #btn-ok' : 'addButton', |
| 57 | 'click #btn-back' : 'backButton', |
| 58 | 'click #btn-next' : 'nextButton', |
| 59 | 'touchstart #btn-ok': 'addButton', |
| 60 | 'keydown' : 'keyboardActions', |
| 61 | 'input' : 'handleInputValidation' |
| 62 | }, |
| 63 | resizeContent: function() { |
| 64 | var $content = $( '.wc-backbone-modal-content' ).find( 'article' ); |
| 65 | var max_h = $( window ).height() * 0.75; |
| 66 | |
| 67 | $content.css({ |
| 68 | 'max-height': max_h + 'px' |
| 69 | }); |
| 70 | }, |
| 71 | initialize: function( data ) { |
| 72 | var view = this; |
| 73 | this._target = data.target; |
| 74 | this._string = data.string; |
| 75 | _.bindAll( this, 'render' ); |
| 76 | this.render(); |
| 77 | |
| 78 | $( window ).on( 'resize', function() { |
| 79 | view.resizeContent(); |
| 80 | }); |
| 81 | }, |
| 82 | render: function() { |
| 83 | var template = wp.template( this._target ); |
| 84 | |
| 85 | this.$el.append( |
| 86 | template( this._string ) |
| 87 | ); |
| 88 | |
| 89 | $( document.body ).css({ |
| 90 | 'overflow': 'hidden' |
| 91 | }).append( this.$el ); |
| 92 | |
| 93 | this.resizeContent(); |
| 94 | this.$( '.wc-backbone-modal-content' ).attr( 'tabindex' , '0' ).trigger( 'focus' ); |
| 95 | |
| 96 | $( document.body ).trigger( 'init_tooltips' ); |
| 97 | |
| 98 | $( document.body ).trigger( 'wc_backbone_modal_loaded', this._target ); |
| 99 | }, |
| 100 | closeButton: function( e, addButtonCalled ) { |
| 101 | e.preventDefault(); |
| 102 | $( document.body ).trigger( 'wc_backbone_modal_before_remove', [ this._target, this.getFormData(), !!addButtonCalled ] ); |
| 103 | this.undelegateEvents(); |
| 104 | $( document ).off( 'focusin' ); |
| 105 | $( document.body ).css({ |
| 106 | 'overflow': 'auto' |
| 107 | }); |
| 108 | this.remove(); |
| 109 | $( document.body ).trigger( 'wc_backbone_modal_removed', this._target ); |
| 110 | }, |
| 111 | addButton: function( e ) { |
| 112 | $( document.body ).trigger( 'wc_backbone_modal_response', [ this._target, this.getFormData() ] ); |
| 113 | this.closeButton( e, true ); |
| 114 | }, |
| 115 | backButton: function( e ) { |
| 116 | $( document.body ).trigger( 'wc_backbone_modal_back_response', [ this._target, this.getFormData() ] ); |
| 117 | this.closeButton( e, false ); |
| 118 | }, |
| 119 | nextButton: function( e ) { |
| 120 | var context = this; |
| 121 | function closeModal() { |
| 122 | context.closeButton( e ); |
| 123 | } |
| 124 | $( document.body ).trigger( 'wc_backbone_modal_next_response', [ this._target, this.getFormData(), closeModal ] ); |
| 125 | }, |
| 126 | getFormData: function( updating = true ) { |
| 127 | var data = {}; |
| 128 | |
| 129 | if ( updating ) { |
| 130 | $( document.body ).trigger( 'wc_backbone_modal_before_update', this._target ); |
| 131 | } |
| 132 | |
| 133 | $.each( $( 'form', this.$el ).serializeArray(), function( index, item ) { |
| 134 | if ( item.name.indexOf( '[]' ) !== -1 ) { |
| 135 | item.name = item.name.replace( '[]', '' ); |
| 136 | data[ item.name ] = $.makeArray( data[ item.name ] ); |
| 137 | data[ item.name ].push( item.value ); |
| 138 | } else { |
| 139 | data[ item.name ] = item.value; |
| 140 | } |
| 141 | }); |
| 142 | |
| 143 | return data; |
| 144 | }, |
| 145 | handleInputValidation: function() { |
| 146 | $( document.body ).trigger( 'wc_backbone_modal_validation', [ this._target, this.getFormData( false ) ] ); |
| 147 | }, |
| 148 | keyboardActions: function( e ) { |
| 149 | var button = e.keyCode || e.which; |
| 150 | |
| 151 | // Enter key |
| 152 | if ( |
| 153 | 13 === button && |
| 154 | ! ( e.target.tagName && ( e.target.tagName.toLowerCase() === 'input' || e.target.tagName.toLowerCase() === 'textarea' ) ) |
| 155 | ) { |
| 156 | if ( $( '#btn-ok' ).length ) { |
| 157 | this.addButton( e ); |
| 158 | } else if ( $( '#btn-next' ).length ) { |
| 159 | this.nextButton( e ); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | // ESC key |
| 164 | if ( 27 === button ) { |
| 165 | this.closeButton( e ); |
| 166 | } |
| 167 | } |
| 168 | }); |
| 169 | |
| 170 | }( jQuery, Backbone, _ )); |
| 171 |