Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merged rangeHandler, ranges broken for now
- Loading branch information
Showing
5 changed files
with
200 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
<<<<<<< HEAD | ||
node_modules | ||
======= | ||
.c9revisions | ||
>>>>>>> rangeHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//Beautifier.js | ||
// | ||
//Copywrite 2011 Josh Benentt | ||
//License - https://raw.github.com/joshatjben/excelFormulaUtilitiesJS/master/LICENSE.txt | ||
//[on github](https://github.com/joshatjben/excelFormulaUtilitiesJS/tree/master/examples/basic_example1 "github") | ||
// | ||
(function (window, undefiend) { | ||
"use strict"; | ||
|
||
//Check and setup name spaces. | ||
window.excelFormulaBeautifier = window.excelFormulaBeautifier || {}; | ||
window.excelFormulaBeautifier.examples = window.excelFormulaBeautifier.examples || {}; | ||
|
||
//Configuration | ||
//------------------------------- | ||
var config = { | ||
//The ID for the formula Input input/textarea | ||
INPUT_ID: 'formula_input', | ||
|
||
//The ID for the formula title area. in this example it spits out the function call; | ||
FORMULA_TITLE_ID: 'fomatFormula_2', | ||
|
||
//THE ID for the area to contain the beautified excel formula. | ||
FORMULA_BODY_ID:'fomatFormula_2_out', | ||
|
||
//Use this to set the inital textare/input text area. | ||
DEFAULT_FORMULA: '' | ||
}, | ||
|
||
|
||
//Beautifier Page functionality | ||
//------------------------------- | ||
beautifier = window.excelFormulaBeautifier.examples.beautifier = | ||
(function () { | ||
var oldFormula; | ||
|
||
return { | ||
formula: '=IF(SUM( If(FOO = BAR, 10, 0), 10 ) = 20 , "FOO", "BAR")', | ||
input: null, | ||
formulaTitle: null, | ||
formulaBody: null, | ||
mode: "beautify", | ||
changeMode: function(mode){ | ||
window.excelFormulaBeautifier.examples.beautifier.mode = mode; | ||
window.excelFormulaBeautifier.examples.beautifier.update.call(window.excelFormulaBeautifier.examples.beautifier); | ||
}, | ||
update: function () { | ||
this.formula = this.input.value; | ||
|
||
//Test to see if the formula has changed, if it hasn't don't do anything | ||
if (oldFormula === this.formula) { | ||
return; | ||
} | ||
|
||
// Check to see which mode we're in, render appropriately | ||
try{ | ||
|
||
switch( this.mode ) { | ||
case "beautify": | ||
this.formulaBody.innerHTML = window.excelFormulaUtilities.formatFormulaHTML(this.formula); | ||
break; | ||
case "js": | ||
this.formulaBody.innerHTML = window.excelFormulaUtilities.formula2JavaScript(this.formula); | ||
break; | ||
} | ||
}catch(exception){ | ||
//Do nothing, This should throw an error when the formula is improperly formed, which shouldn't blow things up. | ||
} | ||
} | ||
}; | ||
}()); | ||
|
||
//On Page Load | ||
//------------------- | ||
window.onload = function () { | ||
beautifier.input = document.getElementById(config.INPUT_ID); | ||
//beautifier.formulaTitle = document.getElementById(config.FORMULA_TITLE_ID); | ||
beautifier.formulaBody = document.getElementById(config.FORMULA_BODY_ID); | ||
|
||
beautifier.input.value = beautifier.formula; | ||
beautifier.update(); | ||
//add beautifier.update(); here if if you have set an inital DEFAULT_FORMULA and would like it to render on page load. | ||
}; | ||
|
||
}(window)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,111 @@ | ||
<!doctype html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>ExcelFormulaUtilities.js - Online Excel Formula Beautifier</title> | ||
|
||
<meta name="description" content="Online Excel Formula Beautifier"> | ||
<meta name="author" content="Josh Bennett"> | ||
<title>Test - Online Excel Formula Beautifier</title> | ||
|
||
<style type="text/css">/*<![CDATA[*/ | ||
html, body{font-size:12px; font-family:"Trebuchet MS", "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Tahoma, sans-serif;} | ||
body{margin:0.618em;} | ||
footer{display:none;} | ||
#main .formula{ | ||
margin:0; | ||
padding:0; | ||
margin-bottom:0.61em; | ||
} | ||
#main .formula pre, #main .formula div{ | ||
margin:0; | ||
padding:0.61em; | ||
margin-bottom:1.618em; | ||
background: #ffffff; /* Old browsers */ | ||
background: -moz-linear-gradient(top, #ffffff 0%, #e5e5e5 100%); /* FF3.6+ */ | ||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#e5e5e5)); /* Chrome,Safari4+ */ | ||
background: -webkit-linear-gradient(top, #ffffff 0%,#e5e5e5 100%); /* Chrome10+,Safari5.1+ */ | ||
background: -o-linear-gradient(top, #ffffff 0%,#e5e5e5 100%); /* Opera11.10+ */ | ||
background: -ms-linear-gradient(top, #ffffff 0%,#e5e5e5 100%); /* IE10+ */ | ||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#e5e5e5',GradientType=0 ); /* IE6-9 */ | ||
background: linear-gradient(top, #ffffff 0%,#e5e5e5 100%); /* W3C */ | ||
} | ||
#main .formula h2{ | ||
font-weight:700; | ||
margin:0; | ||
padding:0.61em; | ||
font-size:12px; | ||
color:#fff; | ||
background: #b8e1fc; /* Old browsers */ | ||
background: -moz-linear-gradient(top, #b8e1fc 0%, #a9d2f3 10%, #90bae4 25%, #90bcea 37%, #90bff0 50%, #6ba8e5 51%, #a2daf5 83%, #bdf3fd 100%); /* FF3.6+ */ | ||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b8e1fc), color-stop(10%,#a9d2f3), color-stop(25%,#90bae4), color-stop(37%,#90bcea), color-stop(50%,#90bff0), color-stop(51%,#6ba8e5), color-stop(83%,#a2daf5), color-stop(100%,#bdf3fd)); /* Chrome,Safari4+ */ | ||
background: -webkit-linear-gradient(top, #b8e1fc 0%,#a9d2f3 10%,#90bae4 25%,#90bcea 37%,#90bff0 50%,#6ba8e5 51%,#a2daf5 83%,#bdf3fd 100%); /* Chrome10+,Safari5.1+ */ | ||
background: -o-linear-gradient(top, #b8e1fc 0%,#a9d2f3 10%,#90bae4 25%,#90bcea 37%,#90bff0 50%,#6ba8e5 51%,#a2daf5 83%,#bdf3fd 100%); /* Opera11.10+ */ | ||
background: -ms-linear-gradient(top, #b8e1fc 0%,#a9d2f3 10%,#90bae4 25%,#90bcea 37%,#90bff0 50%,#6ba8e5 51%,#a2daf5 83%,#bdf3fd 100%); /* IE10+ */ | ||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b8e1fc', endColorstr='#bdf3fd',GradientType=0 ); /* IE6-9 */ | ||
background: linear-gradient(top, #b8e1fc 0%,#a9d2f3 10%,#90bae4 25%,#90bcea 37%,#90bff0 50%,#6ba8e5 51%,#a2daf5 83%,#bdf3fd 100%); /* W3C */ | ||
} | ||
#main .formula h2 span{ | ||
font-weight:normal; | ||
} | ||
#inputArea{ | ||
margin:1.618em 0; | ||
} | ||
#formula_input{width:500px;} | ||
/*-----------FORMULA STYLES------------*/ | ||
.function{ | ||
color:#069; | ||
} | ||
.function_start, .function_stop{ | ||
color:#ff0000; | ||
} | ||
.tabs{border-left:dotted 1px #a0a0a0} | ||
.quote_mark, .text{color:#0000ff} | ||
/*-----------FORMULA STYLES------------*/ | ||
#formula_input{width:90%} | ||
/*]]>*/</style> | ||
|
||
|
||
<!--[if gte IE 9]> | ||
<style type="text/css"> | ||
.gradient { | ||
filter: none; | ||
} | ||
</style> | ||
<![endif]--> | ||
</head> | ||
|
||
<body> | ||
|
||
<div id="container"> | ||
<header> | ||
<h1>Online Excel Formula Beautifier (Beta)</h1> | ||
</header> | ||
|
||
<div id="main" role="main"> | ||
<!-- Side Content --> | ||
<div id="sideContent" class="span-6 last"> | ||
<p> | ||
<label class="span-2" for="mode">Mode: </label> | ||
<div class="span-4 last"> | ||
<select id="mode" class="span-4 last" onchange="window.beautifier.changeMode_update(this.value)"> | ||
<option value="beautify">Beautify</option> | ||
<option value="js" selected="selected">Formula to JavaScript</option> | ||
</select> | ||
</div> | ||
</p> | ||
</div> | ||
|
||
<!-- Main Content --> | ||
<div id="container" class="span-12 colborder"> | ||
|
||
<div id="main" role="main" class="span-12 last"> | ||
<div id="inputArea"> | ||
<label for="formula_input">Start Typing formula here.</label><br /> | ||
<input type="text" id="formula_input" onkeyup="window.excelFormulaBeautifier.examples.beautifier.update()" /> | ||
<label for="formula_input">Enter your formula here. The leading = is optional.</label><br /> | ||
<input type="text" id="formula_input" onkeyup="window.beautifier.txtFormula_Update()" /> | ||
</div> | ||
<div class="formula"> | ||
<h2>excelFormulaUtilities.formatFormulaHTML( "<span id="fomatFormula_2"></span>" );</h2> | ||
<code id="fomatFormula_2_out"></code> | ||
<!--h2>excelFormulaUtilities.formatFormulaHTML( "<span id="fomatFormula_2"></span>" );</h2--> | ||
<pre id="fomatFormula_2_out"></pre> | ||
</div> | ||
|
||
</div> | ||
|
||
<footer> | ||
© copyright 2011 Josh Bennett | ||
</footer> | ||
</div> | ||
|
||
|
||
|
||
<script src="js/excelFormulaUtilities-0.9.1.min.js"></script> | ||
<script src="js/beautifier.js"></script> | ||
<script src="src/core.js"></script> | ||
<script src="src/ExcelFormulaUtilities.js"></script> | ||
|
||
<script type="text/javascript"> | ||
/*<![CDATA[*/ | ||
(function(){ | ||
var MODE_BEAUTIFY = "beautify" | ||
,MODE_JS = "js" | ||
, txtFormula | ||
, formulaOut | ||
, selMode | ||
, trim = window.excelFormulaUtilities.string.trim; | ||
|
||
window.beautifier = {} | ||
|
||
// Convert the input fields text to the out | ||
function convertFormula( inputElement, outputElement, mode ) { | ||
switch(mode){ | ||
case MODE_BEAUTIFY: | ||
try{ | ||
outputElement.innerHTML = excelFormulaUtilities.formatFormula( trim(inputElement.value) ); | ||
outputElement.style.background = "transparent"; | ||
} catch (ex){ | ||
outputElement.style.background = "red"; | ||
} | ||
break; | ||
case MODE_JS: | ||
try{ | ||
outputElement.innerHTML = excelFormulaUtilities.formula2JavaScript( trim(inputElement.value) ); | ||
outputElement.style.background = "transparent"; | ||
} catch (ex){ | ||
outputElement.style.background = "red"; | ||
} | ||
break; | ||
} | ||
} | ||
|
||
window.onload = function(){ | ||
|
||
txtFormula = document.getElementById('formula_input'), | ||
formulaOut = document.getElementById('fomatFormula_2_out'); | ||
selMode = document.getElementById('mode'); | ||
|
||
// Handle when the formula input changes value | ||
window.beautifier.txtFormula_Update = function(){ | ||
convertFormula(txtFormula, formulaOut, selMode.value); | ||
} | ||
|
||
// Handle when the mode input changes value | ||
window.beautifier.changeMode_update = function(){ | ||
|
||
} | ||
} | ||
}()); | ||
/*]]>*/ | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters