api-keys.js
5 years ago
api-keys.min.js
5 years ago
backbone-modal.js
5 years ago
backbone-modal.min.js
5 years ago
marketplace-suggestions.js
4 years ago
marketplace-suggestions.min.js
3 years ago
meta-boxes-coupon.js
5 years ago
meta-boxes-coupon.min.js
3 years ago
meta-boxes-order.js
3 years ago
meta-boxes-order.min.js
3 years ago
meta-boxes-product-variation.js
3 years ago
meta-boxes-product-variation.min.js
3 years ago
meta-boxes-product.js
3 years ago
meta-boxes-product.min.js
3 years ago
meta-boxes.js
3 years ago
meta-boxes.min.js
3 years ago
network-orders.js
8 years ago
network-orders.min.js
3 years ago
product-editor.js
3 years ago
product-editor.min.js
3 years ago
product-ordering.js
3 years ago
product-ordering.min.js
3 years ago
quick-edit.js
4 years ago
quick-edit.min.js
3 years ago
reports.js
5 years ago
reports.min.js
3 years ago
settings-views-html-settings-tax.js
5 years ago
settings-views-html-settings-tax.min.js
3 years ago
settings.js
4 years ago
settings.min.js
3 years ago
system-status.js
3 years ago
system-status.min.js
3 years ago
term-ordering.js
3 years ago
term-ordering.min.js
3 years ago
users.js
5 years ago
users.min.js
3 years ago
wc-clipboard.js
5 years ago
wc-clipboard.min.js
5 years ago
wc-enhanced-select.js
3 years ago
wc-enhanced-select.min.js
3 years ago
wc-orders.js
3 years ago
wc-orders.min.js
3 years ago
wc-product-export.js
5 years ago
wc-product-export.min.js
5 years ago
wc-product-import.js
3 years ago
wc-product-import.min.js
3 years ago
wc-setup.js
5 years ago
wc-setup.min.js
3 years ago
wc-shipping-classes.js
5 years ago
wc-shipping-classes.min.js
3 years ago
wc-shipping-zone-methods.js
4 years ago
wc-shipping-zone-methods.min.js
3 years ago
wc-shipping-zones.js
4 years ago
wc-shipping-zones.min.js
3 years ago
wc-status-widget.js
4 years ago
wc-status-widget.min.js
4 years ago
woocommerce_admin.js
3 years ago
woocommerce_admin.min.js
3 years ago
backbone-modal.js
148 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 | 'touchstart #btn-ok': 'addButton', |
| 58 | 'keydown' : 'keyboardActions' |
| 59 | }, |
| 60 | resizeContent: function() { |
| 61 | var $content = $( '.wc-backbone-modal-content' ).find( 'article' ); |
| 62 | var max_h = $( window ).height() * 0.75; |
| 63 | |
| 64 | $content.css({ |
| 65 | 'max-height': max_h + 'px' |
| 66 | }); |
| 67 | }, |
| 68 | initialize: function( data ) { |
| 69 | var view = this; |
| 70 | this._target = data.target; |
| 71 | this._string = data.string; |
| 72 | _.bindAll( this, 'render' ); |
| 73 | this.render(); |
| 74 | |
| 75 | $( window ).on( 'resize', function() { |
| 76 | view.resizeContent(); |
| 77 | }); |
| 78 | }, |
| 79 | render: function() { |
| 80 | var template = wp.template( this._target ); |
| 81 | |
| 82 | this.$el.append( |
| 83 | template( this._string ) |
| 84 | ); |
| 85 | |
| 86 | $( document.body ).css({ |
| 87 | 'overflow': 'hidden' |
| 88 | }).append( this.$el ); |
| 89 | |
| 90 | this.resizeContent(); |
| 91 | this.$( '.wc-backbone-modal-content' ).attr( 'tabindex' , '0' ).trigger( 'focus' ); |
| 92 | |
| 93 | $( document.body ).trigger( 'init_tooltips' ); |
| 94 | |
| 95 | $( document.body ).trigger( 'wc_backbone_modal_loaded', this._target ); |
| 96 | }, |
| 97 | closeButton: function( e ) { |
| 98 | e.preventDefault(); |
| 99 | $( document.body ).trigger( 'wc_backbone_modal_before_remove', this._target ); |
| 100 | this.undelegateEvents(); |
| 101 | $( document ).off( 'focusin' ); |
| 102 | $( document.body ).css({ |
| 103 | 'overflow': 'auto' |
| 104 | }); |
| 105 | this.remove(); |
| 106 | $( document.body ).trigger( 'wc_backbone_modal_removed', this._target ); |
| 107 | }, |
| 108 | addButton: function( e ) { |
| 109 | $( document.body ).trigger( 'wc_backbone_modal_response', [ this._target, this.getFormData() ] ); |
| 110 | this.closeButton( e ); |
| 111 | }, |
| 112 | getFormData: function() { |
| 113 | var data = {}; |
| 114 | |
| 115 | $( document.body ).trigger( 'wc_backbone_modal_before_update', this._target ); |
| 116 | |
| 117 | $.each( $( 'form', this.$el ).serializeArray(), function( index, item ) { |
| 118 | if ( item.name.indexOf( '[]' ) !== -1 ) { |
| 119 | item.name = item.name.replace( '[]', '' ); |
| 120 | data[ item.name ] = $.makeArray( data[ item.name ] ); |
| 121 | data[ item.name ].push( item.value ); |
| 122 | } else { |
| 123 | data[ item.name ] = item.value; |
| 124 | } |
| 125 | }); |
| 126 | |
| 127 | return data; |
| 128 | }, |
| 129 | keyboardActions: function( e ) { |
| 130 | var button = e.keyCode || e.which; |
| 131 | |
| 132 | // Enter key |
| 133 | if ( |
| 134 | 13 === button && |
| 135 | ! ( e.target.tagName && ( e.target.tagName.toLowerCase() === 'input' || e.target.tagName.toLowerCase() === 'textarea' ) ) |
| 136 | ) { |
| 137 | this.addButton( e ); |
| 138 | } |
| 139 | |
| 140 | // ESC key |
| 141 | if ( 27 === button ) { |
| 142 | this.closeButton( e ); |
| 143 | } |
| 144 | } |
| 145 | }); |
| 146 | |
| 147 | }( jQuery, Backbone, _ )); |
| 148 |