var fluid_1_4=fluid_1_4||{};(function($,fluid){fluid.inlineEdit.makeViewAccessor=function(editorGetFn,setValueFn,getValueFn){return function(editField){return{value:function(newValue){var editor=editorGetFn(editField);if(!editor){if(newValue){$(editField).val(newValue)}return""}if(newValue){setValueFn(editField,editor,newValue)}else{return getValueFn(editor)}}}}};fluid.inlineEdit.richTextViewAccessor=function(element){return{value:function(newValue){return $(element).html(newValue)}}};var configureInlineEdit=function(configurationName,container,options){var defaults=fluid.defaults(configurationName);var assembleOptions=fluid.merge(defaults?defaults.mergePolicy:null,{},defaults,options);return fluid.inlineEdit(container,assembleOptions)};fluid.inlineEdit.normalizeHTML=function(value){var togo=$.trim(value.replace(/\s+/g," "));togo=togo.replace(/\s+<\//g,"</");togo=togo.replace(/\<([a-z0-9A-Z\/]+)\>/g,function(match){return match.toLowerCase()});return togo};fluid.inlineEdit.htmlComparator=function(el1,el2){return fluid.inlineEdit.normalizeHTML(el1)===fluid.inlineEdit.normalizeHTML(el2)};fluid.inlineEdit.bindRichTextHighlightHandler=function(element,displayModeRenderer,invitationStyle){element=$(element);var focusOn=function(){displayModeRenderer.addClass(invitationStyle)};var focusOff=function(){displayModeRenderer.removeClass(invitationStyle)};element.focus(focusOn);element.blur(focusOff)};fluid.inlineEdit.setupRichTextEditButton=function(that){var opts=that.options;var textEditButton=that.locate("textEditButton");if(textEditButton.length===0){var markup=$("<a href='#_' class='flc-inlineEdit-textEditButton'></a>");markup.text(opts.strings.textEditButton);that.locate("text").after(markup);textEditButton=that.locate("textEditButton")}return textEditButton};fluid.inlineEdit.richTextDisplayModeRenderer=function(that){var styles=that.options.styles;var displayModeWrapper=fluid.inlineEdit.setupDisplayModeContainer(styles);var displayModeRenderer=that.viewEl.wrap(displayModeWrapper).parent();that.textEditButton=fluid.inlineEdit.setupRichTextEditButton(that);displayModeRenderer.append(that.textEditButton);displayModeRenderer.addClass(styles.focus);fluid.inlineEdit.bindHoverHandlers(displayModeRenderer,styles.invitation);fluid.inlineEdit.bindMouseHandlers(that.textEditButton,that.edit);fluid.inlineEdit.bindKeyboardHandlers(that.textEditButton,that.edit);fluid.inlineEdit.bindRichTextHighlightHandler(that.viewEl,displayModeRenderer,styles.invitation);fluid.inlineEdit.bindRichTextHighlightHandler(that.textEditButton,displayModeRenderer,styles.invitation);return displayModeRenderer};fluid.inlineEdit.tinyMCE=function(container,options){var inlineEditor=configureInlineEdit("fluid.inlineEdit.tinyMCE",container,options);tinyMCE.init(inlineEditor.options.tinyMCE);return inlineEditor};fluid.inlineEdit.tinyMCE.getEditor=function(editField){return tinyMCE.get(editField.id)};fluid.inlineEdit.tinyMCE.setValue=function(editField,editor,value){$(editField).val(value);editor.setContent(value,{format:"raw"})};fluid.inlineEdit.tinyMCE.getValue=function(editor){return editor.getContent()};var flTinyMCE=fluid.inlineEdit.tinyMCE;flTinyMCE.viewAccessor=fluid.inlineEdit.makeViewAccessor(flTinyMCE.getEditor,flTinyMCE.setValue,flTinyMCE.getValue);fluid.inlineEdit.tinyMCE.blurHandlerBinder=function(that){function focusEditor(editor){setTimeout(function(){tinyMCE.execCommand("mceFocus",false,that.editField[0].id);if($.browser.mozilla&&$.browser.version.substring(0,3)==="1.8"){return }editor.selection.select(editor.getBody(),1);editor.selection.collapse(0)},10)}that.events.afterInitEdit.addListener(function(editor){focusEditor(editor);var editorBody=editor.getBody();fluid.deadMansBlur(that.editField,{exclusions:{body:$(editorBody)},handler:function(){that.cancel()}})});that.events.afterBeginEdit.addListener(function(){var editor=tinyMCE.get(that.editField[0].id);if(editor){focusEditor(editor)}})};fluid.inlineEdit.tinyMCE.editModeRenderer=function(that){var options=that.options.tinyMCE;options.elements=fluid.allocateSimpleId(that.editField);var oldinit=options.init_instance_callback;options.init_instance_callback=function(instance){that.events.afterInitEdit.fire(instance);if(oldinit){oldinit()}};tinyMCE.init(options)};fluid.defaults("fluid.inlineEdit.tinyMCE",{tinyMCE:{mode:"exact",theme:"simple"},useTooltip:true,selectors:{edit:"textarea"},styles:{invitation:"fl-inlineEdit-richText-invitation",displayView:"fl-inlineEdit-textContainer",text:""},strings:{textEditButton:"Edit"},displayAccessor:{type:"fluid.inlineEdit.richTextViewAccessor"},editAccessor:{type:"fluid.inlineEdit.tinyMCE.viewAccessor"},lazyEditView:true,defaultViewText:"Click Edit",modelComparator:fluid.inlineEdit.htmlComparator,blurHandlerBinder:fluid.inlineEdit.tinyMCE.blurHandlerBinder,displayModeRenderer:fluid.inlineEdit.richTextDisplayModeRenderer,editModeRenderer:fluid.inlineEdit.tinyMCE.editModeRenderer});fluid.inlineEdit.CKEditor=function(container,options){return configureInlineEdit("fluid.inlineEdit.CKEditor",container,options)};fluid.inlineEdit.CKEditor.getEditor=function(editField){return CKEDITOR.instances[editField.id]};fluid.inlineEdit.CKEditor.setValue=function(editField,editor,value){editor.setData(value)};fluid.inlineEdit.CKEditor.getValue=function(editor){return editor.getData()};var flCKEditor=fluid.inlineEdit.CKEditor;flCKEditor.viewAccessor=fluid.inlineEdit.makeViewAccessor(flCKEditor.getEditor,flCKEditor.setValue,flCKEditor.getValue);fluid.inlineEdit.CKEditor.focus=function(editor){setTimeout(function(){editor.focus()},0)};fluid.inlineEdit.CKEditor.normalizeHTML=function(value){var togo=fluid.inlineEdit.normalizeHTML(value);var angpos=togo.indexOf(">");if(angpos!==-1&&angpos<togo.length-1){if(togo.charAt(angpos+1)!==" "){togo=togo.substring(0,angpos+1)+" "+togo.substring(angpos+1)}}return togo};fluid.inlineEdit.CKEditor.htmlComparator=function(el1,el2){return fluid.inlineEdit.CKEditor.normalizeHTML(el1)===fluid.inlineEdit.CKEditor.normalizeHTML(el2)};fluid.inlineEdit.CKEditor.blurHandlerBinder=function(that){that.events.afterInitEdit.addListener(fluid.inlineEdit.CKEditor.focus);that.events.afterBeginEdit.addListener(function(){var editor=fluid.inlineEdit.CKEditor.getEditor(that.editField[0]);if(editor){fluid.inlineEdit.CKEditor.focus(editor)}})};fluid.inlineEdit.CKEditor.editModeRenderer=function(that){var id=fluid.allocateSimpleId(that.editField);$.data(fluid.unwrap(that.editField),"fluid.inlineEdit.CKEditor",that);var editor=CKEDITOR.replace(id,that.options.CKEditor);editor.on("instanceReady",function(e){fluid.inlineEdit.CKEditor.focus(e.editor);that.events.afterInitEdit.fire(e.editor)})};fluid.defaults("fluid.inlineEdit.CKEditor",{selectors:{edit:"textarea"},styles:{invitation:"fl-inlineEdit-richText-invitation",displayView:"fl-inlineEdit-textContainer",text:""},strings:{textEditButton:"Edit"},displayAccessor:{type:"fluid.inlineEdit.richTextViewAccessor"},editAccessor:{type:"fluid.inlineEdit.CKEditor.viewAccessor"},lazyEditView:true,defaultViewText:"Click Edit",modelComparator:fluid.inlineEdit.CKEditor.htmlComparator,blurHandlerBinder:fluid.inlineEdit.CKEditor.blurHandlerBinder,displayModeRenderer:fluid.inlineEdit.richTextDisplayModeRenderer,editModeRenderer:fluid.inlineEdit.CKEditor.editModeRenderer,CKEditor:{}});fluid.inlineEdit.dropdown=function(container,options){return configureInlineEdit("fluid.inlineEdit.dropdown",container,options)};fluid.inlineEdit.dropdown.editModeRenderer=function(that){var id=fluid.allocateSimpleId(that.editField);that.editField.selectbox({finishHandler:function(){that.finish()}});return{container:that.editContainer,field:$("input.selectbox",that.editContainer)}};fluid.inlineEdit.dropdown.blurHandlerBinder=function(that){fluid.deadMansBlur(that.editField,{exclusions:{selectBox:$("div.selectbox-wrapper",that.editContainer)},handler:function(){that.cancel()}})};fluid.defaults("fluid.inlineEdit.dropdown",{applyEditPadding:false,blurHandlerBinder:fluid.inlineEdit.dropdown.blurHandlerBinder,editModeRenderer:fluid.inlineEdit.dropdown.editModeRenderer})})(jQuery,fluid_1_4);