/*jslint browser: true, devel: true, indent: 4, maxerr: 50, sub: true */ /*global jQuery, tb_show, tb_remove */ /** * Custom jQuery for Custom Metaboxes and Fields */ jQuery(document).ready(function (jQuery) { 'use strict'; var formfield; /** * Initialize timepicker (this will be moved inline in a future release) */ jQuery('.bsf_timepicker').each(function () { jQuery('#' + jQuery(this).attr('id')).timePicker({ startTime: "07:00", endTime: "22:00", show24Hours: false, separator: ':', step: 30 }); }); /** * Initialize jQuery UI datepicker (this will be moved inline in a future release) */ jQuery('.bsf_datepicker').each(function () { //jQuery('#' + jQuery(this).attr('id')).datepicker(); jQuery('#' + jQuery(this).attr('id')).datepicker({ dateFormat: 'yy-mm-dd' }); // For more options see http://jqueryui.com/demos/datepicker/#option-dateFormat }); // Wrap date picker in class to narrow the scope of jQuery UI CSS and prevent conflicts jQuery("#ui-datepicker-div").wrap('
'); /** * Initialize color picker */ if (typeof jQuery.wp === 'object' && typeof jQuery.wp.wpColorPicker === 'function') { jQuery('input:text.bsf_colorpicker').wpColorPicker(); } else { jQuery('input:text.bsf_colorpicker').each(function (i) { jQuery(this).after(''); jQuery('#picker-' + i).hide().farbtastic(jQuery(this)); }) .focus(function () { jQuery(this).next().show(); }) .blur(function () { jQuery(this).next().hide(); }); } /** * File and image upload handling */ jQuery('.bsf_upload_file').change(function () { formfield = jQuery(this).attr('name'); jQuery('#' + formfield + '_id').val(""); }); jQuery('.bsf_upload_button').live('click', function () { var buttonLabel; formfield = jQuery(this).prev('input').attr('name'); buttonLabel = 'Use as ' + jQuery('label[for=' + formfield + ']').text(); tb_show('', 'media-upload.php?post_id=' + jQuery('#post_ID').val() + '&type=file&bsf_force_send=true&bsf_send_label=' + buttonLabel + '&TB_iframe=true'); return false; }); jQuery('.bsf_remove_file_button').live('click', function () { formfield = jQuery(this).attr('rel'); jQuery('input#' + formfield).val(''); jQuery('input#' + formfield + '_id').val(''); jQuery(this).parent().remove(); return false; }); window.original_send_to_editor = window.send_to_editor; window.send_to_editor = function (html) { var itemurl, itemclass, itemClassBits, itemid, htmlBits, itemtitle, image, uploadStatus = true; if (formfield) { if (jQuery(html).html(html).find('img').length > 0) { itemurl = jQuery(html).html(html).find('img').attr('src'); // Use the URL to the size selected. itemclass = jQuery(html).html(html).find('img').attr('class'); // Extract the ID from the returned class name. itemClassBits = itemclass.split(" "); itemid = itemClassBits[itemClassBits.length - 1]; itemid = itemid.replace('wp-image-', ''); } else { // It's not an image. Get the URL to the file instead. htmlBits = html.split("'"); // jQuery seems to strip out XHTML when assigning the string to an object. Use alternate method. itemurl = htmlBits[1]; // Use the URL to the file. itemtitle = htmlBits[2]; itemtitle = itemtitle.replace('>', ''); itemtitle = itemtitle.replace('', ''); itemid = ""; // TO DO: Get ID for non-image attachments. } image = /(jpe?g|png|gif|ico)jQuery/gi; if (itemurl.match(image)) { uploadStatus = ''; } else { // No output preview if it's not an image // Standard generic output if it's not an image. html = 'View File'; uploadStatus = '