jQuery(document).ready(function($) {
/* Color picker. */
$('.colorSelector').each(function() {
var Othis = this;
var initialColor = $(Othis).next('input').attr('value');
$(this).ColorPicker({
color: initialColor,
onShow: function (colpkr) {
$(colpkr).fadeIn(500);
return false;
},
onHide: function (colpkr) {
$(colpkr).fadeOut(500);
return false;
},
onChange: function (hsb, hex, rgb) {
$(Othis).children('div').css('backgroundColor', '#' + hex);
$(Othis).next('input').attr('value','#' + hex);
}
});
});
/* Select element styling. */
$('.select-wrapper').each(function () {
$(this).prepend('' + $(this).find('option:selected').text() + '');
});
$('.select-wrapper select').live('change', function () {
$(this).prev('span').replaceWith('' + $(this).find('option:selected').text() + '');
});
$('.select-wrapper select').bind($.browser.msie ? 'click' : 'change', function(event) {
$(this).prev('span').replaceWith('' + $(this).find('option:selected').text() + '');
});
/* Use a custom function when working with the Media Upload modal window. */
$('input.upload-button').live("click", function () {
formfield = $(this).prev('input').attr('id');
formID = $(this).attr('rel');
tbframe_interval = setInterval( function() { $('#TB_iframeContent').contents().find('.savesend .button').val('Use This Image'); }, 2000 );
var button_title = '';
tb_show( button_title, 'media-upload.php?type=image&TB_iframe=true' );
return false;
});
window.original_send_to_editor = window.send_to_editor;
window.send_to_editor = function(html) {
if (formfield) {
clearInterval(tbframe_interval);
if ( $(html).html(html).find('img').length > 0 ) {
itemurl = $(html).html(html).find('img').attr('src');
} else {
var htmlBits = html.split("'");
itemurl = htmlBits[1];
var itemtitle = htmlBits[2];
itemtitle = itemtitle.replace( '>', '' );
itemtitle = itemtitle.replace( '', '' );
}
var image = /(^.*\.jpg|jpeg|png|gif|ico*)/gi;
var document = /(^.*\.pdf|doc|docx|ppt|pptx|odt*)/gi;
var audio = /(^.*\.mp3|m4a|ogg|wav*)/gi;
var video = /(^.*\.mp4|m4v|mov|wmv|avi|mpg|ogv|3gp|3g2*)/gi;
if ( itemurl.match(image) ) {
btnContent = '
';
}
$('#' + formfield).val(itemurl);
$('#' + formfield).siblings('.image-preview').show().html(btnContent);
tb_remove();
} else {
window.original_send_to_editor(html);
}
formfield = '';
}
});