(function($) { "use strict"; rianaWidget = { // Call this from the upload button to initiate the upload frame. uploader : function( widget_id, widget_id_string ) { var frame = wp.media({ title : TribeImageWidget.frame_title, multiple : false, library : { type : 'image' }, button : { text : TribeImageWidget.button_title } }); // Handle results from media manager. frame.on('close',function( ) { var attachments = frame.state().get('selection').toJSON(); rianaWidget.render( widget_id, widget_id_string, attachments[0] ); }); frame.open(); return false; }, // Output Image preview and populate widget form. render : function( widget_id, widget_id_string, attachment ) { $("#" + widget_id_string + 'preview').html(rianaWidget.imgHTML( attachment )); $("#" + widget_id_string + 'fields').slideDown(); $("#" + widget_id_string + 'attachment_id').val(attachment.id); $("#" + widget_id_string + 'imageurl').val(attachment.url); $("#" + widget_id_string + 'aspect_ratio').val(attachment.width/attachment.height); $("#" + widget_id_string + 'width').val(attachment.width); $("#" + widget_id_string + 'height').val(attachment.height); $("#" + widget_id_string + 'size').val('full'); $("#" + widget_id_string + 'custom_size_selector').slideDown(); rianaWidget.toggleSizes( widget_id, widget_id_string ); }, // Update input fields if it is empty updateInputIfEmpty : function( widget_id_string, name, value ) { var field = $("#" + widget_id_string + name); if ( field.val() == '' ) { field.val(value); } }, // Render html for the image. imgHTML : function( attachment ) { var img_html = '