admin-currency-selector.js
1 year ago
admin-currency-selector.min.js
1 year ago
bacs-accounts-currencies.js
5 years ago
bacs-accounts-currencies.min.js
5 years ago
cart_widget.js
2 months ago
cart_widget.min.js
2 months ago
currency-switcher-settings.js
1 year ago
currency-switcher-settings.min.js
1 year ago
dialogs.js
5 years ago
dialogs.min.js
5 years ago
exchange-rates.js
3 years ago
exchange-rates.min.js
3 years ago
files.js
5 years ago
files.min.js
5 years ago
languages_notice.js
5 years ago
languages_notice.min.js
5 years ago
lock_fields.js
2 years ago
lock_fields.min.js
2 years ago
multi-currency.js
5 years ago
multi-currency.min.js
5 years ago
pointer.js
1 year ago
pointer.min.js
1 year ago
prices.js
5 years ago
prices.min.js
5 years ago
products-screen-option.js
5 years ago
products-screen-option.min.js
5 years ago
scripts.js
1 year ago
scripts.min.js
1 year ago
taxonomy_translation.js
1 year ago
taxonomy_translation.min.js
1 year ago
tooltip_init.js
5 years ago
tooltip_init.min.js
5 years ago
trnsl_interface_dialog_warning.js
5 years ago
trnsl_interface_dialog_warning.min.js
5 years ago
troubleshooting.js
1 year ago
troubleshooting.min.js
1 year ago
wcml-attributes.js
5 years ago
wcml-attributes.min.js
5 years ago
wcml-messages.js
5 years ago
wcml-messages.min.js
5 years ago
wcml-multi-currency.js
2 months ago
wcml-multi-currency.min.js
2 months ago
wcml-setup.js
3 years ago
wcml-setup.min.js
3 years ago
wcml-translation-editor.js
4 weeks ago
wcml-translation-editor.min.js
4 weeks ago
widgets.js
5 years ago
widgets.min.js
5 years ago
wpml_tm.js
5 years ago
wpml_tm.min.js
5 years ago
wcml-translation-editor.js
207 lines
| 1 | jQuery( function($){ |
| 2 | |
| 3 | var WCML_WPML_Translation_Editor = { |
| 4 | |
| 5 | is_wcml_product: false, |
| 6 | field_views: null, |
| 7 | footer_view: null, |
| 8 | save_buttons_tip: null, |
| 9 | |
| 10 | |
| 11 | init: function(){ |
| 12 | |
| 13 | $(document).on( 'WPML_TM.editor.before_render', WCML_WPML_Translation_Editor.do_editor_before_render ); |
| 14 | $(document).on( 'WPML_TM.editor.ready', WCML_WPML_Translation_Editor.do_editor_ready ); |
| 15 | |
| 16 | }, |
| 17 | |
| 18 | show_file_paths_button: function( event, view ) { |
| 19 | if ( view.field.field_type.substr( 0, 8 ) === 'file-url' ) { |
| 20 | view.$el.append( |
| 21 | '<div style="display: inline-block;width: 100%;">' + |
| 22 | '<button type="button" class="button-secondary wcml_file_paths_button" style="float: right;margin-right: 17px;">'+wcml_settings.strings.choose+'</button>' + |
| 23 | '</div>' ); |
| 24 | } |
| 25 | }, |
| 26 | |
| 27 | show_downloadable_files_frame: function( event ){ |
| 28 | var downloadable_file_frame; |
| 29 | var file_path_field; |
| 30 | var file_paths; |
| 31 | |
| 32 | var el = $(this); |
| 33 | |
| 34 | file_path_field = el.closest('.wpml-form-row').find('.translated_value'); |
| 35 | file_paths = file_path_field.val(); |
| 36 | |
| 37 | event.preventDefault(); |
| 38 | |
| 39 | // If the media frame already exists, reopen it. |
| 40 | if ( downloadable_file_frame ) { |
| 41 | downloadable_file_frame.open(); |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | var downloadable_file_states = [ |
| 46 | // Main states. |
| 47 | new wp.media.controller.Library({ |
| 48 | library: wp.media.query(), |
| 49 | multiple: true, |
| 50 | title: el.data('choose'), |
| 51 | priority: 20, |
| 52 | filterable: 'uploaded' |
| 53 | }) |
| 54 | ]; |
| 55 | |
| 56 | // Create the media frame. |
| 57 | downloadable_file_frame = wp.media.frames.downloadable_file = wp.media({ |
| 58 | // Set the title of the modal. |
| 59 | title: el.data('choose'), |
| 60 | library: { |
| 61 | type: '' |
| 62 | }, |
| 63 | button: { |
| 64 | text: el.data('update') |
| 65 | }, |
| 66 | multiple: true, |
| 67 | states: downloadable_file_states |
| 68 | }); |
| 69 | |
| 70 | // When an image is selected, run a callback. |
| 71 | downloadable_file_frame.on( 'select', function() { |
| 72 | |
| 73 | var selection = downloadable_file_frame.state().get('selection'); |
| 74 | |
| 75 | selection.map( function( attachment ) { |
| 76 | |
| 77 | attachment = attachment.toJSON(); |
| 78 | |
| 79 | if ( attachment.url ) |
| 80 | file_paths = attachment.url; |
| 81 | |
| 82 | } ); |
| 83 | |
| 84 | file_path_field.val( file_paths ); |
| 85 | }); |
| 86 | |
| 87 | // Set post to 0 and set our custom type |
| 88 | downloadable_file_frame.on( 'ready', function() { |
| 89 | downloadable_file_frame.uploader.options.uploader.params = { |
| 90 | type: 'downloadable_product' |
| 91 | }; |
| 92 | }); |
| 93 | |
| 94 | // Finally, open the modal. |
| 95 | downloadable_file_frame.open(); |
| 96 | }, |
| 97 | |
| 98 | update_slug: function(){ |
| 99 | |
| 100 | var title = $('#job_field_title .js-translated-value').val(); |
| 101 | var slug_field = $('#job_field_slug .js-translated-value'); |
| 102 | |
| 103 | if( title != '' && slug_field.val() == '' ){ |
| 104 | |
| 105 | var job_id = $('#icl_tm_editor input[name=job_id]').val(); |
| 106 | |
| 107 | slug_field.prop('readonly', 'on'); |
| 108 | $.ajax({ |
| 109 | url: ajaxurl, |
| 110 | type: 'POST', |
| 111 | dataType: 'json', |
| 112 | data: { action: 'wcml_editor_auto_slug', title: title, job_id: job_id, wcml_nonce: wcml_settings.nonce }, |
| 113 | success: function(response) { |
| 114 | slug_field.val( response.slug ); |
| 115 | slug_field.prop('readonly', false); |
| 116 | $('#icl_tm_copy_link_slug').prop('disabled', 'on'); |
| 117 | } |
| 118 | |
| 119 | }); |
| 120 | |
| 121 | } |
| 122 | |
| 123 | }, |
| 124 | |
| 125 | do_editor_before_render : function( event, job_type ) { |
| 126 | WCML_WPML_Translation_Editor.is_wcml_product = job_type === 'post_product'; |
| 127 | |
| 128 | if ( WCML_WPML_Translation_Editor.is_wcml_product ) { |
| 129 | $(document).on( 'WPML_TM.editor.field_view_ready', WCML_WPML_Translation_Editor.show_file_paths_button ); |
| 130 | $(document).on( 'WPML_TM.editor.field_update_ui', WCML_WPML_Translation_Editor.field_update_ui ); |
| 131 | $(document).on( 'click', '.wcml_file_paths_button', WCML_WPML_Translation_Editor.show_downloadable_files_frame ); |
| 132 | |
| 133 | $(document).on( 'blur', '#job_field_title .js-translated-value', WCML_WPML_Translation_Editor.update_slug ); |
| 134 | $(document).on( 'focus', '#job_field_slug .js-translated-value', WCML_WPML_Translation_Editor.update_slug ); |
| 135 | $(document).on( 'blur', '#job_field_slug .js-translated-value', WCML_WPML_Translation_Editor.update_slug ); |
| 136 | |
| 137 | } |
| 138 | }, |
| 139 | |
| 140 | do_editor_ready : function( event, job_type, field_views, footer_view ) { |
| 141 | |
| 142 | if ( WCML_WPML_Translation_Editor.is_wcml_product ) { |
| 143 | |
| 144 | WCML_WPML_Translation_Editor.save_buttons_tip = WCML_Tooltip.add_before( '.js-save-and-close', wcml_settings.strings.save_tooltip, 'margin-right: 3px;' ); |
| 145 | |
| 146 | WCML_WPML_Translation_Editor.field_views = field_views; |
| 147 | WCML_WPML_Translation_Editor.footer_view = footer_view; |
| 148 | |
| 149 | WCML_WPML_Translation_Editor.update_save_button_state(); |
| 150 | WCML_WPML_Translation_Editor.check_variations_fields(); |
| 151 | |
| 152 | if( wcml_settings.hide_resign ){ |
| 153 | WCML_WPML_Translation_Editor.footer_view.hideResignButton( true ); |
| 154 | }else{ |
| 155 | WCML_Tooltip.add_after( '.js-resign', wcml_settings.strings.resign_tooltip, 'margin-left:-12px;' ); |
| 156 | } |
| 157 | |
| 158 | } |
| 159 | }, |
| 160 | |
| 161 | update_save_button_state: function() { |
| 162 | var one_of_these_fields_is_required = [ 'title', 'product_content', 'product_excerpt' ]; |
| 163 | var disable_buttons = true; |
| 164 | |
| 165 | _.each( WCML_WPML_Translation_Editor.field_views, function( view ) { |
| 166 | var translation = view.getTranslation(); |
| 167 | if ( translation !== '' && jQuery.inArray( view.getFieldType(), one_of_these_fields_is_required ) !== -1 ) { |
| 168 | disable_buttons = false; |
| 169 | if( WCML_WPML_Translation_Editor.save_buttons_tip ){ |
| 170 | WCML_WPML_Translation_Editor.save_buttons_tip.hide(); |
| 171 | } |
| 172 | } |
| 173 | }); |
| 174 | |
| 175 | if( disable_buttons ){ |
| 176 | WCML_WPML_Translation_Editor.save_buttons_tip.show(); |
| 177 | } |
| 178 | |
| 179 | WCML_WPML_Translation_Editor.footer_view.disableSaveButtons( disable_buttons ); |
| 180 | }, |
| 181 | |
| 182 | field_update_ui: function( event, view ) { |
| 183 | WCML_WPML_Translation_Editor.update_save_button_state(); |
| 184 | }, |
| 185 | |
| 186 | check_variations_fields: function(){ |
| 187 | |
| 188 | var elem = false; |
| 189 | jQuery('[id^="job_field_variation_desc"]').closest('.postbox').find('.original_value').each(function(){ |
| 190 | if( jQuery(this).val() === '' ) { |
| 191 | elem = jQuery(this); |
| 192 | }else{ |
| 193 | return false; |
| 194 | } |
| 195 | }); |
| 196 | |
| 197 | if( elem ){ |
| 198 | elem.closest('.postbox').find('.button-link').click(); |
| 199 | } |
| 200 | |
| 201 | } |
| 202 | |
| 203 | }; |
| 204 | |
| 205 | WCML_WPML_Translation_Editor.init(); |
| 206 | |
| 207 | }); |