$(document).ready(function(){ //Configuration Options var max_width = 400; //Sets the max width, in pixels, for every image var selector = 'img'; //Sets the syntax for finding the images. Defaults to all images. //For images inside of a particular element (id="abc") or class (class="abc"), //use '.abc img' or '#abc img' respectively. Don't leave off the img tag!!! //End configuration options. You don't need to change anything below here. $(selector).each(function(){ var width = $(this).width(); var height = $(this).height(); if (width > max_width) { //Set variables for manipulation var ratio = (height / width ); var new_width = max_width; var new_height = (new_width * ratio); //Shrink the image and add link to full-sized image $(this).height(new_height).width(new_width); $(this).hover(function(){ $(this).attr("title", "This image has been scaled down. Click to view the original image.") $(this).css("cursor","pointer"); }); $(this).click(function(){ window.location = $(this).attr("src"); }); } //ends if statement } //ends each function ); }); jQuery.fn.editInPlace = function(options) { /* DEFINE THE DEFAULT SETTINGS, SWITCH THEM WITH THE OPTIONS USER PROVIDES */ var settings = { url: "", params: "", field_type: "text", select_options: "", textarea_cols: "25", textarea_rows: "10", bg_over: "#ffc", bg_out: "transparent", saving_text: "Saving...", saving_image: "", default_text: "(Click here to add text)", select_text: "Choose new value", value_required: null, element_id: "element_id", update_value: "update_value", original_html: "original_html", save_button: '', cancel_button: '', show_buttons: false, on_blur: "save", callback: null, success: null, error: function(request){ alert("Failed to save value: " + request.responseText || 'Unspecified Error'); } }; if(options) { jQuery.extend(settings, options); } /* preload the loading icon if it exists */ if(settings.saving_image != ""){ var loading_image = new Image(); loading_image.src = settings.saving_image; } /* THIS FUNCTION WILL TRIM WHITESPACE FROM BEFORE/AFTER A STRING */ String.prototype.trim = function() { return this.replace(/^\s+/, '') .replace(/\s+$/, ''); }; /* THIS FUNCTION WILL ESCAPE ANY HTML ENTITIES SO "Quoted Values" work */ String.prototype.escape_html = function() { return this.replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """); }; /* CREATE THE INPLACE EDITOR */ return this.each(function(){ if(jQuery(this).html() == "") jQuery(this).html(settings.default_text); var editing = false; //save the original element - for change of scope var original_element = jQuery(this); var click_count = 0; jQuery(this) .mouseover(function(){ jQuery(this).css("background", settings.bg_over); }) .mouseout(function(){ jQuery(this).css("background", settings.bg_out); }) .click(function(){ click_count++; if(!editing) { editing = true; //save original text - for cancellation functionality var original_html = jQuery(this).html(); var buttons_code = (settings.show_buttons) ? settings.save_button + ' ' + settings.cancel_button : ''; //if html is our default text, clear it out to prevent saving accidentally if (original_html == settings.default_text) jQuery(this).html(''); if (settings.field_type == "textarea") { var use_field_type = ''; } else if(settings.field_type == "text") { var use_field_type = ''; } else if(settings.field_type == "select") { var optionsArray = settings.select_options.split(','); var use_field_type = ''; } /* insert the new in place form after the element they click, then empty out the original element */ jQuery(this).html('
'); }/* END- if(!editing) -END */ if(click_count == 1) { function cancelAction() { editing = false; click_count = 0; /* put the original background color in */ original_element.css("background", settings.bg_out); /* put back the original text */ original_element.html(original_html); return false; } function saveAction() { /* put the original background color in */ original_element.css("background", settings.bg_out); var this_elem = jQuery(this); var new_html = (this_elem.is('form')) ? this_elem.children(0).val() : this_elem.parent().children(0).val(); /* set saving message */ if(settings.saving_image != ""){ var saving_message = '