All pastes #932508 Raw Edit

ninix

public text v1 · immutable
·published 2008-03-07 20:03 UTC
rendered paste body
/**
 * @type {Object}
 */
ace.history = {
	/**
	 * @method
	 */
        initialize: function() {
                window.dhtmlHistory.create({
                    toJSON: function(o) {
                        return Object.toJSON(o);
                    }
                    , fromJSON: function(s) {
                        return s.evalJSON();
                    }
                });

                var yourListener = function(newLocation, data) {
		    if (newLocation == '' || !data) return;			
		    try {
		        data.invoke('update');				
		    } catch(e) {
// Les				ace.util.alert(e.fileName + '(' + e.lineNumber + '): \n\n' + e.name + ': ' + e.message + '\n\n' + e.stack, {height:100});
	            }
                }

                Event.observe(window, 'load', function() {
               	    dhtmlHistory.initialize();
                    dhtmlHistory.addListener(yourListener);
                });
        },	
	
	/**
	 * @method
	 * @param {Array(Object)} data - each object must expose update() method
	 */
	add: function(data) {
		var curLoc	= dhtmlHistory.getCurrentLocation();
		var loc		= (curLoc == '') ? '1' : parseInt(curLoc) + 1 + '';
		dhtmlHistory.add(loc, data);
	}
};
//document.observe('dom:loaded', ace.history.initialize);
ace.history.initialize();