-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.rapidEdit.min.js
10 lines (10 loc) · 12.4 KB
/
jquery.rapidEdit.min.js
1
2
3
4
5
6
7
8
9
10
/**
* RapidEdit (for jQuery)
* Version: 1.3.2 (2012-09-08)
* @requires jQuery v. 1.6.X or later
* @supports TinyMCE jQuery Package (http://www.tinymce.com/download/download.php)
* @supports InnovaStudio LiveEditor (http://www.innovastudio.com/)
* @supports MetaData plugin (http://docs.jquery.com/Plugins/Metadata)
*
*/
(function($){$.rapidEdit=function(a,b){var c=$.extend({},$.rapidEdit.defaults,b);c.submitTo=a;$.rapidEdit.settings=c;return $("."+$.rapidEdit.settings.rapidEditClass).each(function(){$.rapidEdit.attachEditLink($(this))})};$.rapidEdit.bindClick=function(a){var b=$(a);var c=$.rapidEdit.metadata(a);b.find("."+c.editLinkClass).bind("click",function(){if($.rapidEdit.preview!=true||$.rapidEdit.preview==true&&confirm(c.previewConfirmText)){if($.rapidEdit.preview==true){$("#"+c.endPreviewButtonId).click();$("."+c.overlayContainerClass+" ."+c.cancelButtonClass).click()}$.rapidEdit.startOverlay(c,a);$.rapidEdit.editElement(a,b.attr("id"))}});if(c.editLinkHoverAttribute!=""&&c.editLinkHoverValue!=""){b.children("."+c.editLinkClass).hover(function(){b.css(c.editLinkHoverAttribute,c.editLinkHoverValue)},function(){$.rapidEdit.resetHover(a)})}};$.rapidEdit.bindSubmit=function(a,b){var c=$.rapidEdit.metadata(a);var d=$(a);$("."+c.overlayContainerClass+" ."+c.submitButtonClass).bind("click",function(){var e=$.rapidEdit.getEditorValue(c);var f="";$.each(c.extraData,function(a,b){f+="&"+a+"="+b});$.ajax({url:c.submitTo,type:c.submitType,data:"id="+b+"&class="+d.attr("class")+"&content="+encodeURIComponent(c.tinymce==true||c.liveEditor?e:$.rapidEdit.nl2br(e))+f,dataType:"json",success:function(b){if(b.error!=undefined){alert(b.error)}else{$.rapidEdit.restoreElement(e,a)}},error:function(a,b,c){alert("Something went wrong. Save was unsuccessful. ("+c+")")}})})};$.rapidEdit.bindPreview=function(a,b){var c=$.rapidEdit.metadata(a);var d=$(a);$("."+c.overlayContainerClass+" ."+c.previewButtonClass).bind("click",function(){$.rapidEdit.preview=true;var a=d.html();var b=$.rapidEdit.getEditorValue(c);d.html(b);$.rapidEdit.hideOverlay();$("body").css({overflow:"visible"});$("body").append('<div style="'+c.endPreviewContainerStyle+'"><input id="'+c.endPreviewButtonId+'" type="button" value="'+c.endPreviewButtonValue+'" style="'+c.endPreviewButtonStyle+'" /></div>');$("#"+c.endPreviewButtonId).bind("click",function(){d.html(a);$(this).parent().remove();$.rapidEdit.showOverlay();$.rapidEdit.preview=false;$("body").css({"overflow-y":"hidden"})})})};$.rapidEdit.bindCancel=function(a,b){var c=$.rapidEdit.metadata(b);$("."+c.overlayContainerClass+" ."+c.cancelButtonClass).bind("click",function(){$.rapidEdit.restoreElement(a,b,true)})};$.rapidEdit.resetHover=function(a){var b=$.rapidEdit.metadata(a);$(a).css(b.editLinkHoverAttribute,"")};$.rapidEdit.attachEditLink=function(a){var b=$.rapidEdit.metadata(a);var c=$(a);if(b.setParentPositionRelative==true){c.css("position","relative")}var d='<div class="'+b.editLinkClass+'" style="cursor: pointer; position: absolute; '+b.editLinkPosY+": "+b.editLinkDistY+"; "+b.editLinkPosX+": "+b.editLinkDistX+';"><img src="'+b.editLinkImagePath+'" alt="'+b.editLinkImageTitle+'" title="'+b.editLinkImageTitle+'" /></div>';c.append(d);$.rapidEdit.bindClick(a)};$.rapidEdit.editElement=function(a,b){var c=$.rapidEdit.metadata(a);var d=$(a);$.rapidEdit.resetHover(a);d.find("."+c.editLinkClass).remove();var e=c.tinymce==true||c.liveEditor==true?d.html():$.rapidEdit.br2nl(d.html());var f=(c.liveEditor==true?'<div id="'+c.liveEditorDivId+'"></div>':"")+'<textarea id="'+c.textareaId+'" name="'+c.textareaClass+'" class="'+c.textareaClass+'" style="width: '+c.textareaWidth+"px; height: "+c.textareaHeight+"px;"+c.textareaStyle+'">'+e+"</textarea>";var g='<input type="submit" class="'+c.submitButtonClass+'" value="'+c.submitButtonValue+'" style="'+c.submitButtonStyle+'" />';var h='<input type="button" class="'+c.previewButtonClass+'" value="'+c.previewButtonValue+'" style="'+c.previewButtonStyle+'" />';var i='<input type="button" class="'+c.cancelButtonClass+'" value="'+c.cancelButtonValue+'" style="'+c.cancelButtonStyle+'" />';$("."+c.overlayContainerClass).html(f+g+h+i);$.rapidEdit.bindSubmit(a,b);$.rapidEdit.bindPreview(a,b);$.rapidEdit.bindCancel(e,a);$.rapidEdit.initiateWYSIWYG(c)};$.rapidEdit.restoreElement=function(a,b,c){var d=$.rapidEdit.metadata(b);$.rapidEdit.restoreTinyMCE(d);if(c!=true){$(b).html(a)}$.rapidEdit.removeOverlay();$.rapidEdit.attachEditLink(b)};$.rapidEdit.getEditorValue=function(settings){var newContent="";if(settings.tinymce==true){newContent=$("."+settings.textareaClass).html()}else if(settings.liveEditor==true){newContent=eval(settings.liveEditorObject+".getXHTMLBody();")}else{newContent=$("."+settings.textareaClass).val()}return newContent};$.rapidEdit.metadata=function(a){var b=$.rapidEdit.settings;return $.metadata?$.extend({},b,$(a).metadata()):b};$.rapidEdit.restoreTinyMCE=function(a){if(a.tinymce==true){$("."+a.textareaClass).tinymce().remove()}};$.rapidEdit.initiateWYSIWYG=function(a){$.rapidEdit.initiateTinyMCE(a);$.rapidEdit.initiateLiveEditor(a)};$.rapidEdit.initiateTinyMCE=function(a){if(a.tinymce==true){$("."+a.textareaClass).tinymce(a.tinymceOptions)}};$.rapidEdit.initiateLiveEditor=function(settings){if(settings.liveEditor==true){eval(settings.liveEditorObject+' = new InnovaEditor("'+settings.liveEditorObject+'");');$.each(settings.liveEditorOptions,function(key,value){eval(settings.liveEditorObject+"[key] = value;")});eval(settings.liveEditorObject+".REPLACE(settings.textareaId, settings.liveEditorDivId)");var container=document.getElementById(settings.overlayContainerId);var tmpLeft=container.style.left;var tmpTop=container.style.top;var tmpMarginLeft=container.style.marginLeft;var tmpMarginTop=container.style.marginTop;eval(settings.liveEditorObject+".onFullScreen = function () {container.style.left='0';container.style.top='0';container.style.marginLeft='-'+$(container).css('border-left-width');container.style.marginTop='-'+$(container).css('border-top-width');};");eval(settings.liveEditorObject+".onNormalScreen = function () {container.style.left=tmpLeft;container.style.top=tmpTop;container.style.marginLeft=tmpMarginLeft;container.style.marginTop=tmpMarginTop;};")}};$.rapidEdit.nl2br=function(a){var b="<br />";a=(a+"").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,"$1"+b+"$2");return a};$.rapidEdit.br2nl=function(a){a=(a+"").replace(/<br \/>/g,"\n");a=(a+"").replace(/<br>/g,"\n");return a};$.rapidEdit.startOverlay=function(a,b){$("body").append('<div id="'+a.overlayId+'" class="'+a.overlayClass+'" style="'+a.overlayStyle+'"></div><div id="'+a.overlayContainerId+'" class="'+a.overlayContainerClass+'" style="'+a.overlayContainerStyle+'"></div>').css({"overflow-y":"hidden"});$("."+a.overlayClass).animate({opacity:a.overlayOpacity},a.overlayFadeInSpeed,a.overlayFadeInEasing);$("."+a.overlayContainerClass).html("help");$("."+a.overlayContainerClass).css({top:"50%",left:"50%",width:a.overlayContainerWidth,"min-height":a.overlayContainerMinHeight,"margin-top":-(a.overlayContainerMinHeight/2),"margin-left":-(a.overlayContainerWidth/2)}).animate({opacity:"1"},a.overlayContainerFadeInSpeed,a.overlayContainerFadeInEasing);$("."+a.overlayClass).click(function(){$.rapidEdit.removeOverlay();$.rapidEdit.attachEditLink(b)})};$.rapidEdit.removeOverlay=function(){var a=$.rapidEdit.settings;var b=$("."+a.overlayContainerClass+", ."+a.overlayClass);b.animate({opacity:"0"},a.overlayFadeOutSpeed,a.overlayFadeOutEasing,function(){$("body").css({overflow:"visible"});b.remove()})};$.rapidEdit.hideOverlay=function(){var a=$.rapidEdit.settings;$("."+a.overlayContainerClass+", ."+a.overlayClass).hide()};$.rapidEdit.showOverlay=function(){var a=$.rapidEdit.settings;$("."+a.overlayContainerClass+", ."+a.overlayClass).show()};$.rapidEdit.preview=false;$.rapidEdit.settings={};$.rapidEdit.defaults={rapidEditClass:"editable",submitTo:"",submitType:"POST",extraData:{},editLinkImagePath:"edit.png",editLinkImageTitle:"Edit",editLinkClass:"rapidEdit-link",editLinkHoverAttribute:"",editLinkHoverValue:"",editLinkPosX:"right",editLinkPosY:"top",editLinkDistX:"0",editLinkDistY:"0",overlayId:"rapidEdit-overlay",overlayClass:"rapidEdit-overlay",overlayFadeInSpeed:400,overlayFadeInEasing:"linear",overlayFadeOutSpeed:0,overlayFadeOutEasing:"linear",overlayOpacity:.6,overlayStyle:"cursor:pointer;position:fixed;top:0;left:0;height:100%;width:100%;background:#000;opacity:0;filter:alpha(opacity=0);z-index:5000;",overlayContainerWidth:695,overlayContainerMinHeight:400,overlayContainerId:"rapidEdit-container",overlayContainerClass:"rapidEdit-container",overlayContainerFadeInSpeed:400,overlayContainerFadeInEasing:"linear",overlayContainerStyle:"position:fixed;opacity:0;filter:alpha(opacity=0);left:-9999em;z-index:5001;background-color:#fff;padding:10px;border:3px solid #cdcdcd;text-align:left;border-radius:10px;",liveEditor:false,liveEditorObject:"oEdit1",liveEditorDivId:"rapidEdit-liveEditor",liveEditorOptions:{width:689,height:360,groups:[["group1","",["Bold","Italic","Underline","FontDialog","ForeColor","TextDialog","RemoveFormat"]],["group2","",["Bullets","Numbering","JustifyLeft","JustifyCenter","JustifyRight"]],["group3","",["LinkDialog","ImageDialog","YoutubeDialog","TableDialog","Emoticons"]],["group4","",["Undo","Redo","FullScreen","SourceDialog"]]],css:"LiveEditor/styles/default.css"},tinymce:false,tinymceOptions:{script_url:"tiny_mce/tiny_mce.js",theme:"advanced",theme_advanced_toolbar_location:"top",plugins:"autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",theme_advanced_buttons1:"save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",theme_advanced_buttons2:"cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",theme_advanced_buttons3:"tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",theme_advanced_buttons4:"insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",theme_advanced_statusbar_location:"bottom",forced_root_block:false},textareaWidth:689,textareaHeight:360,textareaId:"rapidEdit-textarea",textareaClass:"rapidEdit-textarea",textareaStyle:"padding:3px;font-family:Arial;font-size:12px;max-width:687px;border:1px solid #ccc;",submitButtonClass:"rapidEdit-submit",submitButtonValue:"Save",submitButtonStyle:"margin:5px 5px 0 0;background-color: #F7F7F7;border-color: #CCCCCC;border-radius: 11px 11px 11px 11px;border-style: solid;border-width: 1px;color: #464646;cursor: pointer;font-size: 12px !important;line-height: 15px;padding: 3px 10px;text-shadow: 0 1px 0 #FFFFFF;white-space: nowrap;width: auto;",previewButtonClass:"rapidEdit-preview",previewButtonValue:"Preview",previewButtonStyle:"margin:5px 5px 0 0;background-color: #F7F7F7;border-color: #CCCCCC;border-radius: 11px 11px 11px 11px;border-style: solid;border-width: 1px;color: #464646;cursor: pointer;font-size: 12px !important;line-height: 15px;padding: 3px 10px;text-shadow: 0 1px 0 #FFFFFF;white-space: nowrap;width: auto;",endPreviewButtonId:"rapidEdit-endpreview",endPreviewButtonValue:"End preview",endPreviewButtonStyle:"margin:0;background-color: #F7F7F7;border-color: #CCCCCC;border-radius: 11px 11px 11px 11px;border-style: solid;border-width: 1px;color: #464646;cursor: pointer;font-size: 12px !important;line-height: 15px;padding: 3px 10px;text-shadow: 0 1px 0 #FFFFFF;white-space: nowrap;width: auto;",endPreviewContainerStyle:"padding:5px;position:fixed;bottom:0;left:100px;border:3px solid #cdcdcd;border-bottom:0;border-radius:10px 10px 0 0;background-color:#fff;z-index:9999;",previewConfirmText:"You are currently previewing the changes of another element, would you like to end the preview and edit this element instead?",cancelButtonClass:"rapidEdit-cancel",cancelButtonValue:"Cancel",cancelButtonStyle:"margin-top:5px;background-color: #F7F7F7;border-color: #CCCCCC;border-radius: 11px 11px 11px 11px;border-style: solid;border-width: 1px;color: #464646;cursor: pointer;font-size: 12px !important;line-height: 15px;padding: 3px 10px;text-shadow: 0 1px 0 #FFFFFF;white-space: nowrap;width: auto;",setParentPositionRelative:true}})(jQuery)