Advertisement
Guest User

Magento 1.7.0.2 - js.js

a guest
Sep 3rd, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Magento
  3.  *
  4.  * NOTICE OF LICENSE
  5.  *
  6.  * This source file is subject to the Academic Free License (AFL 3.0)
  7.  * that is bundled with this package in the file LICENSE_AFL.txt.
  8.  * It is also available through the world-wide-web at this URL:
  9.  * http://opensource.org/licenses/afl-3.0.php
  10.  * If you did not receive a copy of the license and are unable to
  11.  * obtain it through the world-wide-web, please send an email
  12.  * to license@magentocommerce.com so we can send you a copy immediately.
  13.  *
  14.  * DISCLAIMER
  15.  *
  16.  * Do not edit or add to this file if you wish to upgrade Magento to newer
  17.  * versions in the future. If you wish to customize Magento for your
  18.  * needs please refer to http://www.magentocommerce.com for more information.
  19.  *
  20.  * @category    Varien
  21.  * @package     js
  22.  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  23.  * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
  24.  */
  25. function popWin(url,win,para) {
  26.     var win = window.open(url,win,para);
  27.     win.focus();
  28. }
  29.  
  30. function setLocation(url){
  31.     window.location.href = url;
  32. }
  33.  
  34. function setPLocation(url, setFocus){
  35.     if( setFocus ) {
  36.         window.opener.focus();
  37.     }
  38.     window.opener.location.href = url;
  39. }
  40.  
  41. function setLanguageCode(code, fromCode){
  42.     //TODO: javascript cookies have different domain and path than php cookies
  43.     var href = window.location.href;
  44.     var after = '', dash;
  45.     if (dash = href.match(/\#(.*)$/)) {
  46.         href = href.replace(/\#(.*)$/, '');
  47.         after = dash[0];
  48.     }
  49.  
  50.     if (href.match(/[?]/)) {
  51.         var re = /([?&]store=)[a-z0-9_]*/;
  52.         if (href.match(re)) {
  53.             href = href.replace(re, '$1'+code);
  54.         } else {
  55.             href += '&store='+code;
  56.         }
  57.  
  58.         var re = /([?&]from_store=)[a-z0-9_]*/;
  59.         if (href.match(re)) {
  60.             href = href.replace(re, '');
  61.         }
  62.     } else {
  63.         href += '?store='+code;
  64.     }
  65.     if (typeof(fromCode) != 'undefined') {
  66.         href += '&from_store='+fromCode;
  67.     }
  68.     href += after;
  69.  
  70.     setLocation(href);
  71. }
  72.  
  73. /**
  74.  * Add classes to specified elements.
  75.  * Supported classes are: 'odd', 'even', 'first', 'last'
  76.  *
  77.  * @param elements - array of elements to be decorated
  78.  * [@param decorateParams] - array of classes to be set. If omitted, all available will be used
  79.  */
  80. function decorateGeneric(elements, decorateParams)
  81. {
  82.     var allSupportedParams = ['odd', 'even', 'first', 'last'];
  83.     var _decorateParams = {};
  84.     var total = elements.length;
  85.  
  86.     if (total) {
  87.         // determine params called
  88.         if (typeof(decorateParams) == 'undefined') {
  89.             decorateParams = allSupportedParams;
  90.         }
  91.         if (!decorateParams.length) {
  92.             return;
  93.         }
  94.         for (var k in allSupportedParams) {
  95.             _decorateParams[allSupportedParams[k]] = false;
  96.         }
  97.         for (var k in decorateParams) {
  98.             _decorateParams[decorateParams[k]] = true;
  99.         }
  100.  
  101.         // decorate elements
  102.         // elements[0].addClassName('first'); // will cause bug in IE (#5587)
  103.         if (_decorateParams.first) {
  104.             Element.addClassName(elements[0], 'first');
  105.         }
  106.         if (_decorateParams.last) {
  107.             Element.addClassName(elements[total-1], 'last');
  108.         }
  109.         for (var i = 0; i < total; i++) {
  110.             if ((i + 1) % 2 == 0) {
  111.                 if (_decorateParams.even) {
  112.                     Element.addClassName(elements[i], 'even');
  113.                 }
  114.             }
  115.             else {
  116.                 if (_decorateParams.odd) {
  117.                     Element.addClassName(elements[i], 'odd');
  118.                 }
  119.             }
  120.         }
  121.     }
  122. }
  123.  
  124. /**
  125.  * Decorate table rows and cells, tbody etc
  126.  * @see decorateGeneric()
  127.  */
  128. function decorateTable(table, options) {
  129.     var table = $(table);
  130.     if (table) {
  131.         // set default options
  132.         var _options = {
  133.             'tbody'    : false,
  134.             'tbody tr' : ['odd', 'even', 'first', 'last'],
  135.             'thead tr' : ['first', 'last'],
  136.             'tfoot tr' : ['first', 'last'],
  137.             'tr td'    : ['last']
  138.         };
  139.         // overload options
  140.         if (typeof(options) != 'undefined') {
  141.             for (var k in options) {
  142.                 _options[k] = options[k];
  143.             }
  144.         }
  145.         // decorate
  146.         if (_options['tbody']) {
  147.             decorateGeneric(table.select('tbody'), _options['tbody']);
  148.         }
  149.         if (_options['tbody tr']) {
  150.             decorateGeneric(table.select('tbody tr'), _options['tbody tr']);
  151.         }
  152.         if (_options['thead tr']) {
  153.             decorateGeneric(table.select('thead tr'), _options['thead tr']);
  154.         }
  155.         if (_options['tfoot tr']) {
  156.             decorateGeneric(table.select('tfoot tr'), _options['tfoot tr']);
  157.         }
  158.         if (_options['tr td']) {
  159.             var allRows = table.select('tr');
  160.             if (allRows.length) {
  161.                 for (var i = 0; i < allRows.length; i++) {
  162.                     decorateGeneric(allRows[i].getElementsByTagName('TD'), _options['tr td']);
  163.                 }
  164.             }
  165.         }
  166.     }
  167. }
  168.  
  169. /**
  170.  * Set "odd", "even" and "last" CSS classes for list items
  171.  * @see decorateGeneric()
  172.  */
  173. function decorateList(list, nonRecursive) {
  174.     if ($(list)) {
  175.         if (typeof(nonRecursive) == 'undefined') {
  176.             var items = $(list).select('li')
  177.         }
  178.         else {
  179.             var items = $(list).childElements();
  180.         }
  181.         decorateGeneric(items, ['odd', 'even', 'last']);
  182.     }
  183. }
  184.  
  185. /**
  186.  * Set "odd", "even" and "last" CSS classes for list items
  187.  * @see decorateGeneric()
  188.  */
  189. function decorateDataList(list) {
  190.     list = $(list);
  191.     if (list) {
  192.         decorateGeneric(list.select('dt'), ['odd', 'even', 'last']);
  193.         decorateGeneric(list.select('dd'), ['odd', 'even', 'last']);
  194.     }
  195. }
  196.  
  197. /**
  198.  * Parse SID and produces the correct URL
  199.  */
  200. function parseSidUrl(baseUrl, urlExt) {
  201.     var sidPos = baseUrl.indexOf('/?SID=');
  202.     var sid = '';
  203.     urlExt = (urlExt != undefined) ? urlExt : '';
  204.  
  205.     if(sidPos > -1) {
  206.         sid = '?' + baseUrl.substring(sidPos + 2);
  207.         baseUrl = baseUrl.substring(0, sidPos + 1);
  208.     }
  209.  
  210.     return baseUrl+urlExt+sid;
  211. }
  212.  
  213. /**
  214.  * Formats currency using patern
  215.  * format - JSON (pattern, decimal, decimalsDelimeter, groupsDelimeter)
  216.  * showPlus - true (always show '+'or '-'),
  217.  *      false (never show '-' even if number is negative)
  218.  *      null (show '-' if number is negative)
  219.  */
  220.  
  221. function formatCurrency(price, format, showPlus){
  222.     var precision = isNaN(format.precision = Math.abs(format.precision)) ? 2 : format.precision;
  223.     var requiredPrecision = isNaN(format.requiredPrecision = Math.abs(format.requiredPrecision)) ? 2 : format.requiredPrecision;
  224.  
  225.     //precision = (precision > requiredPrecision) ? precision : requiredPrecision;
  226.     //for now we don't need this difference so precision is requiredPrecision
  227.     precision = requiredPrecision;
  228.  
  229.     var integerRequired = isNaN(format.integerRequired = Math.abs(format.integerRequired)) ? 1 : format.integerRequired;
  230.  
  231.     var decimalSymbol = format.decimalSymbol == undefined ? "," : format.decimalSymbol;
  232.     var groupSymbol = format.groupSymbol == undefined ? "." : format.groupSymbol;
  233.     var groupLength = format.groupLength == undefined ? 3 : format.groupLength;
  234.  
  235.     var s = '';
  236.  
  237.     if (showPlus == undefined || showPlus == true) {
  238.         s = price < 0 ? "-" : ( showPlus ? "+" : "");
  239.     } else if (showPlus == false) {
  240.         s = '';
  241.     }
  242.  
  243.     var i = parseInt(price = Math.abs(+price || 0).toFixed(precision)) + "";
  244.     var pad = (i.length < integerRequired) ? (integerRequired - i.length) : 0;
  245.     while (pad) { i = '0' + i; pad--; }
  246.     j = (j = i.length) > groupLength ? j % groupLength : 0;
  247.     re = new RegExp("(\\d{" + groupLength + "})(?=\\d)", "g");
  248.  
  249.     /**
  250.      * replace(/-/, 0) is only for fixing Safari bug which appears
  251.      * when Math.abs(0).toFixed() executed on "0" number.
  252.      * Result is "0.-0" :(
  253.      */
  254.     var r = (j ? i.substr(0, j) + groupSymbol : "") + i.substr(j).replace(re, "$1" + groupSymbol) + (precision ? decimalSymbol + Math.abs(price - i).toFixed(precision).replace(/-/, 0).slice(2) : "")
  255.     var pattern = '';
  256.     if (format.pattern.indexOf('{sign}') == -1) {
  257.         pattern = s + format.pattern;
  258.     } else {
  259.         pattern = format.pattern.replace('{sign}', s);
  260.     }
  261.  
  262.     return pattern.replace('%s', r).replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  263. };
  264.  
  265. function expandDetails(el, childClass) {
  266.     if (Element.hasClassName(el,'show-details')) {
  267.         $$(childClass).each(function(item){item.hide()});
  268.         Element.removeClassName(el,'show-details');
  269.     }
  270.     else {
  271.         $$(childClass).each(function(item){item.show()});
  272.         Element.addClassName(el,'show-details');
  273.     }
  274. }
  275.  
  276. // Version 1.0
  277. var isIE = navigator.appVersion.match(/MSIE/) == "MSIE";
  278.  
  279. if (!window.Varien)
  280.     var Varien = new Object();
  281.  
  282. Varien.showLoading = function(){
  283.     Element.show('loading-process');
  284. }
  285. Varien.hideLoading = function(){
  286.     Element.hide('loading-process');
  287. }
  288. Varien.GlobalHandlers = {
  289.     onCreate: function() {
  290.         Varien.showLoading();
  291.     },
  292.  
  293.     onComplete: function() {
  294.         if(Ajax.activeRequestCount == 0) {
  295.             Varien.hideLoading();
  296.         }
  297.     }
  298. };
  299.  
  300. Ajax.Responders.register(Varien.GlobalHandlers);
  301.  
  302. /**
  303.  * Quick Search form client model
  304.  */
  305. Varien.searchForm = Class.create();
  306. Varien.searchForm.prototype = {
  307.     initialize : function(form, field, emptyText){
  308.         this.form   = $(form);
  309.         this.field  = $(field);
  310.         this.emptyText = emptyText;
  311.  
  312.         Event.observe(this.form,  'submit', this.submit.bind(this));
  313.         Event.observe(this.field, 'focus', this.focus.bind(this));
  314.         Event.observe(this.field, 'blur', this.blur.bind(this));
  315.         this.blur();
  316.     },
  317.  
  318.     submit : function(event){
  319.         if (this.field.value == this.emptyText || this.field.value == ''){
  320.             Event.stop(event);
  321.             return false;
  322.         }
  323.         return true;
  324.     },
  325.  
  326.     focus : function(event){
  327.         if(this.field.value==this.emptyText){
  328.             this.field.value='';
  329.         }
  330.  
  331.     },
  332.  
  333.     blur : function(event){
  334.         if(this.field.value==''){
  335.             this.field.value=this.emptyText;
  336.         }
  337.     },
  338.  
  339.     initAutocomplete : function(url, destinationElement){
  340.         new Ajax.Autocompleter(
  341.             this.field,
  342.             destinationElement,
  343.             url,
  344.             {
  345.                 paramName: this.field.name,
  346.                 method: 'get',
  347.                 minChars: 2,
  348.                 updateElement: this._selectAutocompleteItem.bind(this),
  349.                 onShow : function(element, update) {
  350. //                    if(!update.style.position || update.style.position=='absolute') {
  351. //                        update.style.position = 'absolute';
  352. //                        Position.clone(element, update, {
  353. //                            setHeight: false,
  354. //                            offsetTop: element.offsetHeight
  355. //                        });
  356. //                    }
  357.                     Effect.Appear(update,{duration:0});
  358.                 }
  359.  
  360.             }
  361.         );
  362.     },
  363.  
  364.     _selectAutocompleteItem : function(element){
  365.         if(element.title){
  366.             this.field.value = element.title;
  367.         }
  368.         this.form.submit();
  369.     }
  370. }
  371.  
  372. Varien.Tabs = Class.create();
  373. Varien.Tabs.prototype = {
  374.   initialize: function(selector) {
  375.     var self=this;
  376.     $$(selector+' a').each(this.initTab.bind(this));
  377.   },
  378.  
  379.   initTab: function(el) {
  380.       el.href = 'javascript:void(0)';
  381.       if ($(el.parentNode).hasClassName('active')) {
  382.         this.showContent(el);
  383.       }
  384.       el.observe('click', this.showContent.bind(this, el));
  385.   },
  386.  
  387.   showContent: function(a) {
  388.     var li = $(a.parentNode), ul = $(li.parentNode);
  389.     ul.getElementsBySelector('li', 'ol').each(function(el){
  390.       var contents = $(el.id+'_contents');
  391.       if (el==li) {
  392.         el.addClassName('active');
  393.         contents.show();
  394.       } else {
  395.         el.removeClassName('active');
  396.         contents.hide();
  397.       }
  398.     });
  399.   }
  400. }
  401.  
  402. Varien.DateElement = Class.create();
  403. Varien.DateElement.prototype = {
  404.     initialize: function(type, content, required, format) {
  405.         if (type == 'id') {
  406.             // id prefix
  407.             this.day    = $(content + 'day');
  408.             this.month  = $(content + 'month');
  409.             this.year   = $(content + 'year');
  410.             this.full   = $(content + 'full');
  411.             this.advice = $(content + 'date-advice');
  412.         } else if (type == 'container') {
  413.             // content must be container with data
  414.             this.day    = content.day;
  415.             this.month  = content.month;
  416.             this.year   = content.year;
  417.             this.full   = content.full;
  418.             this.advice = content.advice;
  419.         } else {
  420.             return;
  421.         }
  422.  
  423.         this.required = required;
  424.         this.format   = format;
  425.  
  426.         this.day.addClassName('validate-custom');
  427.         this.day.validate = this.validate.bind(this);
  428.         this.month.addClassName('validate-custom');
  429.         this.month.validate = this.validate.bind(this);
  430.         this.year.addClassName('validate-custom');
  431.         this.year.validate = this.validate.bind(this);
  432.  
  433.         this.setDateRange(false, false);
  434.         this.year.setAttribute('autocomplete','off');
  435.  
  436.         this.advice.hide();
  437.     },
  438.     validate: function() {
  439.         var error = false,
  440.             day = parseInt(this.day.value.replace(/^0*/, '')) || 0,
  441.             month = parseInt(this.month.value.replace(/^0*/, '')) || 0,
  442.             year = parseInt(this.year.value) || 0;
  443.         if (!day && !month && !year) {
  444.             if (this.required) {
  445.                 error = 'This date is a required value.';
  446.             } else {
  447.                 this.full.value = '';
  448.             }
  449.         } else if (!day || !month || !year) {
  450.             error = 'Please enter a valid full date.';
  451.         } else {
  452.             var date = new Date, countDaysInMonth = 0, errorType = null;
  453.             date.setYear(year);date.setMonth(month-1);date.setDate(32);
  454.             countDaysInMonth = 32 - date.getDate();
  455.             if(!countDaysInMonth || countDaysInMonth>31) countDaysInMonth = 31;
  456.  
  457.             if (day<1 || day>countDaysInMonth) {
  458.                 errorType = 'day';
  459.                 error = 'Please enter a valid day (1-%d).';
  460.             } else if (month<1 || month>12) {
  461.                 errorType = 'month';
  462.                 error = 'Please enter a valid month (1-12).';
  463.             } else {
  464.                 if(day % 10 == day) this.day.value = '0'+day;
  465.                 if(month % 10 == month) this.month.value = '0'+month;
  466.                 this.full.value = this.format.replace(/%[mb]/i, this.month.value).replace(/%[de]/i, this.day.value).replace(/%y/i, this.year.value);
  467.                 var testFull = this.month.value + '/' + this.day.value + '/'+ this.year.value;
  468.                 var test = new Date(testFull);
  469.                 if (isNaN(test)) {
  470.                     error = 'Please enter a valid date.';
  471.                 } else {
  472.                     this.setFullDate(test);
  473.                 }
  474.             }
  475.             var valueError = false;
  476.             if (!error && !this.validateData()){//(year<1900 || year>curyear) {
  477.                 errorType = this.validateDataErrorType;//'year';
  478.                 valueError = this.validateDataErrorText;//'Please enter a valid year (1900-%d).';
  479.                 error = valueError;
  480.             }
  481.         }
  482.  
  483.         if (error !== false) {
  484.             try {
  485.                 error = Translator.translate(error);
  486.             }
  487.             catch (e) {}
  488.             if (!valueError) {
  489.                 this.advice.innerHTML = error.replace('%d', countDaysInMonth);
  490.             } else {
  491.                 this.advice.innerHTML = this.errorTextModifier(error);
  492.             }
  493.             this.advice.show();
  494.             return false;
  495.         }
  496.  
  497.         // fixing elements class
  498.         this.day.removeClassName('validation-failed');
  499.         this.month.removeClassName('validation-failed');
  500.         this.year.removeClassName('validation-failed');
  501.  
  502.         this.advice.hide();
  503.         return true;
  504.     },
  505.     validateData: function() {
  506.         var year = this.fullDate.getFullYear();
  507.         var date = new Date;
  508.         this.curyear = date.getFullYear();
  509.         return (year>=1900 && year<=this.curyear);
  510.     },
  511.     validateDataErrorType: 'year',
  512.     validateDataErrorText: 'Please enter a valid year (1900-%d).',
  513.     errorTextModifier: function(text) {
  514.         return text.replace('%d', this.curyear);
  515.     },
  516.     setDateRange: function(minDate, maxDate) {
  517.         this.minDate = minDate;
  518.         this.maxDate = maxDate;
  519.     },
  520.     setFullDate: function(date) {
  521.         this.fullDate = date;
  522.     }
  523. };
  524.  
  525. Varien.DOB = Class.create();
  526. Varien.DOB.prototype = {
  527.     initialize: function(selector, required, format) {
  528.         var el = $$(selector)[0];
  529.         var container       = {};
  530.         container.day       = Element.select(el, '.dob-day input')[0];
  531.         container.month     = Element.select(el, '.dob-month input')[0];
  532.         container.year      = Element.select(el, '.dob-year input')[0];
  533.         container.full      = Element.select(el, '.dob-full input')[0];
  534.         container.advice    = Element.select(el, '.validation-advice')[0];
  535.  
  536.         new Varien.DateElement('container', container, required, format);
  537.     }
  538. };
  539.  
  540. Varien.dateRangeDate = Class.create();
  541. Varien.dateRangeDate.prototype = Object.extend(new Varien.DateElement(), {
  542.     validateData: function() {
  543.         var validate = true;
  544.         if (this.minDate || this.maxValue) {
  545.             if (this.minDate) {
  546.                 this.minDate = new Date(this.minDate);
  547.                 this.minDate.setHours(0);
  548.                 if (isNaN(this.minDate)) {
  549.                     this.minDate = new Date('1/1/1900');
  550.                 }
  551.                 validate = validate && (this.fullDate >= this.minDate)
  552.             }
  553.             if (this.maxDate) {
  554.                 this.maxDate = new Date(this.maxDate)
  555.                 this.minDate.setHours(0);
  556.                 if (isNaN(this.maxDate)) {
  557.                     this.maxDate = new Date();
  558.                 }
  559.                 validate = validate && (this.fullDate <= this.maxDate)
  560.             }
  561.             if (this.maxDate && this.minDate) {
  562.                 this.validateDataErrorText = 'Please enter a valid date between %s and %s';
  563.             } else if (this.maxDate) {
  564.                 this.validateDataErrorText = 'Please enter a valid date less than or equal to %s';
  565.             } else if (this.minDate) {
  566.                 this.validateDataErrorText = 'Please enter a valid date equal to or greater than %s';
  567.             } else {
  568.                 this.validateDataErrorText = '';
  569.             }
  570.         }
  571.         return validate;
  572.     },
  573.     validateDataErrorText: 'Date should be between %s and %s',
  574.     errorTextModifier: function(text) {
  575.         if (this.minDate) {
  576.             text = text.sub('%s', this.dateFormat(this.minDate));
  577.         }
  578.         if (this.maxDate) {
  579.             text = text.sub('%s', this.dateFormat(this.maxDate));
  580.         }
  581.         return text;
  582.     },
  583.     dateFormat: function(date) {
  584.         return (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
  585.     }
  586. });
  587.  
  588. Varien.FileElement = Class.create();
  589. Varien.FileElement.prototype = {
  590.     initialize: function (id) {
  591.         this.fileElement = $(id);
  592.         this.hiddenElement = $(id + '_value');
  593.  
  594.         this.fileElement.observe('change', this.selectFile.bind(this));
  595.     },
  596.     selectFile: function(event) {
  597.         this.hiddenElement.value = this.fileElement.getValue();
  598.     }
  599. };
  600.  
  601. Validation.addAllThese([
  602.     ['validate-custom', ' ', function(v,elm) {
  603.         return elm.validate();
  604.     }]
  605. ]);
  606.  
  607. function truncateOptions() {
  608.     $$('.truncated').each(function(element){
  609.         Event.observe(element, 'mouseover', function(){
  610.             if (element.down('div.truncated_full_value')) {
  611.                 element.down('div.truncated_full_value').addClassName('show')
  612.             }
  613.         });
  614.         Event.observe(element, 'mouseout', function(){
  615.             if (element.down('div.truncated_full_value')) {
  616.                 element.down('div.truncated_full_value').removeClassName('show')
  617.             }
  618.         });
  619.  
  620.     });
  621. }
  622. Event.observe(window, 'load', function(){
  623.    truncateOptions();
  624. });
  625.  
  626. Element.addMethods({
  627.     getInnerText: function(element)
  628.     {
  629.         element = $(element);
  630.         if(element.innerText && !Prototype.Browser.Opera) {
  631.             return element.innerText
  632.         }
  633.         return element.innerHTML.stripScripts().unescapeHTML().replace(/[\n\r\s]+/g, ' ').strip();
  634.     }
  635. });
  636.  
  637. /*
  638. if (!("console" in window) || !("firebug" in console))
  639. {
  640.     var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
  641.     "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
  642.  
  643.     window.console = {};
  644.     for (var i = 0; i < names.length; ++i)
  645.         window.console[names[i]] = function() {}
  646. }
  647. */
  648.  
  649. /**
  650.  * Executes event handler on the element. Works with event handlers attached by Prototype,
  651.  * in a browser-agnostic fashion.
  652.  * @param element The element object
  653.  * @param event Event name, like 'change'
  654.  *
  655.  * @example fireEvent($('my-input', 'click'));
  656.  */
  657. function fireEvent(element, event) {
  658.     if (document.createEvent) {
  659.         // dispatch for all browsers except IE before version 9
  660.         var evt = document.createEvent("HTMLEvents");
  661.         evt.initEvent(event, true, true ); // event type, bubbling, cancelable
  662.         return element.dispatchEvent(evt);
  663.     } else {
  664.         // dispatch for IE before version 9
  665.         var evt = document.createEventObject();
  666.         return element.fireEvent('on' + event, evt)
  667.     }
  668. }
  669.  
  670. /**
  671.  * Returns more accurate results of floating-point modulo division
  672.  * E.g.:
  673.  * 0.6 % 0.2 = 0.19999999999999996
  674.  * modulo(0.6, 0.2) = 0
  675.  *
  676.  * @param dividend
  677.  * @param divisor
  678.  */
  679. function modulo(dividend, divisor)
  680. {
  681.     var epsilon = divisor / 10000;
  682.     var remainder = dividend % divisor;
  683.  
  684.     if (Math.abs(remainder - divisor) < epsilon || Math.abs(remainder) < epsilon) {
  685.         remainder = 0;
  686.     }
  687.  
  688.     return remainder;
  689. }
  690.  
  691. /**
  692.  * createContextualFragment is not supported in IE9. Adding its support.
  693.  */
  694. if ((typeof Range != "undefined") && !Range.prototype.createContextualFragment)
  695. {
  696.     Range.prototype.createContextualFragment = function(html)
  697.     {
  698.         var frag = document.createDocumentFragment(),
  699.         div = document.createElement("div");
  700.         frag.appendChild(div);
  701.         div.outerHTML = html;
  702.         return frag;
  703.     };
  704. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement