225 lines
6.4 KiB
JavaScript
225 lines
6.4 KiB
JavaScript
/**
|
|
* @license Dual licensed under the MIT or GPL Version 2 licenses.
|
|
*/
|
|
calc_pos();
|
|
$('.button-minus, .button-plus').hide();
|
|
var price = $('.current-price');
|
|
var pricecurrencyval = $('meta[property="product:price:currency"]').attr('content');
|
|
if (null == currencySign)
|
|
var currencySign = pricecurrencyval;
|
|
if (null == currencyRate)
|
|
var currencyRate = 1;
|
|
if (null == currencyFormat)
|
|
var currencyFormat = 2;
|
|
if (null == currencyBlank)
|
|
var currencyBlank = 1;
|
|
|
|
function number_format (number, decimals, decPoint, thousandsSep) { // eslint-disable-line camelcase
|
|
// discuss at: http://locutus.io/php/number_format/
|
|
// example 1: number_format(1234.56)
|
|
// returns 1: '1,235'
|
|
// example 2: number_format(1234.56, 2, ',', ' ')
|
|
// returns 2: '1 234,56'
|
|
// example 3: number_format(1234.5678, 2, '.', '')
|
|
// returns 3: '1234.57'
|
|
// example 4: number_format(67, 2, ',', '.')
|
|
// returns 4: '67,00'
|
|
// example 5: number_format(1000)
|
|
// returns 5: '1,000'
|
|
// example 6: number_format(67.311, 2)
|
|
// returns 6: '67.31'
|
|
// example 7: number_format(1000.55, 1)
|
|
// returns 7: '1,000.6'
|
|
// example 8: number_format(67000, 5, ',', '.')
|
|
// returns 8: '67.000,00000'
|
|
// example 9: number_format(0.9, 0)
|
|
// returns 9: '1'
|
|
// example 10: number_format('1.20', 2)
|
|
// returns 10: '1.20'
|
|
// example 11: number_format('1.20', 4)
|
|
// returns 11: '1.2000'
|
|
// example 12: number_format('1.2000', 3)
|
|
// returns 12: '1.200'
|
|
// example 13: number_format('1 000,50', 2, '.', ' ')
|
|
// returns 13: '100 050.00'
|
|
// example 14: number_format(1e-8, 8, '.', '')
|
|
// returns 14: '0.00000001'
|
|
number = (number + '').replace(/[^0-9+\-Ee.]/g, '')
|
|
var n = !isFinite(+number) ? 0 : +number
|
|
var prec = !isFinite(+decimals) ? 0 : Math.abs(decimals)
|
|
var sep = (typeof thousandsSep === 'undefined') ? ',' : thousandsSep
|
|
var dec = (typeof decPoint === 'undefined') ? '.' : decPoint
|
|
var s = ''
|
|
var toFixedFix = function (n, prec) {
|
|
var k = Math.pow(10, prec)
|
|
return '' + (Math.round(n * k) / k)
|
|
.toFixed(prec)
|
|
}
|
|
// @todo: for IE parseFloat(0.55).toFixed(0) = 0;
|
|
s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.')
|
|
if (s[0].length > 3) {
|
|
s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep)
|
|
}
|
|
if ((s[1] || '').length < prec) {
|
|
s[1] = s[1] || ''
|
|
s[1] += new Array(prec - s[1].length + 1).join('0')
|
|
}
|
|
return s.join(dec)
|
|
}
|
|
|
|
function ps_round_half_up(value, precision)
|
|
{
|
|
var mul = Math.pow(10, precision);
|
|
var val = value * mul;
|
|
|
|
var next_digit = Math.floor(val * 10) - 10 * Math.floor(val);
|
|
if (next_digit >= 5)
|
|
val = Math.ceil(val);
|
|
else
|
|
val = Math.floor(val);
|
|
|
|
return val / mul;
|
|
}
|
|
|
|
function ps_round(value, places)
|
|
{
|
|
if (typeof(roundMode) === 'undefined')
|
|
roundMode = 2;
|
|
if (typeof(places) === 'undefined')
|
|
places = 2;
|
|
|
|
var method = roundMode;
|
|
|
|
if (method === 0)
|
|
return ceilf(value, places);
|
|
else if (method === 1)
|
|
return floorf(value, places);
|
|
else if (method === 2)
|
|
return ps_round_half_up(value, places);
|
|
else if (method == 3 || method == 4 || method == 5)
|
|
{
|
|
// From PHP Math.c
|
|
var precision_places = 14 - Math.floor(ps_log10(Math.abs(value)));
|
|
var f1 = Math.pow(10, Math.abs(places));
|
|
|
|
if (precision_places > places && precision_places - places < 15)
|
|
{
|
|
var f2 = Math.pow(10, Math.abs(precision_places));
|
|
if (precision_places >= 0)
|
|
tmp_value = value * f2;
|
|
else
|
|
tmp_value = value / f2;
|
|
|
|
tmp_value = ps_round_helper(tmp_value, roundMode);
|
|
|
|
/* now correctly move the decimal point */
|
|
f2 = Math.pow(10, Math.abs(places - precision_places));
|
|
/* because places < precision_places */
|
|
tmp_value /= f2;
|
|
}
|
|
else
|
|
{
|
|
/* adjust the value */
|
|
if (places >= 0)
|
|
tmp_value = value * f1;
|
|
else
|
|
tmp_value = value / f1;
|
|
|
|
if (Math.abs(tmp_value) >= 1e15)
|
|
return value;
|
|
}
|
|
|
|
tmp_value = ps_round_helper(tmp_value, roundMode);
|
|
if (places > 0)
|
|
tmp_value = tmp_value / f1;
|
|
else
|
|
tmp_value = tmp_value * f1;
|
|
|
|
return tmp_value;
|
|
}
|
|
}
|
|
|
|
function formatCurrency(price, currencyFormat, currencySign, currencyBlank) {
|
|
var blank = '';
|
|
price = parseFloat(parseFloat(price).toFixed(10));
|
|
price = ps_round(price, 2);
|
|
var priceDisplayPrecision = 2;
|
|
if (currencyBlank > 0)
|
|
blank = ' ';
|
|
if (currencyFormat == 1)
|
|
return (currencySign + blank + number_format(price, priceDisplayPrecision, ',', '.'));
|
|
if (currencyFormat == 2)
|
|
return (number_format(price, priceDisplayPrecision, ' ', ',') + blank + currencySign);
|
|
if (currencyFormat == 3)
|
|
return (currencySign + blank + number_format(price, priceDisplayPrecision, '.', ','));
|
|
if (currencyFormat == 4)
|
|
return (number_format(price, priceDisplayPrecision, ',', '.') + blank + currencySign);
|
|
if (currencyFormat == 5)
|
|
return (currencySign + blank + number_format(price, priceDisplayPrecision, '\'', '.'));
|
|
return price;
|
|
}
|
|
|
|
this.imagePreview = function(){
|
|
/* CONFIG */
|
|
|
|
xOffset = 10;
|
|
yOffset = 30;
|
|
|
|
// these 2 variable determine popup's distance from the cursor
|
|
// you might want to adjust to get the right result
|
|
|
|
/* END CONFIG */
|
|
$("a.preview").hover(function(e){
|
|
this.t = this.title;
|
|
this.title = "";
|
|
var c = (this.t != "") ? "<br/>" + this.t : "";
|
|
$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");
|
|
$("#preview")
|
|
.css("top",(e.pageY - xOffset) + "px")
|
|
.css("left",(e.pageX + yOffset) + "px")
|
|
.css("z-index", "10000")
|
|
.fadeIn("fast");
|
|
},
|
|
function(){
|
|
this.title = this.t;
|
|
$("#preview").remove();
|
|
});
|
|
$("a.preview").mousemove(function(e){
|
|
$("#preview")
|
|
.css("top",(e.pageY - xOffset) + "px")
|
|
.css("left",(e.pageX + yOffset) + "px");
|
|
});
|
|
};
|
|
|
|
|
|
// starting the script on page load
|
|
$(document).ready(function(){
|
|
imagePreview();
|
|
});
|
|
|
|
function increaseValue(id, stepType) {
|
|
if (stepType)
|
|
s = Number(stepType);
|
|
else
|
|
s = Number(step);
|
|
var value = parseFloat(document.getElementById(id).value, 10);
|
|
value = value + s;
|
|
if((value % 1 < 1) && (value % 1 != 0))
|
|
document.getElementById(id).value = parseFloat(value).toFixed(2);
|
|
else
|
|
document.getElementById(id).value = parseFloat(value);
|
|
}
|
|
|
|
function decreaseValue(id, stepType) {
|
|
if (stepType)
|
|
s = Number(stepType);
|
|
else
|
|
s = Number(step);
|
|
var value = parseFloat(document.getElementById(id).value, 10);
|
|
value = isNaN(value) ? 0 : value;
|
|
value = value - s;
|
|
if((value % 1 < 1) && (value % 1 != 0))
|
|
document.getElementById(id).value = parseFloat(value).toFixed(2);
|
|
else
|
|
document.getElementById(id).value = parseFloat(value);
|
|
} |