jQuery(function($){
var obj = {
mbtn : '#aliproduct',
modal : 'ae_modal_1',
close : 'button.media-modal-close',
content : '.media-modal-content .media-frame'
},
imgsize = {
'thumb' : '_50x50.jpg',
'medium' : '_220x220.jpg',
'full' : ''
},
act = {
review : $('form.review'),
categoryId : '[name="categories"]',
keywords : '[name="keywords"]',
priceFrom : '[name="pricefrom"]',
priceTo : '[name="priceto"]',
promotionFrom : '[name="promotionfrom"]',
promotionTo : '[name="promotionto"]',
creditScoreFrom : '[name="creditScoreFrom"]',
creditScoreTo : '[name="creditScoreTo"]',
send : 'form.review [name="search-submit"]',
content : '#request-content',
output : '#request-data',
load : '#request-data .load',
back : '#back-to-search a',
shortcode : '#indert-shortcode',
setup : 'button.setup',
inner : '.media-frame-content .inner-content',
mcontent : '.media-frame-content .modal-content-single',
layout : '#layout',
alignment : '#alignment',
title : 'input[name="title"]',
size : '#img-size'
};
$(document).on('click', '#'+obj.modal+' '+act.setup, ae_setup_product);
$(document).on('click', '#'+obj.modal+' '+act.back, ae_back_search);
$(document).on('click', '#'+obj.modal+' '+act.shortcode, ae_save_shortcode);
$(document).on('change', '#'+obj.modal+' '+act.size, function(){
var size = $(this).val(),
mc = $('#'+obj.modal+' '+act.mcontent),
path = mc.find('[name="title"]').data('image');
size = imgsize[size];
mc.find('.type-view img').attr('src', path+''+size);
});
$(document).on('change', '#'+obj.modal+' '+act.alignment, function(){
var align = $(this).val();
$('#'+obj.modal+' '+act.mcontent+' .type-view').
removeClass('text-right text-left text-center').
addClass('text-'+align);
});
$(document).on('keyup', '#'+obj.modal+' '+act.title, function(){
var mc = $('#'+obj.modal+' '+act.mcontent),
title = $(this).val();
mc.find('h3 a.link').html(title);
});
$(document).on('change', '#'+obj.modal+' '+act.layout, function(){
var size = $(this).val(),
mc = $('#'+obj.modal+' '+act.mcontent);
mc.find('.type-view').hide();
mc.find('.type-view#'+size).show();
});
$(document).on('change', '#'+obj.modal+' '+act.layout, function(){
var size = $(this).val(),
mc = $('#'+obj.modal+' '+act.mcontent);
mc.find('.type-view').hide();
mc.find('.type-view#'+size).show();
});
$(document).on('click', obj.mbtn, ae_open_modal);
$(document).on('click', '#'+obj.modal+' '+obj.close, ae_close_modal);
$(document).mouseup(
function (e){
var container = $('#'+obj.modal+' .media-modal');
if (!container.is(e.target) && container.has(e.target).length === 0){
ae_close_modal();
}
}
);
/* review */
$(document).on( 'click', act.send, function(e) {
e.preventDefault();
ajaxReview( 1 );
});
function ae_setup_product(e) {
e.preventDefault();
var th = $(this).parents('tr'),
url = th.data('url'),
image = th.data('image'),
price = th.data('price'),
title = th.find('span.this_title').text(),
mc = $('#'+obj.modal+' '+act.mcontent);
$.ajaxQueue({
url : ajaxurl,
data : {action : 'aliprice_get_promotion', link:url},
type : "POST",
success : function(data){
var response = $.parseJSON(data);
if( typeof response.error == 'undefined' ) {
mc.find('a.link').attr('href', response.success);
mc.find('.thumb a.link').html('
');
mc.find('.content-inner .thumb').html('
');
mc.find('h3 a.link').html(title);
mc.find('p.price span').html(price);
mc.find('[name="title"]').val(title).data('image', image);
mc.find('[name="img-size"] option[value="medium"]').attr("selected","selected");
mc.find('[name="alignment"] option[value="left"]').attr("selected","selected");
mc.find('[name="layout"] option[value="img-left-text-right"]').attr("selected","selected");
mc.find('.type-view').hide();
mc.find('.type-view#img-left-text-right').show();
$('#'+obj.modal+' '+act.inner).hide();
mc.show();
}
}
});
}
function ae_back_search(e) {
e.preventDefault();
$('#'+obj.modal+' '+act.mcontent).hide();
$('#'+obj.modal+' '+act.inner).show();
}
function ae_save_shortcode(e) {
var id = 'content',
editor = tinyMCE.get(id),
textArea = $('textarea#' + id),
content = '';
var mc = $('#'+obj.modal+' '+act.mcontent),
h = $('#'+obj.modal),
link = mc.find('a.link').attr('href'),
title = mc.find('[name="title"]').val(),
price = mc.find('p.price span').html(),
image = mc.find('[name="title"]').data('image'),
size = mc.find('[name="img-size"]').val(),
align = mc.find('[name="alignment"]').val(),
layout = mc.find('[name="layout"]').val(),
target = ( mc.find('[name="target"]:checked').length > 0 ) ? 1 : 0,
nofollow = ( mc.find('[name="nofollow"]:checked').length > 0 ) ? 1 : 0;
content = '[aebox title="'+title+'" price="'+price+'" url="'+link+'" image="'+image+'" size="'+size+'" align="'+align+'" layout="'+layout+'" target="'+target+'" nofollow="'+nofollow+'"]';
e.preventDefault();
$('#'+obj.modal+' '+act.mcontent).hide();
$('#'+obj.modal+' '+act.inner).show();
if (textArea.length > 0 && textArea.is(':visible')) {
var pos = textArea.getCursorPosition();
textArea.setCursorPosition(pos);
textArea.insertAtCursor(content);
}
else {
editor.execCommand('mceInsertContent',false, content);
}
mc.hide();
h.hide();
}
function ae_open_modal( ) {
if( $('#'+obj.modal).length === 0 ) {
var content = $('script[type="text/html"]#tmpl-media-modal').html();
$('body').append('
| '+str+' | '; }); output += '||||||
|---|---|---|---|---|---|---|
![]() | \
'+str.productTitle+' \ | \
'+str.salePrice+'/'+str.packageType+' | \'+rate+'% | \US $'+commission+' | \'+str.volume+' | \'+str.evaluateScore+' | \