1/* 2 * 3 * Storequickorder plugin for Webasyst framework. 4 * 5 * @name Storequickorder 6 * @author EasyIT LLC 7 * @link http://easy-it.ru/ 8 * @copyright Copyright (c) 2015, EasyIT LLC 9 * @version 1.6.4, 2016-03-17 10 * 11 */ 12(function($) { 13 sCenterDialog = function(dialog) { 14 dialog = $(dialog); 15 var wdw = dialog.find('.dialog-window'); 16 var dw = wdw.outerWidth(true); 17 var dh = wdw.outerHeight(true); 18 var ww = $(window).width(); 19 var wh = $(window).height(); 20 var w = ((ww/2)-(dw/2)); 21 var h = ((wh/2)-(dh/2)); 22 23 24 //*if (($.storequickorder.options.window_style_position_absolute !== undefined) && $.storequickorder.options.window_style_position_absolute) {*/ 25 26 if (($.storequickorder.options.window_vert_align !== undefined) && $.storequickorder.options.window_vert_align) { 27 28 wdw.css({ 29 'marginLeft': Math.round(w)+'px', 30 'marginTop': $(window).scrollTop() + $.storequickorder.options.window_margin_top +'px', 31 'position': 'absolute' 32 }); 33 } else { 34 wdw.css({ 35 'marginLeft': Math.round(w)+'px', 36 'marginTop': $.storequickorder.options.window_margin_top +'px', 37 //'position': 'absolute' 38 }); 39 } 40 /*} else { 41 wdw.css({ 42 'marginLeft': Math.round(w)+'px', 43 'marginTop': Math.round(h)+'px' 44 }); 45 }*/ 46 47 48 } 49 50sdialogCreate = function(p) { 51 p = $.extend({ 52 url: null, 53 post: null, 54 el: null 55 }, p); 56 57 var dialog = $('#storequickorder'); 58 if (dialog.size() <= 0) { 59 if (p.url) { 60 var f_callback = function (response) { 61 dialog = $(response); 62 if (typeof storequickorder_event_dialog_show == 'function') { 63 storequickorder_event_dialog_show(response, dialog, p); 64 } else { 65 dialog.appendTo('body'); 66 dialog.show(); 67 } 68 69 p.el.removeAttr('disabled'); 70 71 sCenterDialog(dialog); 72 $('#storequickorder').on('click', '.close-button', function() { 73 74 if ($('input[name=storequickorder_result_success]').length) { 75 if (typeof storequickorder_event_dialog_result_success == 'function') { 76 storequickorder_event_dialog_result_success(response, dialog, p); 77 } 78 $('#storequickorder').remove(); 79 location.reload(); 80 } else { 81 $('#storequickorder').remove(); 82 } 83 84 }); 85 $('#storequickorder').on('click', '.submit-button', function() { 86 var button = this; 87 if (typeof storequickorder_event_dialog_submit == 'function') { 88 storequickorder_event_dialog_submit(response, dialog, button); 89 } 90 91 if ($('#storequickorder form:first').length) { 92 var form = $('#storequickorder form:first'); 93 var place = $(form).find('input[name="place"]').val(); 94 //var act = place === undefined ? 'order' : ( place == 'frontend_cart' ? 'cart_order' : 'order'); 95 var act = (place == 'frontend_cart' ? 'cart_order' : 'order'); 96 97 $.ajax({ 98 url: p.el.attr('data-app-url') + 'storequickorder/' + act + '/', 99 data: $(form).serialize(), 100 type: 'POST', 101 dataType: 'html', //"JSON", 102 beforeSend: function() { 103 if (typeof storequickorder_event_dialog_submit_beforesend == 'function') { 104 storequickorder_event_dialog_submit_beforesend(response, dialog, button); 105 } 106 $(button).attr('disabled', 'disabled'); 107 }, 108 success: function(r){ 109 if (typeof storequickorder_event_dialog_submit_success == 'function') { 110 storequickorder_event_dialog_submit_success($.storequickorder.options, r); 111 } 112 $('#storequickorder .dialog-content-indent').replaceWith($(r).find('.dialog-content-indent')); 113 if ($(r).find('.checkout-result').length) { 114 115 // Yandex-Metrics 116 if (($.storequickorder.options.yaCounter_enabled !== undefined) && ($.storequickorder.options.yaCounter_enabled == true) && ($.storequickorder.options.yaCounter_id !== undefined) && !isNaN(parseInt($.storequickorder.options.yaCounter_id)) && (typeof eval('yaCounter' + $.storequickorder.options.yaCounter_id) == 'object')) { 117 eval('yaCounter' + $.storequickorder.options.yaCounter_id).reachGoal($.
117storequickorder.options.yaCounter_target_name); 118 //console.log('yaCounter reachGoal !!!'); 119 } 120 121 // Google-Analytics 122 if (($.storequickorder.options.ga_enabled !== undefined) && ($.storequickorder.options.ga_enabled == true) && ($.storequickorder.options.ga_id !== undefined) && (typeof ga == 'function')) { 123 ga('send', 'event', $.storequickorder.options.ga_target_name, $.storequickorder.options.ga_target_name); 124 //console.log('ga send !!!'); 125 } 126 127 if (typeof storequickorder_event_order_created == 'function') { 128 storequickorder_event_order_created($.storequickorder.options, r); 129 } 130 $(button).hide(); 131 } else { 132 $(button).removeAttr('disabled', 'disabled'); 133 } 134 135 } 136 }); 137 138 139 } 140 }); 141 var onEsc = function(e) { 142 if (!dialog.is(':visible')) { 143 return; 144 } 145 146 if (e && e.keyCode == 27) { // escape 147 if (p.oncancel && typeof p.oncancel == 'function') { 148 p.oncancel.call(dialog[0]); 149 } 150 $('#storequickorder').remove(); 151 return; 152 } 153 154 $(document).one('keyup', onEsc); 155 }; 156 onEsc(); 157 if (p.onload) { 158 p.onload.call(dialog[0]); 159 } 160 }; 161 if (p.post) { 162 $.post(p.url, p.post, f_callback); 163 } else { 164 $.get(p.url, f_callback); 165 } 166 } 167 } else { 168 dialog.show(); 169 } 170 171 $(document).one('hashchange', $('#storequickorder').remove); 172 return dialog; 173} 174 175 176 $(function() { 177 $.storequickorder = { 178 init : 0, 179 is_mobile : true,//false, 180 options: {}, 181 check_stock_delay: 100, 182 setOptions: function(opts) { 183 var self = this; 184 self.options = opts; 185 if (typeof opts.check_stock_delay != 'undefined') { 186 self.check_stock_delay = opts.check_stock_delay; 187 } 188 if (/iPhone/i.test(window.navigator.userAgent)) { 189 self.is_mobile = true; 190 } 191 if (/Android/i.test(window.navigator.userAgent)) { 192 if (/Mobile/i.test(window.navigator.userAgent)) { 193 self.is_mobile = true; 194 } 195 } 196 self.options.window_margin_top = 200; 197 if ((typeof opts.window_margin_top != 'undefined') && (opts.window_margin_top)) { 198 self.options.window_margin_top = 200; 199 } 200 }, 201 findParentFormBuyoneclick : function(button_one_click) { 202 var parent_form; 203 var parent_li; 204 var parent_div_cart; 205 if ((parent_form = button_one_click.closest('form')) && parent_form.length) { 206 return parent_form; 207 } else if ((parent_li = button_one_click.closest('li')) && parent_li.length) { 208 if ((parent_form = parent_li.find('form').first()) && parent_form.length) { 209 return parent_form; 210 } 211 212 return $(); 213 } else if ((parent_div_cart = button_one_click.closest('div.cart')) && parent_div_cart.length) { 214 215 if ((parent_form = parent_div_cart.find('form').first()) && parent_form.length) { 216 return parent_form; 217 } 218 219 return $(); 220 } else if ((parent_form = $('form#cart-form').first()) && parent_form.length) { 221 return parent_form; 222 } else if ((parent_form = $('form.cart-form')) && (parent_form.length == 1)) { 223 return parent_form; 224 } 225 return $(); /* заглÑÑка Ð¾Ñ JS-нÑÑ Ð¾Ñибок, вмеÑÑо false */ 226 //element.closest('form') 227 }, 228 initProduct: function(params) { 229 var self = this; 230 if (self.init != 1) { 231 $('#dsvoverview').removeAttr('tabindex'); // for dsv2 delete поÑле вÑÑ Ð¾Ð´Ð° ss6.1 232 self.init = 1; 233 } 234 if (typeof params.button_id == 'undefined') { 235 return false;
236 } 237 params.place = 'product'; 238 self.initButtonBuyoneclick(params); 239 }, 240 initFrontendCart: function(params) { 241 var self = this; 242 if (typeof params.button_id == 'undefined') { 243 return false; 244 } 245 params.place = 'frontend_cart'; 246 self.initButtonBuyoneclick(params); 247 }, 248 249 initButtonBuyoneclick: function(params) { 250 var self = this; 251 if (self.init != 1) { 252 $('#dsvoverview').removeAttr('tabindex'); // for dsv2 253 self.init = 1; 254 } 255 if (typeof params.button_id == 'undefined') { 256 return false; 257 } 258 259 var but_id = params.button_id; 260 261 var but = $('.' + but_id); 262 var parent_form = self.findParentFormBuyoneclick(but); 263 parent_form.data('storequickorder-button', but); 264 but.data('parent_form', parent_form); 265 266 if (typeof params.place != 'undefined') { 267 but.data('place', params.place); 268 } else { 269 but.data('place', 'product'); 270 } 271 if (typeof storequickorder_event_init_buyoneclick == 'function') { 272 storequickorder_event_init_buyoneclick(params, but); 273 } 274 275 276 var ajax_url = 'order'; 277 if (but.data('place') == 'frontend_cart') { 278 ajax_url = 'cart_order'; 279 } else { 280 if (!parent_form.find('[name="product_id"]').length) { 281 but.hide(); 282 //self.setVisibilityButton(false,but, parent_form); 283 } 284 } 285 286 287 288 $('body').on('click', '.' + but_id, function() { 289 var element = $(this); 290 if (typeof storequickorder_event_button_click == 'function') { 291 storequickorder_event_button_click(element, parent_form, but_id); 292 } 293 element.attr('disabled', 'disabled'); 294 295 sdialogCreate({ 296 url: element.attr('data-app-url') + 'storequickorder/' + ajax_url + '/', 297 //post: $('form#cart-form').serialize() + '&product_data=1', 298 post: parent_form.serialize() + '&product_data=1', 299 el: element 300 }); 301 }); 302 303 self.searchMethodStorageStocks(but, parent_form); 304 parent_form.find("#product-skus input:radio").on('click', function () { 305 if ($(this).data('disabled')) { 306 self.setVisibilityButton(false, but, parent_form); 307 } else { 308 self.setVisibilityButton(true, but, parent_form); 309 } 310 }); 311 parent_form.find( 312 '.skus input:radio,' + 313 '.services input[type=checkbox],' + 314 '.inline-select a,' + 315 'a[data-feature-id]' + 316 '').on('click', function () { 317 setTimeout(function() { 318 self.checkStock( but, parent_form); 319 }, self.check_stock_delay); 320 }); 321 322 parent_form.find( 323 'select.sku-feature,' + 324 'select[name^="service_variant"]' + 325 '').on('change', function() { 326 setTimeout(function() { 327 self.checkStock( but, parent_form); 328 }, self.check_stock_delay); 329 }); 330 331 self.checkStock(but, parent_form); 332 setTimeout(function() { 333 self.checkStock( but, parent_form); 334 }, self.check_stock_delay); /* fix */ 335 }, 336 337 checkStock : function (but, parent_form) { 338 var av = true; 339 var skip = true; 340 var self = this; 341 if (but.data('methodStorageStock') == 'div_stocks') { 342 var fl = false; 343 parent_form.find('div.stocks strong[class^="stock-"]:visible, div.stocks span[class^="stock-"]:visible').each(function(indx, el){ 344 if ($(this).hasClass('stock-none')) { /* || $(this).hasClass('stock-critical') */ 345 av = false;
346 } else { 347 fl = true; 348 } 349 }); 350 if (!fl) { 351 av = false; 352 } else { 353 av = true; 354 } 355 skip = false; 356 } else if ((but.data('methodStorageStock') == 'div_stocks_custom') || (but.data('methodStorageStock') == 'default')) { 357 skip = false; 358 //setTimeout(function() { 359 av = self.isEnabledAdd2cart_button(but, parent_form); 360 //}, 500); 361 } else { 362 //unknown method storage stock 363 } 364 //if (!skip) { 365 self.setVisibilityButton(av, but, parent_form); 366 //} 367 if (typeof storequickorder_event_check_stock == 'function') { 368 storequickorder_event_check_stock(av, but, parent_form); 369 } 370 return av; 371 372 }, 373 searchMethodStorageStocks : function (but, parent_form) { 374 var self = this; 375 if (typeof storequickorder_event_search_method == 'function') { 376 return storequickorder_event_search_method(but, parent_form, self); 377 } 378 379 if ((typeof but.data('methodStorageStock') != 'undefined') && (but.data('methodStorageStock') != '')) { 380 return but.data('methodStorageStock'); 381 } else { 382 if (parent_form.find('div.stocks strong').length) { 383 but.data('methodStorageStock', 'div_stocks'); 384 if (!parent_form.find('div.stocks strong:visible').length) { 385 but.data('methodStorageStock', 'div_stocks_custom'); 386 } 387 } else if (parent_form.find('div.stocks span').length) { 388 but.data('methodStorageStock', 'div_stocks'); 389 if (!parent_form.find('div.stocks span:visible').length) { 390 but.data('methodStorageStock', 'div_stocks_custom'); // var 2 391 } 392 } else { 393 but.data('methodStorageStock', 'default'); 394 } 395 return but.data('methodStorageStock'); 396 } 397 }, 398 setVisibilityButton : function (vis, but, parent_form) { 399 var self = this; 400 if (typeof storequickorder_event_set_visibility_button == 'function') { 401 return storequickorder_event_set_visibility_button(vis, but, parent_form, self); 402 } 403 var but_place = but.data('place'); 404 if (but_place != 'frontend_cart') { 405 if (vis) { 406 // rename 407 if (self.options.button_name !== undefined) { 408 but.val(self.options.button_name); 409 } 410 } else { 411 // rename 412 if (self.options.button_name_not_available !== undefined) { 413 but.val(self.options.button_name_not_available); 414 } 415 } 416 } 417 418 419 if (((self.options.always_show_active_button !== undefined) && self.options.always_show_active_button) || vis) { 420 but.removeAttr('disabled'); 421 422 if (typeof storequickorder_event_set_visibility_button_true == 'function') { 423 storequickorder_event_set_visibility_button_true(vis, but, parent_form); 424 } 425 426 427 428 } else { 429 but.attr('disabled', 'disabled'); 430 431 if (typeof storequickorder_event_set_visibility_button_false == 'function') { 432 storequickorder_event_set_visibility_button_false(vis, but, parent_form); 433 } 434 } 435 436 }, 437 isEnabledAdd2cart_button : function ( but, parent_form ) { 438 if (typeof storequickorder_event_is_enabled_add2cart == 'function') { 439 return storequickorder_event_is_enabled_add2cart(but, parent_form); 440 } 441 if (!parent_form.find('.add2cart [type="submit"]').is("[disabled]") || (parent_form.find('.add2cart [type="submit"]:enabled').length>0)) { 442 return true; 443 } else { 444 return false; 445 } 446 } 447 ,startCheckStock : function (but, parent_form) { 448 var self = this; 449 self.checkStock(but, parent_form); 450 } 451 }; 452}); 453 454})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.