js 封装 js

原创
2014/11/07 14:33
阅读数 217

define(['jquery'], function($) { var orderSummary = { $el: $('.summary-totals'), updateUrl : '../checkout/orderSummaryContentJson.jsp', cartRemoveUpdateUrl : '../cartridges/cart/subTotalContainer.jsp', orderComfirmSummaryUrl : '../checkout/orderReviewInfoSummaryContainer.jsp', bindChange : function() { this.$el = $('.summary-totals'); if($('.js-estimated').length) { $('.js-estimated').off('change').on('change', function() { var data={ changeShippingMethod: $('#changeShippingMethod').val(), selectedShippingMethod : $(this).val(), zipCode : $('.js-zipCode').val() ? $('.js-zipCode').val() : '' }; orderSummary.update(data); }); $('.js-estimated').simSelect(); } }, render: function(data) { var self = this; self.$el.find('span.js-order-subTotal').text(self.formatMoney(data.ship.subTotal)); self.$el.find('span.js-order-shipping').text(self.formatMoney(data.ship.shippingPrice)); self.$el.find('span.js-order-tax').text(self.formatMoney(data.ship.tax)); self.$el.find('span.js-order-total').text(self.formatMoney(data.ship.total)); }, update: function(data, cb, currentElm) { var self = this; $.get(self.updateUrl, data).done(function(result) { var result = JSON.parse(result); if(result.status) { if(cb && typeof cb === 'function') { cb(result); } else { $('.order-item').removeClass("changed"); $('.js-order-change-tip').addClass("hide"); self.$el.removeClass('changed'); } self.render(result); } else { self.showError(result.msg); } if(currentElm) currentElm.data('pending', false); }).fail(function(result) { if(currentElm) currentElm.data('pending', false); }); }, return orderSummary; }); //////////////////////////////////////////// function($, utils, header, acsCarousel, Handlebars, popover, quickview, orderSummary) { $(function() { var isTouch = Modernizr.touch; utils.init(); header.init();

$('#js-down-pdf').on('click', function(e) {
	$.post("/layouts/webAnalysis.jsp", {pageId : "/shoppingcartDocumentDownload"}).done(function(html) {
		$("#eventFlag").html(html);
	});
});

$(".also-like .jQ-carousel").acsCarousel({
	sliderLoop: false,
	sliderMoveNum: 6,
	sliderCanDrag: true,
	sliderList: 'carousel-content',
	sliderButtonCov: 'carousel-btn',
	sliderButtonPrev: 'carousel-prev',
	sliderButtonNext: 'carousel-next',
	sliderItem: 'carousel-item',
	callBack: function(obj, setting){
		obj.find(".item-num-note").html(setting.startItemNum+"-"+setting.endItemNum+" of "+ setting.sliderLength)
		utils.ellipsis();
	}
});

function isChangedQty(){
	var flag = false;
	$('.cart-item').each(function(){
		if($(this).data("isChangedQty")){
			flag = true;
			return;
		}
	});
	return flag;
}

function reClickSubmit(){
	if($('#hasError').val()=='true'){
		return;
	}
	if($('.jQ_checkoutNow').data('isClick')){
		$('.jQ_checkoutNow').data('isClick',false);
		$("#submit_checkoutNow_button").click();
		return;
	}
	if($('.jQ_checkoutNow_login').data('isClick')){
		$('.jQ_checkoutNow_login').data('isClick',false);
		$("#shoppingCart-login").submit();
		return;
	}
	if($('.jQ_guestCheckoutNow').data('isClick')){
		$('.jQ_guestCheckoutNow').data('isClick',false);
		$("#submit_checkoutAsGuestNow_button").click();
		return;
	}
}

//shoppingCart:recognize User do check out
$(document).on('click', '.jQ_checkoutNow', function(e){
	e.preventDefault();
	if($('#hasError').val()=='true'){
		return;
	}
	$(this).data('isClick',true);
	if(isChangedQty()){
		return;
	}
	$("#submit_checkoutNow_button").click();
	$(this).data('isClick',false);
});

$(document).on('click', '.jQ_checkoutNow_login', function(e){
	e.preventDefault();
	if($('#hasError').val()=='true'){
		return;
	}
	$(this).data('isClick',true);
	if(isChangedQty()){
		return;
	}
	$("#shoppingCart-login").submit();
	$(this).data('isClick',false);
});

//shoppingCart:guest User do check out
$(document).on('click', '.jQ_guestCheckoutNow', function(e){
	e.preventDefault();
	if($('#hasError').val()=='true'){
		return;
	}
	$(this).data('isClick',true);
	if(isChangedQty()){
		return;
	}
	$("#submit_checkoutAsGuestNow_button").click();
	$(this).data('isClick',false);
});

$(document).on('click', '.js-quick-view', function(e) {
	e.preventDefault();
	quickview.open(this);
	var productId = $(this).data('productid');
	$.post("/layouts/webAnalysis_ajax.jsp", {pageId : "/quickLook", productId : productId}).done(function(html) {
		$("#ensightenFlag").html(html);
	});
	$.post("/layouts/webAnalysis.jsp", {pageId : "/eventQuickLook", productId : productId}).done(function(code) {
		$("#eventFlag").html(code);
	});
});

/**
 * format The Price
 * 
 */
var formatMoney = function(number, places, symbol, thousand, decimal) {
	number = number || 0;
	places = !isNaN(places = Math.abs(places)) ? places : 2;
	symbol = symbol !== undefined ? symbol : "$";
	thousand = thousand || ",";
	decimal = decimal || ".";
	var negative = number < 0 ? "-" : "",
	i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + "",
	j = (j = i.length) > 3 ? j % 3 : 0;
	return negative + symbol + (j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : "");
}

//bind
orderSummary.bindChange();
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部