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)
{
var k = key.toLowerCase();
if (k == "wraps")
{
setWraps(value);
}
else if (k == "showsauthorcolors")
{
setClassPresence(root, "authorColors", !! value);
}
else if (k == "showsuserselections")
{
setClassPresence(root, "userSelections", !! value);
}
else if (k == "showslinenumbers")
{
hasLineNumbers = !! value;
// disable line numbers on mobile devices
if (browser.mobile) hasLineNumbers = false;
setClassPresence(sideDiv, "sidedivhidden", !hasLineNumbers);
fixView();
}
else if (k == "grayedout")
{
setClassPresence(outerWin.document.body, "grayedout", !! value);
}
else if (k == "dmesg")
{
dmesg = value;
window.dmesg = value;
}
else if (k == 'userauthor')
{
thisAuthor = String(value);
}
else if (k == 'styled')
{
setStyled(value);
}
else if (k == 'textface')
{
setTextFace(value);
}
else if (k == 'textsize')
{
setTextSize(value);
}
else if (k == 'rtlistrue')
{
setClassPresence(root, "rtl", !! value);
// Convinience function returning a setter for a class on an element
var setClassPresenceNamed = function(element, cls){
return function(value){
setClassPresence(element, cls, !! value)
}
};
// These properties are exposed
var setters = {
wraps: setWraps,
showsauthorcolors: setClassPresenceNamed(root, "authorColors"),
showsuserselections: setClassPresenceNamed(root, "userSelections"),
showslinenumbers : function(value){
hasLineNumbers = !! value;
// disable line numbers on mobile devices
if (browser.mobile) hasLineNumbers = false;
setClassPresence(sideDiv, "sidedivhidden", !hasLineNumbers);
fixView();
},
grayedout: setClassPresenceNamed(outerWin.document.body, "grayedout"),
dmesg: function(){ dmesg = window.dmesg = value; },
userauthor: function(value){ thisAuthor = String(value); },
styled: setStyled,
textface: setTextFace,
textsize: setTextSize,
rtlistrue: setClassPresenceNamed(root, "rtl")
};
var setter = setters[key.toLowerCase()];
// check if setter is present
if(setter !== undefined){
setter(value)
}
}