SHARE
TWEET

Untitled

a guest Oct 21st, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. //alert('loaded')
  3. function log(text) {
  4.   console.log(text)
  5. }
  6.  
  7. function docReady(fn) {
  8.   //setTimeout(fn, 10000);
  9.   //return
  10.     // see if DOM is already available
  11.     console.log("read?", document.readyState, document.readyState, $('[role=slider]').length)
  12.  
  13.     if (document.readyState === "complete" || document.readyState === "interactive" && $('[role=slider]').length) {
  14.         // call on next available tick
  15.        return setTimeout(fn, 200);
  16.     } else {
  17.        return setTimeout(function() {
  18.          log("not ready")
  19.          docReady(fn)
  20.        }, 200);
  21.        //document.addEventListener("DOMContentLoaded", fn);
  22.     }
  23. }
  24.  
  25. function setKeywordText($el, text) {
  26.     // $el.val(text);
  27.     // $el.html(text);
  28.     // $el.click()
  29.     $d = $(document)
  30.     $el.trigger('focus')
  31.     for (var i = 0; i < text.length; i++) {  
  32.       $d.trigger('keydown', {which: text.charCodeAt(0), key: 'A'.charCodeAt(0)})
  33.       //    
  34.       $el.trigger('beforeinput', {which: 'A'.charCodeAt(0), key: 'A'.charCodeAt(0)})
  35.       $d.trigger('keypress', {which: 'A'.charCodeAt(0), key: 'A'.charCodeAt(0)})
  36.       $el.val($el.val() + 'A')
  37.       $el.trigger('input', {which: 'A'.charCodeAt(0), key: 'A'.charCodeAt(0)})
  38.       $el.trigger('change', {which: 'A'.charCodeAt(0), key: 'A'.charCodeAt(0)})
  39.       $d.trigger('keyup', {which: 'A'.charCodeAt(0), key: 'A'.charCodeAt(0)})
  40.     //    
  41.     }
  42.     //$el.trigger('change')
  43.     //$el.trigger('blur')
  44.  
  45.   return
  46.  
  47.     $el.trigger('keypress')
  48.    
  49.     $el.trigger('change')
  50. }
  51.  
  52.  
  53. window.getTotalQuantity = function () {
  54.   log('getTotalQuantity')
  55.   var $sliders = $('[role=slider]')
  56.   var $input = $("input[aria-label=Cantidad]")
  57.   var $textarea = $('textarea[data-hook=text-option-text-area]')
  58.  
  59.   var total = $sliders.reduce(function(i, n) {  
  60.     return n.getAttribute('aria-valuenow') * i
  61.   }, quantity.val()) / 10000
  62.    
  63.   var rounded = Math.round( total * 10 ) / 10
  64.   $input.val(rounded)
  65.  
  66.   var text = quantity.val()
  67.          + " Baldosas adhesivas de "
  68.          + $sliders[0].getAttribute('aria-valuenow')
  69.          + "cm x "
  70.          + $sliders[1].getAttribute('aria-valuenow')
  71.          + "cm"
  72.        
  73.   setKeywordText($textarea, text);
  74.  
  75.   return rounded  
  76. }  
  77.  
  78. document.body.onload = function() {    
  79.   quantity = $('[role=slider]').parent().parent().find('input')
  80.  
  81.  
  82.   quantity.change( function() {
  83.     log('quantity change')
  84.     getTotalQuantity()
  85.   })
  86.  
  87.   var observer = new MutationObserver(function(mutations) {
  88.     mutations.forEach(function(mutation) {
  89.       if (mutation.type == "attributes") {
  90.         log('slider change')
  91.         console.log("attributes changed")
  92.         getTotalQuantity()
  93.       }
  94.     });
  95.   });
  96.   $('[role=slider]').each( function(i, n) {
  97.      observer.observe(n, {
  98.        attributes: true //configure it to listen to attribute changes
  99.      });
  100.   })
  101. }
  102. </script>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top