????
| Current Path : /home2/morganrand/www/wp-content-bkp/themes/wanderfuls/framework/addons/assets/ |
| Current File : /home2/morganrand/www/wp-content-bkp/themes/wanderfuls/framework/addons/assets/widget_areas.js |
(function($) {
"use strict";
var TB_Widget_Areas = function(){
if ( $('.sidebars-column-2').length !== 0 ) {
this.widget_wrap = $('.sidebars-column-2');
} else {
this.widget_wrap = $('.sidebars-column-1');
}
this.widget_area = $('#widgets-right');
this.parent_area = $('.widget-liquid-right');
this.widget_template = $('#tb-add-widget-template');
this.add_form_html();
this.add_del_button();
this.bind_events();
};
TB_Widget_Areas.prototype = {
add_form_html: function() {
this.widget_wrap.append( this.widget_template.html() );
this.widget_name = this.widget_wrap.find('input[name="tb-add-widget-input"]');
this.nonce = this.widget_wrap.find('input[name="tb-nonce"]').val();
},
add_del_button: function() {
var i = 0;
this.widget_area.find('.sidebar-tb-custom .widgets-sortables').each(function() {
if ( i >= tbWidgetAreasLocalize.count ) {
var widgetID = $(this).attr('id')
$(this).append('<div class="tb-widget-area-footer"><div class="tb-widget-area-id">ID:<span class="description"> '+ widgetID +'</span></div><div class="tb-widget-area-buttons"><a href="#" class="tb-widget-area-delete button-primary">'+ tbWidgetAreasLocalize.delete +'</a><a href="#" class="tb-widget-area-delete-cancel button-secondary">'+ tbWidgetAreasLocalize.cancel +'</a><a href="#" class="tb-widget-area-delete-confirm button-primary">'+ tbWidgetAreasLocalize.confirm +'</a></div></div>')
}
i++;
});
},
bind_events: function() {
this.parent_area.on( 'click', 'a.tb-widget-area-delete', function(event) {
event.preventDefault()
$(this).hide();
$(this).next('a.tb-widget-area-delete-cancel').show().next('a.tb-widget-area-delete-confirm').show();
});
this.parent_area.on( 'click', 'a.tb-widget-area-delete-cancel', function(event) {
event.preventDefault()
$(this).hide();
$(this).prev('a.tb-widget-area-delete').show();
$(this).next('a.tb-widget-area-delete-confirm').hide();
});
this.parent_area.on('click', 'a.tb-widget-area-delete-confirm', $.proxy( this.delete_widget_area, this));
//this.parent_area.on('click', '.addWidgetArea-button', $.proxy( this.add_widget_area, this));
$( "#addWidgetAreaForm" ).submit(function() {
$.proxy( this.add_widget_area, this)
});
},
add_widget_area: function(e) {
e.preventDefault();
// console.log(e);
// alert('yo'+$('#tb-add-widget-input').val());
return false;
},
//delete the widget_area area with all widgets within, then re calculate the other widget_area ids and re save the order
delete_widget_area: function(e) {
var widget = $(e.currentTarget).parents('.widgets-holder-wrap:eq(0)'),
title = widget.find('.sidebar-name h3'),
spinner = title.find('.spinner'),
widget_name = $.trim(title.text()),
obj = this;
widget.addClass('closed');
spinner.css('display', 'inline-block');
$.ajax({
type: "POST",
url: window.ajaxurl,
data: {
action: 'tb_delete_widget_area',
name: widget_name,
_wpnonce: obj.nonce
},
success: function(response) {
if(response.trim() == 'widget_area-deleted') {
widget.slideUp(200).remove();
}
}
});
}
};
$(function() {
new TB_Widget_Areas();
});
})(jQuery);