more compact code for exposed functions in ace2.js
This commit is contained in:
parent
6ba865521a
commit
8031c31bc3
|
@ -49,8 +49,7 @@ function Ace2Editor()
|
||||||
{
|
{
|
||||||
var that = this;
|
var that = this;
|
||||||
var args = arguments;
|
var args = arguments;
|
||||||
|
var action = function()
|
||||||
function action()
|
|
||||||
{
|
{
|
||||||
func.apply(that, args);
|
func.apply(that, args);
|
||||||
}
|
}
|
||||||
|
@ -71,78 +70,47 @@ function Ace2Editor()
|
||||||
|
|
||||||
function doActionsPendingInit()
|
function doActionsPendingInit()
|
||||||
{
|
{
|
||||||
for (var i = 0; i < actionsPendingInit.length; i++)
|
$.each(actionsPendingInit, function(i,fn){
|
||||||
{
|
fn()
|
||||||
actionsPendingInit[i]();
|
});
|
||||||
}
|
|
||||||
actionsPendingInit = [];
|
actionsPendingInit = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
ace2.registry[info.id] = info;
|
ace2.registry[info.id] = info;
|
||||||
|
|
||||||
editor.importText = pendingInit(function(newCode, undoable)
|
// The following functions (prefixed by 'ace_') are exposed by editor, but
|
||||||
{
|
// execution is delayed until init is complete
|
||||||
info.ace_importText(newCode, undoable);
|
var aceFunctionsPendingInit = ['importText', 'importAText', 'focus',
|
||||||
|
'setEditable', 'getFormattedCode', 'setOnKeyPress', 'setOnKeyDown',
|
||||||
|
'setNotifyDirty', 'setProperty', 'setBaseText', 'setBaseAttributedText',
|
||||||
|
'applyChangesToBase', 'applyPreparedChangesetToBase',
|
||||||
|
'setUserChangeNotificationCallback', 'setAuthorInfo',
|
||||||
|
'setAuthorSelectionRange', 'callWithAce', 'execCommand', 'replaceRange'];
|
||||||
|
|
||||||
|
$.each(aceFunctionsPendingInit, function(i,fnName){
|
||||||
|
var prefix = 'ace_';
|
||||||
|
var name = prefix + fnName;
|
||||||
|
editor[fnName] = pendingInit(function(){
|
||||||
|
info[prefix + fnName].apply(this, arguments);
|
||||||
});
|
});
|
||||||
editor.importAText = pendingInit(function(newCode, apoolJsonObj, undoable)
|
|
||||||
{
|
|
||||||
info.ace_importAText(newCode, apoolJsonObj, undoable);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
editor.exportText = function()
|
editor.exportText = function()
|
||||||
{
|
{
|
||||||
if (!loaded) return "(awaiting init)\n";
|
if (!loaded) return "(awaiting init)\n";
|
||||||
return info.ace_exportText();
|
return info.ace_exportText();
|
||||||
};
|
};
|
||||||
|
|
||||||
editor.getFrame = function()
|
editor.getFrame = function()
|
||||||
{
|
{
|
||||||
return info.frame || null;
|
return info.frame || null;
|
||||||
};
|
};
|
||||||
editor.focus = pendingInit(function()
|
|
||||||
{
|
|
||||||
info.ace_focus();
|
|
||||||
});
|
|
||||||
editor.setEditable = pendingInit(function(newVal)
|
|
||||||
{
|
|
||||||
info.ace_setEditable(newVal);
|
|
||||||
});
|
|
||||||
editor.getFormattedCode = function()
|
|
||||||
{
|
|
||||||
return info.ace_getFormattedCode();
|
|
||||||
};
|
|
||||||
editor.setOnKeyPress = pendingInit(function(handler)
|
|
||||||
{
|
|
||||||
info.ace_setOnKeyPress(handler);
|
|
||||||
});
|
|
||||||
editor.setOnKeyDown = pendingInit(function(handler)
|
|
||||||
{
|
|
||||||
info.ace_setOnKeyDown(handler);
|
|
||||||
});
|
|
||||||
editor.setNotifyDirty = pendingInit(function(handler)
|
|
||||||
{
|
|
||||||
info.ace_setNotifyDirty(handler);
|
|
||||||
});
|
|
||||||
|
|
||||||
editor.setProperty = pendingInit(function(key, value)
|
|
||||||
{
|
|
||||||
info.ace_setProperty(key, value);
|
|
||||||
});
|
|
||||||
editor.getDebugProperty = function(prop)
|
editor.getDebugProperty = function(prop)
|
||||||
{
|
{
|
||||||
return info.ace_getDebugProperty(prop);
|
return info.ace_getDebugProperty(prop);
|
||||||
};
|
};
|
||||||
|
|
||||||
editor.setBaseText = pendingInit(function(txt)
|
|
||||||
{
|
|
||||||
info.ace_setBaseText(txt);
|
|
||||||
});
|
|
||||||
editor.setBaseAttributedText = pendingInit(function(atxt, apoolJsonObj)
|
|
||||||
{
|
|
||||||
info.ace_setBaseAttributedText(atxt, apoolJsonObj);
|
|
||||||
});
|
|
||||||
editor.applyChangesToBase = pendingInit(function(changes, optAuthor, apoolJsonObj)
|
|
||||||
{
|
|
||||||
info.ace_applyChangesToBase(changes, optAuthor, apoolJsonObj);
|
|
||||||
});
|
|
||||||
// prepareUserChangeset:
|
// prepareUserChangeset:
|
||||||
// Returns null if no new changes or ACE not ready. Otherwise, bundles up all user changes
|
// Returns null if no new changes or ACE not ready. Otherwise, bundles up all user changes
|
||||||
// to the latest base text into a Changeset, which is returned (as a string if encodeAsString).
|
// to the latest base text into a Changeset, which is returned (as a string if encodeAsString).
|
||||||
|
|
Loading…
Reference in New Issue