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
1 month ago
cart_widget.min.js
1 month 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
1 year ago
lock_fields.min.js
1 year 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
1 month ago
wcml-multi-currency.min.js
1 month ago
wcml-setup.js
3 years ago
wcml-setup.min.js
3 years ago
wcml-translation-editor.js
1 week ago
wcml-translation-editor.min.js
1 week 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
dialogs.js
310 lines
| 1 | |
| 2 | var WCML_Dialog = WCML_Dialog || {}; |
| 3 | |
| 4 | jQuery( function($){ |
| 5 | |
| 6 | var dialog_div; |
| 7 | |
| 8 | WCML_Dialog.dialog = function(dialog_id, data){ |
| 9 | var self = this; |
| 10 | |
| 11 | if(typeof dialog_id == 'undefined'){ |
| 12 | dialog_id = 'generic'; |
| 13 | } |
| 14 | |
| 15 | self.overflow_y = $('body').css('overflow-y'); |
| 16 | $('body').css('overflow-y','hidden'); |
| 17 | |
| 18 | dialog_div = $('#wcml-dialog-' + dialog_id); |
| 19 | |
| 20 | var title = $('#' + dialog_id).attr('title'); |
| 21 | if( typeof title == 'undefined'){ |
| 22 | if( data.title != 'undefined'){ |
| 23 | title = data.title; |
| 24 | }else{ |
| 25 | title = ''; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | if( typeof data.class === 'undefined'){ |
| 30 | data.class = ''; |
| 31 | } |
| 32 | |
| 33 | if( typeof data.draggable === 'undefined'){ |
| 34 | data.draggable = false; |
| 35 | } |
| 36 | |
| 37 | if(!dialog_div.length){ |
| 38 | $(document.body).append($('<div class="wcml-dialog-container" title="' + title + '" id="wcml-dialog-' + dialog_id + '" />')); |
| 39 | |
| 40 | dialog_div = $('#wcml-dialog-' + dialog_id); |
| 41 | var window_h = $( window ).height(); |
| 42 | |
| 43 | var dialog_parameters = { |
| 44 | title: '', |
| 45 | autoOpen:false, |
| 46 | show:true, |
| 47 | dialogClass:'wcml-ui-dialog otgs-ui-dialog ' + data.class, |
| 48 | position: { my: 'center', at: 'center', of: window }, |
| 49 | modal:true, |
| 50 | width: "90%", |
| 51 | height: "auto", |
| 52 | resizable:false, |
| 53 | draggable: data.draggable, |
| 54 | beforeOpen: function (event) { |
| 55 | }, |
| 56 | beforeClose: function (event) { |
| 57 | }, |
| 58 | close: function (event) { |
| 59 | $('#jquery-ui-style-css').prop('disabled', false); |
| 60 | $('body').css('overflow-y', self.overflow_y); |
| 61 | }, |
| 62 | create: function (event) { |
| 63 | |
| 64 | }, |
| 65 | focus: function (event) { |
| 66 | }, |
| 67 | open: function (event) { |
| 68 | $('body').css('overflow', 'hidden'); |
| 69 | $('#jquery-ui-style-css').prop('disabled', true); |
| 70 | |
| 71 | if( data.class === 'wcml-cs-dialog' ){ |
| 72 | WCML_Dialog._attachDialogScrollEvent(); |
| 73 | } |
| 74 | }, |
| 75 | refresh:function(event){ |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | if(typeof data.height != 'undefined' && data.class != 'wcml-cs-dialog'){ |
| 80 | dialog_parameters.height = Math.min(window_h * 0.7, data.height); |
| 81 | } |
| 82 | |
| 83 | if(typeof data.width != 'undefined' && data.class != 'wcml-cs-dialog'){ |
| 84 | dialog_parameters.width = data.width; |
| 85 | } |
| 86 | |
| 87 | if(WCML_Dialog.using_wpdialog){ // pre WP 3.5 |
| 88 | dialog_div.wpdialog(dialog_parameters); |
| 89 | }else{ |
| 90 | dialog_div.dialog( |
| 91 | dialog_parameters |
| 92 | ).on('dialogopen', function () { |
| 93 | WCML_Dialog._repositionDialog(); |
| 94 | }); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | var resizeWindowEvent = _.debounce(function() { |
| 99 | WCML_Dialog._repositionDialog(); |
| 100 | if( data.class === 'wcml-cs-dialog' ) { |
| 101 | WCML_Dialog._attachDialogScrollEvent(); |
| 102 | } |
| 103 | }, 200); |
| 104 | |
| 105 | if(WCML_Dialog.using_wpdialog) { // pre WP 3.5 |
| 106 | dialog_div.wpdialog('open'); |
| 107 | }else{ |
| 108 | dialog_div.dialog('open'); |
| 109 | } |
| 110 | |
| 111 | //load data |
| 112 | if(data.action) { |
| 113 | |
| 114 | var spinner = $('<div class="spinner"></div>'); |
| 115 | spinner.css({display: 'inline-block', visibility: 'visible', float: 'none'}); |
| 116 | dialog_div.html(spinner); |
| 117 | |
| 118 | $.ajax({ |
| 119 | url: ajaxurl, |
| 120 | type: 'post', |
| 121 | dataType: 'json', |
| 122 | data: data, |
| 123 | success: function (response) { |
| 124 | dialog_div.html(response.html); |
| 125 | } |
| 126 | }); |
| 127 | } |
| 128 | |
| 129 | // load static html |
| 130 | if( data.content && $('#' + data.content).length ) { |
| 131 | dialog_div.html($('#' + data.content).html()); |
| 132 | } |
| 133 | |
| 134 | if( typeof WCML_Tooltip != 'undefined' ){ |
| 135 | WCML_Tooltip.init(); |
| 136 | } |
| 137 | |
| 138 | $(window).resize(resizeWindowEvent); |
| 139 | |
| 140 | return false; |
| 141 | } |
| 142 | |
| 143 | WCML_Dialog._repositionDialog = function () { |
| 144 | var winH = $(window).height() - 180; |
| 145 | dialog_div.css("max-height", winH); |
| 146 | |
| 147 | setTimeout(function() { |
| 148 | dialog_div.dialog("option", "position", { |
| 149 | my: "center", |
| 150 | at: "center", |
| 151 | of: window |
| 152 | }); |
| 153 | }, 50); |
| 154 | |
| 155 | } |
| 156 | |
| 157 | WCML_Dialog._attachDialogScrollEvent = function() { |
| 158 | var preview = dialog_div.find('.wcml-currency-preview-wrapper'), |
| 159 | has_two_columns = dialog_div.width() > 900, |
| 160 | has_minimal_height = (preview.height() + 200) < dialog_div.height(); |
| 161 | |
| 162 | has_minimal_height = has_minimal_height || (has_two_columns && preview.height() < dialog_div.height()); |
| 163 | |
| 164 | if (has_minimal_height) { |
| 165 | dialog_div.on('scroll.preview', function(){ |
| 166 | dialog_div.find('.wcml-currency-preview-wrapper').css({ |
| 167 | position: 'relative', |
| 168 | top: dialog_div.scrollTop() |
| 169 | }); |
| 170 | }); |
| 171 | } else { |
| 172 | dialog_div |
| 173 | .off('scroll.preview') |
| 174 | .find('.wcml-currency-preview-wrapper').css({ |
| 175 | position: 'relative', |
| 176 | top: 0 |
| 177 | }); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | WCML_Dialog._register_open_handler = function(){ |
| 182 | |
| 183 | // dialog open handler |
| 184 | $(document).on( 'click','.js-wcml-dialog-trigger', function(e){ |
| 185 | |
| 186 | e.preventDefault(); |
| 187 | var dialog_id = false; |
| 188 | |
| 189 | if($(this).data('dialog')){ |
| 190 | dialog_id = $(this).data('dialog'); |
| 191 | }else if($(this).data('action')) { |
| 192 | dialog_id = $(this).data('action'); |
| 193 | } |
| 194 | |
| 195 | if(dialog_id){ |
| 196 | if($(this).data('action')){ |
| 197 | $(this).data('action', $(this).data('action').replace(/-/g, '_')); |
| 198 | } |
| 199 | WCML_Dialog.dialog(dialog_id, $(this).data()); |
| 200 | } |
| 201 | }); |
| 202 | |
| 203 | // dialog open handler for currency switcher |
| 204 | $(document).on( 'click','.js-wcml-cs-dialog-trigger', function(e){ |
| 205 | |
| 206 | e.preventDefault(); |
| 207 | var dialog_id = false; |
| 208 | |
| 209 | if( $(this).data('dialog') ){ |
| 210 | dialog_id = $(this).data('dialog'); |
| 211 | } |
| 212 | |
| 213 | var data = $(this).data(); |
| 214 | data.class = 'wcml-cs-dialog'; |
| 215 | data.draggable = true; |
| 216 | |
| 217 | if( dialog_id ){ |
| 218 | WCML_Dialog.dialog( dialog_id, data ); |
| 219 | |
| 220 | WCML_Currency_Switcher_Settings.initColorPicker(); |
| 221 | WCML_Currency_Switcher_Settings.currency_switcher_preview( $('#wcml-dialog-'+dialog_id) ); |
| 222 | } |
| 223 | }); |
| 224 | } |
| 225 | |
| 226 | WCML_Dialog._register_close_handler = function(){ |
| 227 | |
| 228 | // dialog close handler |
| 229 | $(document).on( 'click', '.wcml-dialog-close-button', function(e){ |
| 230 | e.preventDefault(); |
| 231 | |
| 232 | if( typeof tinyMCE != 'undefined' ){ |
| 233 | tinyMCE.triggerSave(); |
| 234 | } |
| 235 | |
| 236 | $('.wcml-dialog').find('.mce_editor textarea').each(function(){ |
| 237 | var editor_id = $(this).attr('id'); |
| 238 | var editor_area = $(this); |
| 239 | if (editor_id in tinyMCE.editors) { |
| 240 | var tinymce_editor = tinyMCE.get(editor_id); |
| 241 | if (!tinymce_editor.isHidden()) { |
| 242 | editor_area.val(tinymce_editor.getContent()); |
| 243 | } |
| 244 | } |
| 245 | }); |
| 246 | |
| 247 | var dialog_div = $(this).closest('.wcml-dialog-container'); |
| 248 | |
| 249 | var elem = $(this); |
| 250 | elem.prop('disabled', true); |
| 251 | |
| 252 | var data = $(this).data(); |
| 253 | if(data.action){ // sync ajax |
| 254 | |
| 255 | var spinner = $('<div class="spinner"></div>'); |
| 256 | spinner.css({visibility: 'visible', float: 'right'}).prependTo( $('.wcml-dialog-footer .alignright') ); |
| 257 | |
| 258 | $.ajax({ |
| 259 | url: ajaxurl, |
| 260 | type: 'post', |
| 261 | dataType: 'json', |
| 262 | data: { |
| 263 | action : data.action, |
| 264 | fields : elem.closest('.wcml-dialog-container').find('form').serialize(), |
| 265 | icl_nonce : data.nonce |
| 266 | }, |
| 267 | async: false, |
| 268 | success: function (response) { |
| 269 | if( data.stay ){ |
| 270 | spinner.remove(); |
| 271 | elem.prop('disabled', false); |
| 272 | } |
| 273 | } |
| 274 | }); |
| 275 | } |
| 276 | |
| 277 | if(!data.stay){ |
| 278 | elem.trigger('before_close_dialog'); |
| 279 | if(WCML_Dialog.using_wpdialog){ // pre WP 3.5 |
| 280 | dialog_div.wpdialog('close'); |
| 281 | }else{ |
| 282 | dialog_div.dialog('close'); |
| 283 | } |
| 284 | } |
| 285 | }); |
| 286 | } |
| 287 | |
| 288 | WCML_Dialog.init = function(){ |
| 289 | |
| 290 | $(function() { |
| 291 | if (typeof $.wp != 'undefined') { |
| 292 | WCML_Dialog.using_wpdialog = typeof $.wp.wpdialog != 'undefined'; |
| 293 | } else { |
| 294 | WCML_Dialog.using_wpdialog = false; |
| 295 | } |
| 296 | |
| 297 | WCML_Dialog._register_open_handler(); |
| 298 | WCML_Dialog._register_close_handler(); |
| 299 | }); |
| 300 | } |
| 301 | |
| 302 | WCML_Dialog.init(); |
| 303 | }); |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 |