Merge pull request #483 from fourplusone/ace2_inner_patch2

refactored ace_setProperty of ace2_inner.js
This commit is contained in:
John McLear 2012-02-24 09:00:18 -08:00
commit 64f04670ef
1 changed files with 37 additions and 49 deletions

View File

@ -1123,57 +1123,45 @@ function OUTER(gscope)
} }
} }
// This methed exposes a setter for some ace properties
// @param key the name of the parameter
// @param value the value to set to
editorInfo.ace_setProperty = function(key, value) editorInfo.ace_setProperty = function(key, value)
{ {
var k = key.toLowerCase();
if (k == "wraps") // Convinience function returning a setter for a class on an element
{ var setClassPresenceNamed = function(element, cls){
setWraps(value); return function(value){
setClassPresence(element, cls, !! value)
} }
else if (k == "showsauthorcolors") };
{
setClassPresence(root, "authorColors", !! value); // These properties are exposed
} var setters = {
else if (k == "showsuserselections") wraps: setWraps,
{ showsauthorcolors: setClassPresenceNamed(root, "authorColors"),
setClassPresence(root, "userSelections", !! value); showsuserselections: setClassPresenceNamed(root, "userSelections"),
} showslinenumbers : function(value){
else if (k == "showslinenumbers")
{
hasLineNumbers = !! value; hasLineNumbers = !! value;
// disable line numbers on mobile devices // disable line numbers on mobile devices
if (browser.mobile) hasLineNumbers = false; if (browser.mobile) hasLineNumbers = false;
setClassPresence(sideDiv, "sidedivhidden", !hasLineNumbers); setClassPresence(sideDiv, "sidedivhidden", !hasLineNumbers);
fixView(); fixView();
} },
else if (k == "grayedout") grayedout: setClassPresenceNamed(outerWin.document.body, "grayedout"),
{ dmesg: function(){ dmesg = window.dmesg = value; },
setClassPresence(outerWin.document.body, "grayedout", !! value); userauthor: function(value){ thisAuthor = String(value); },
} styled: setStyled,
else if (k == "dmesg") textface: setTextFace,
{ textsize: setTextSize,
dmesg = value; rtlistrue: setClassPresenceNamed(root, "rtl")
window.dmesg = value; };
}
else if (k == 'userauthor') var setter = setters[key.toLowerCase()];
{
thisAuthor = String(value); // check if setter is present
} if(setter !== undefined){
else if (k == 'styled') setter(value)
{
setStyled(value);
}
else if (k == 'textface')
{
setTextFace(value);
}
else if (k == 'textsize')
{
setTextSize(value);
}
else if (k == 'rtlistrue')
{
setClassPresence(root, "rtl", !! value);
} }
} }