Created
November 24, 2012 06:49
-
-
Save caratage/4138698 to your computer and use it in GitHub Desktop.
Reusable Custom Meta Boxes JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function(jQuery) { | |
jQuery('#media-items').bind('DOMNodeInserted',function(){ | |
jQuery('input[value="Insert into Post"]').each(function(){ | |
jQuery(this).attr('value','Use This Image'); | |
}); | |
}); | |
jQuery('.custom_upload_image_button').click(function() { | |
formfield = jQuery(this).siblings('.custom_upload_image'); | |
preview = jQuery(this).siblings('.custom_preview_image'); | |
tb_show('', 'media-upload.php?type=image&TB_iframe=true'); | |
window.send_to_editor = function(html) { | |
imgurl = jQuery('img',html).attr('src'); | |
classes = jQuery('img', html).attr('class'); | |
id = classes.replace(/(.*?)wp-image-/, ''); | |
formfield.val(id); | |
preview.attr('src', imgurl); | |
tb_remove(); | |
} | |
return false; | |
}); | |
jQuery('.custom_clear_image_button').click(function() { | |
var defaultImage = jQuery(this).parent().siblings('.custom_default_image').text(); | |
jQuery(this).parent().siblings('.custom_upload_image').val(''); | |
jQuery(this).parent().siblings('.custom_preview_image').attr('src', defaultImage); | |
return false; | |
}); | |
jQuery('.repeatable-add').click(function() { | |
field = jQuery(this).closest('td').find('.custom_repeatable li:last').clone(true); | |
fieldLocation = jQuery(this).closest('td').find('.custom_repeatable li:last'); | |
jQuery('input', field).val('').attr('name', function(index, name) { | |
return name.replace(/(\d+)/, function(fullMatch, n) { | |
return Number(n) + 1; | |
}); | |
}) | |
field.insertAfter(fieldLocation, jQuery(this).closest('td')) | |
return false; | |
}); | |
jQuery('.repeatable-remove').click(function(){ | |
jQuery(this).parent().remove(); | |
return false; | |
}); | |
jQuery('.custom_repeatable').sortable({ | |
opacity: 0.6, | |
revert: true, | |
cursor: 'move', | |
handle: '.sort' | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment