Skip to content

Instantly share code, notes, and snippets.

@joeydsmith
Created November 21, 2014 16:13
Show Gist options
  • Save joeydsmith/9eb5c9bb434464c3af10 to your computer and use it in GitHub Desktop.
Save joeydsmith/9eb5c9bb434464c3af10 to your computer and use it in GitHub Desktop.
jQuery(document).ready(function(){
jQuery('.spark_sortable').each(function(){
jQuery(this).sortable({
update: function( event, ui ){
ui.item.parents('.spark_sortable').find('> div').each(function(){
jQuery(this).find('.update_order').val(jQuery(this).index());
})
var ui_item = ui.item;
ui.item.addClass('moved');
setTimeout(function(){
jQuery('.moved').removeClass('moved')
}, 1);
}
});
jQuery(this).disableSelection();
})
jQuery('.spark_tab-sortable').each(function(){
jQuery(this).sortable({
axis: 'x',
update: function( event, ui ){
ui.item.parents('ul').find('> li a').each(function(){
var target = jQuery(this).attr('data-tab-target');
jQuery(target).find('.update_order').val(jQuery(this).parents('li').index());
})
}
});
jQuery(this).disableSelection();
})
jQuery(document).on('focus', '.spark_ui-input input, .spark_ui-input textarea, .spark_ui-input select', function(){
if ( jQuery(this).parents('.spark_ui-input').find('.spark_ui-tooltip').length > 0 && jQuery(window).width() > 800 ) {
jQuery(this).parents('.spark_ui-input').find('.spark_ui-tooltip').stop().fadeIn();
}
})
jQuery(document).on('blur', '.spark_ui-input input, .spark_ui-input textarea, .spark_ui-input select', function(){
if ( jQuery(this).parents('.spark_ui-input').find('.spark_ui-tooltip').length > 0 && jQuery(window).width() > 800 ) {
jQuery(this).parents('.spark_ui-input').find('.spark_ui-tooltip').stop().fadeOut();
}
})
jQuery('.spark_tabs').each(function(){
jQuery(this).find('.spark_tab-group a').click(function(e){
e.preventDefault();
console.log(jQuery(this).attr('data-tab-target'));
jQuery(this).parents('.spark_tabs').find('.active').removeClass('active');
jQuery(this).addClass('active');
jQuery('.spark_tab-container').find(jQuery(this).attr('data-tab-target')).addClass('active');
})
jQuery(this).find('.spark_tab-group li:first-child a').click();
})
jQuery('#add_new_custom_field').click(function(e){
e.preventDefault();
var _target = jQuery('#convio_form_fields');
var _clone = _target.find('.active').last();
var defaultName = 'My Custom Element';
_clone.clone().appendTo(_target).addClass('is_custom').each(function(){
jQuery(this).find('.elementName').val(defaultName);
jQuery(this).find('.field-required').val('false');
jQuery(this).find('.field-type').val('text');
jQuery(this).find('.convio_options').hide();
});
})
jQuery(document).on('click', '.delete_row', function(){
var _target = jQuery(this).parents('div[class*="donation_field"]');
_target.remove();
})
jQuery(document).live('each', '.field-nicename', function(i){
var current = jQuery(this);
value;
current.on('keyup', function(){
value = jQuery(this).val();
console.log(value);
})
})
})
function changeFieldType(element){
var type = element.val();
if ( type == 'select' || type == 'radio' || type == 'checkbox') {
element.parents('.convio_api-donationField').find('.convio_options').css({'display' : 'table'});
} else {
element.parents('.convio_api-donationField').find('.convio_options').hide();
}
}
function spark_ui_upload(element, action){
// Define Target Container
var target = jQuery(element).parents('.spark_ui-input');
// When action != 0, then New Image
if ( action != 0 ) {
// Open Media Library / Upload Window
wp.media.editor.open(element);
// Upload or Choose From Media Library Call Back
wp.media.editor.send.attachment = function(props, attachment) {
// Add Image ID to Hidden Input Field
target.find('input[type="hidden"]').val(attachment.id);
// Add Image Src to .spark_ui-imageHold and show
target.find('img').attr('src', attachment.url).removeClass('hidden');
}
} else {
// Remove Image ID from Hidden Input Field
alert("removed image");
// Remove Image Src from .spark_ui-imageHold and hide
alert("removed image");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment