';
slidesContainer.append(newSlide);
var nSlide = slidesContainer.find('.temphide');
nSlide.fadeIn('fast', function() {
$(this).removeClass('temphide');
});
optionsframework_file_bindings(); // re-initialise upload image..
return false; //prevent jumps, as always..
});
//Sort slides
jQuery('.slider').find('ul').each( function() {
var id = jQuery(this).attr('id');
$('#'+ id).sortable({
placeholder: "placeholder",
opacity: 0.6,
handle: ".slide_header",
cancel: "a"
});
});
/** Sorter (Layout Manager) */
jQuery('.sorter').each( function() {
var id = jQuery(this).attr('id');
$('#'+ id).find('ul').sortable({
items: 'li',
placeholder: "placeholder",
connectWith: '.sortlist_' + id,
opacity: 0.6,
update: function() {
$(this).find('.position').each( function() {
var listID = $(this).parent().attr('id');
var parentID = $(this).parent().parent().attr('id');
parentID = parentID.replace(id + '_', '')
var optionID = $(this).parent().parent().parent().attr('id');
$(this).prop("name", optionID + '[' + parentID + '][' + listID + ']');
});
}
});
});
/** Ajax Backup & Restore MOD */
//backup button
$('#of_backup_button').live('click', function(){
var answer = confirm("Click OK to backup your current saved options.")
if (answer){
var clickedObject = $(this);
var clickedID = $(this).attr('id');
var nonce = $('#security').val();
var data = {
action: 'of_ajax_post_action',
type: 'backup_options',
security: nonce
};
$.post(ajaxurl, data, function(response) {
//check nonce
if(response==-1){ //failed
var fail_popup = $('#of-popup-fail');
fail_popup.fadeIn();
window.setTimeout(function(){
fail_popup.fadeOut();
}, 2000);
}
else {
var success_popup = $('#of-popup-save');
success_popup.fadeIn();
window.setTimeout(function(){
location.reload();
}, 1000);
}
});
}
return false;
});
//restore button
$('#of_restore_button').live('click', function(){
var answer = confirm("'Warning: All of your current options will be replaced with the data from your last backup! Proceed?")
if (answer){
var clickedObject = $(this);
var clickedID = $(this).attr('id');
var nonce = $('#security').val();
var data = {
action: 'of_ajax_post_action',
type: 'restore_options',
security: nonce
};
$.post(ajaxurl, data, function(response) {
//check nonce
if(response==-1){ //failed
var fail_popup = $('#of-popup-fail');
fail_popup.fadeIn();
window.setTimeout(function(){
fail_popup.fadeOut();
}, 2000);
}
else {
var success_popup = $('#of-popup-save');
success_popup.fadeIn();
window.setTimeout(function(){
location.reload();
}, 1000);
}
});
}
return false;
});
/** Ajax Transfer (Import/Export) Option */
$('#of_import_button').live('click', function(){
var answer = confirm("Click OK to import options.")
if (answer){
var clickedObject = $(this);
var clickedID = $(this).attr('id');
var nonce = $('#security').val();
var import_data = $('#export_data').val();
var data = {
action: 'of_ajax_post_action',
type: 'import_options',
security: nonce,
data: import_data
};
$.post(ajaxurl, data, function(response) {
var fail_popup = $('#of-popup-fail');
var success_popup = $('#of-popup-save');
//check nonce
if(response==-1){ //failed
fail_popup.fadeIn();
window.setTimeout(function(){
fail_popup.fadeOut();
}, 2000);
}
else
{
success_popup.fadeIn();
window.setTimeout(function(){
location.reload();
}, 1000);
}
});
}
return false;
});
/** AJAX Save Options */
$('#of_save').live('click',function() {
var nonce = $('#security').val();
$('.ajax-loading-img').fadeIn();
//get serialized data from all our option fields
var serializedReturn = $('#of_form :input[name][name!="security"][name!="of_reset"]').serialize();
var data = {
type: 'save',
action: 'of_ajax_post_action',
security: nonce,
data: serializedReturn
};
$.post(ajaxurl, data, function(response) {
var success = $('#of-popup-save');
var fail = $('#of-popup-fail');
var loading = $('.ajax-loading-img');
loading.fadeOut();
if (response==1) {
success.fadeIn();
} else {
fail.fadeIn();
}
window.setTimeout(function(){
success.fadeOut();
fail.fadeOut();
}, 2000);
});
return false;
});
/* AJAX Options Reset */
$('#of_reset').click(function() {
//confirm reset
var answer = confirm("Click OK to reset. All settings will be lost and replaced with default settings!");
//ajax reset
if (answer){
var nonce = $('#security').val();
$('.ajax-reset-loading-img').fadeIn();
var data = {
type: 'reset',
action: 'of_ajax_post_action',
security: nonce,
};
$.post(ajaxurl, data, function(response) {
var success = $('#of-popup-reset');
var fail = $('#of-popup-fail');
var loading = $('.ajax-reset-loading-img');
loading.fadeOut();
if (response==1)
{
success.fadeIn();
window.setTimeout(function(){
location.reload();
}, 1000);
}
else
{
fail.fadeIn();
window.setTimeout(function(){
fail.fadeOut();
}, 2000);
}
});
}
return false;
});
/** Tipsy @since v1.3 */
if (jQuery().tipsy) {
$('.typography-size, .typography-height, .typography-face, .typography-style, .of-typography-color').tipsy({
fade: true,
gravity: 's',
opacity: 0.7,
});
}
/**
* JQuery UI Slider function
* Dependencies : jquery, jquery-ui-slider
* Feature added by : Smartik - http://smartik.ws/
* Date : 03.17.2013
*/
jQuery('.smof_sliderui').each(function() {
var obj = jQuery(this);
var sId = "#" + obj.data('id');
var val = parseInt(obj.data('val'));
var min = parseInt(obj.data('min'));
var max = parseInt(obj.data('max'));
var step = parseInt(obj.data('step'));
//slider init
obj.slider({
value: val,
min: min,
max: max,
step: step,
range: "min",
slide: function( event, ui ) {
jQuery(sId).val( ui.value );
}
});
});
/**
* Switch
* Dependencies : jquery
* Feature added by : Smartik - http://smartik.ws/
* Date : 03.17.2013
*/
jQuery(".cb-enable").click(function(){
var parent = $(this).parents('.switch-options');
jQuery('.cb-disable',parent).removeClass('selected');
jQuery(this).addClass('selected');
jQuery('.main_checkbox',parent).attr('checked', true);
//fold/unfold related options
var obj = jQuery(this);
var $fold='.f_'+obj.data('id');
jQuery($fold).slideDown('normal', "swing");
});
jQuery(".cb-disable").click(function(){
var parent = $(this).parents('.switch-options');
jQuery('.cb-enable',parent).removeClass('selected');
jQuery(this).addClass('selected');
jQuery('.main_checkbox',parent).attr('checked', false);
//fold/unfold related options
var obj = jQuery(this);
var $fold='.f_'+obj.data('id');
jQuery($fold).slideUp('normal', "swing");
});
//disable text select(for modern chrome, safari and firefox is done via CSS)
if (($.browser.msie && $.browser.version < 10) || $.browser.opera) {
$('.cb-enable span, .cb-disable span').find().attr('unselectable', 'on');
}
/**
* Google Fonts
* Dependencies : google.com, jquery
* Feature added by : Smartik - http://smartik.ws/
* Date : 03.17.2013
*/
function GoogleFontSelect( slctr, mainID ){
var _selected = $(slctr).val(); //get current value - selected and saved
var _linkclass = 'style_link_'+ mainID;
var _previewer = mainID +'_ggf_previewer';
if( _selected ){ //if var exists and isset
//Check if selected is not equal with "Select a font" and execute the script.
if ( _selected !== 'none' && _selected !== 'Select a font' ) {
//remove other elements crested in
$( '.'+ _linkclass ).remove();
//replace spaces with "+" sign
var the_font = _selected.replace(/\s+/g, '+');
//add reference to google font family
$('head').append('');
//show in the preview box the font
$('.'+ _previewer ).css('font-family', _selected +', sans-serif' );
}else{
//if selected is not a font remove style "font-family" at preview box
$('.'+ _previewer ).css('font-family', '' );
}
}
}
//init for each element
jQuery( '.google_font_select' ).each(function(){
var mainID = jQuery(this).attr('id');
GoogleFontSelect( this, mainID );
});
//init when value is changed
jQuery( '.google_font_select' ).change(function(){
var mainID = jQuery(this).attr('id');
GoogleFontSelect( this, mainID );
});
/**
* Media Uploader
* Dependencies : jquery, wp media uploader
* Feature added by : Smartik - http://smartik.ws/
* Date : 05.28.2013
*/
function optionsframework_add_file(event, selector) {
var upload = $(".uploaded-file"), frame;
var $el = $(this);
event.preventDefault();
// If the media frame already exists, reopen it.
if ( frame ) {
frame.open();
return;
}
// Create the media frame.
frame = wp.media({
// Set the title of the modal.
title: $el.data('choose'),
// Customize the submit button.
button: {
// Set the text of the button.
text: $el.data('update'),
// Tell the button not to close the modal, since we're
// going to refresh the page when the image is selected.
close: false
}
});
// When an image is selected, run a callback.
frame.on( 'select', function() {
// Grab the selected attachment.
var attachment = frame.state().get('selection').first();
frame.close();
selector.find('.upload').val(attachment.attributes.url);
if ( attachment.attributes.type == 'image' ) {
selector.find('.screenshot').empty().hide().append('').slideDown('fast');
}
selector.find('.media_upload_button').unbind();
selector.find('.remove-image').show().removeClass('hide');//show "Remove" button
selector.find('.of-background-properties').slideDown();
optionsframework_file_bindings();
});
// Finally, open the modal.
frame.open();
}
function optionsframework_remove_file(selector) {
selector.find('.remove-image').hide().addClass('hide');//hide "Remove" button
selector.find('.upload').val('');
selector.find('.of-background-properties').hide();
selector.find('.screenshot').slideUp();
selector.find('.remove-file').unbind();
// We don't display the upload button if .upload-notice is present
// This means the user doesn't have the WordPress 3.5 Media Library Support
if ( $('.section-upload .upload-notice').length > 0 ) {
$('.media_upload_button').remove();
}
optionsframework_file_bindings();
}
function optionsframework_file_bindings() {
$('.remove-image, .remove-file').on('click', function() {
optionsframework_remove_file( $(this).parents('.section-upload, .section-media, .slide_body') );
});
$('.media_upload_button').unbind('click').click( function( event ) {
optionsframework_add_file(event, $(this).parents('.section-upload, .section-media, .slide_body'));
});
}
optionsframework_file_bindings();
}); //end doc ready