4836: side menu inline edit now properly saved after exiting edit mode.
[acontent.git] / docs / include / jscripts / infusion / components / undo / js / Undo.js
1 fluid_1_1=fluid_1_1||{};(function($,fluid){var STATE_INITIAL="state_initial",STATE_CHANGED="state_changed",STATE_REVERTED="state_reverted";function defaultRenderer(that,targetContainer){var markup="<span class='flc-undo'><span class='flc-undo-undoContainer'>[<a href='#' class='flc-undo-undoControl'>undo</a>]</span><span class='flc-undo-redoContainer'>[<a href='#' class='flc-undo-redoControl'>redo</a>]</span></span>";var markupNode=$(markup);targetContainer.append(markupNode);return markupNode}function refreshView(that){if(that.state===STATE_INITIAL){that.locate("undoContainer").hide();that.locate("redoContainer").hide()}else{if(that.state===STATE_CHANGED){that.locate("undoContainer").show();that.locate("redoContainer").hide()}else{if(that.state===STATE_REVERTED){that.locate("undoContainer").hide();that.locate("redoContainer").show()}}}}var bindHandlers=function(that){that.locate("undoControl").click(function(){if(that.state!==STATE_REVERTED){fluid.model.copyModel(that.extremalModel,that.component.model);that.component.updateModel(that.initialModel,that);that.state=STATE_REVERTED;refreshView(that);that.locate("redoControl").focus()}return false});that.locate("redoControl").click(function(){if(that.state!==STATE_CHANGED){that.component.updateModel(that.extremalModel,that);that.state=STATE_CHANGED;refreshView(that);that.locate("undoControl").focus()}return false});return{modelChanged:function(newModel,oldModel,source){if(source!==that){that.state=STATE_CHANGED;fluid.model.copyModel(that.initialModel,oldModel);refreshView(that)}}}};fluid.undoDecorator=function(component,userOptions){var that=fluid.initView("undo",null,userOptions);that.container=that.options.renderer(that,component.container);fluid.initDomBinder(that);fluid.tabindex(that.locate("undoControl"),0);fluid.tabindex(that.locate("redoControl"),0);that.component=component;that.initialModel={};that.extremalModel={};fluid.model.copyModel(that.initialModel,component.model);fluid.model.copyModel(that.extremalModel,component.model);that.state=STATE_INITIAL;refreshView(that);var listeners=bindHandlers(that);that.returnedOptions={listeners:listeners};return that};fluid.defaults("undo",{selectors:{undoContainer:".flc-undo-undoContainer",undoControl:".flc-undo-undoControl",redoContainer:".flc-undo-redoContainer",redoControl:".flc-undo-redoControl"},renderer:defaultRenderer})})(jQuery,fluid_1_1);