diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-18 00:47:25 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-18 00:47:25 +0000 |
commit | 89e8523da19d3a8150f508e9fcbcfc797b9b9c0c (patch) | |
tree | 9b45dd58f14718e064b94df928f9549e4d52c3e5 /third_party/jstemplate/tutorial_examples | |
parent | 70fa3a4c64429c867d837c4a31d8d11aafeb5a4f (diff) | |
download | chromium_src-89e8523da19d3a8150f508e9fcbcfc797b9b9c0c.zip chromium_src-89e8523da19d3a8150f508e9fcbcfc797b9b9c0c.tar.gz chromium_src-89e8523da19d3a8150f508e9fcbcfc797b9b9c0c.tar.bz2 |
Move chrome\third_party\jstemplate to third_party\jstemplate since it's used from ui\.
This is a cleanup after r177425 which I didn't want to do in that already large cl.
BUG=169170
Review URL: https://codereview.chromium.org/11971042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177551 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/jstemplate/tutorial_examples')
12 files changed, 640 insertions, 0 deletions
diff --git a/third_party/jstemplate/tutorial_examples/01-quick.html b/third_party/jstemplate/tutorial_examples/01-quick.html new file mode 100644 index 0000000..df8c7e5 --- /dev/null +++ b/third_party/jstemplate/tutorial_examples/01-quick.html @@ -0,0 +1,33 @@ +<html> +<head><title>Jstemplates: Quick example</title> + <script src="../util.js" type="text/javascript"></script> + <script src="../jsevalcontext.js" type="text/javascript"></script> + <script src="../jstemplate.js" type="text/javascript"></script> + <script type="text/javascript"> + var favdata = { + title: 'Favorite Things', + favs: ['raindrops', 'whiskers', 'mittens'] + }; + + function showData(data) { + // This is the javascript code that processes the template: + var input = new JsEvalContext(data); + var output = document.getElementById('t1'); + jstProcess(input, output); + } + </script> +</head> +<body onload="showData(favdata)"> + +<!-- +This is the template: +--> +<div id="t1"> + <h1 jscontent="title"></h1> + <ul><li jscontent="$this" jsselect="favs"></li></ul> +</div> +<p> +<a href="#" onclick="favdata.favs.push('packages');showData(favdata);">Reprocess</a> +</p> +</body> +</html> diff --git a/third_party/jstemplate/tutorial_examples/02-gettpl.html b/third_party/jstemplate/tutorial_examples/02-gettpl.html new file mode 100644 index 0000000..f4829c7 --- /dev/null +++ b/third_party/jstemplate/tutorial_examples/02-gettpl.html @@ -0,0 +1,57 @@ +<html> +<head><title>Jstemplates: Quick example</title> + <script src="../util.js" type="text/javascript"></script> + <script src="../jsevalcontext.js" type="text/javascript"></script> + <script src="../jstemplate.js" type="text/javascript"></script> + <script type="text/javascript"> + var favdata = {title: 'Favorite Things', favs:['raindrops', 'whiskers', 'mittens']}; + + function showData(reprocess) { + var templateToProcess; + var peg = document.getElementById('peg'); + + if (!reprocess) { // Get a copy of the template: + templateToProcess = jstGetTemplate('t1'); + // Clear the element to which we'll attach the template: + peg.innerHTML = ''; + // Attach the template + domAppendChild(peg, templateToProcess); + } + else { // Use the copy we already have + templateToProcess = peg; + } + // Wrap our data in a context object: + var processingContext = new JsEvalContext(favdata); + + // Process the template + jstProcess(processingContext, templateToProcess); + } + </script> + <link rel="stylesheet" type="text/css" href="css/maps2.deb.css"/> +</head> +<body onload="showData(false)"> +<!-- +The element to which our template will be attached at display-time: +--> +<div id="peg"></div> + +<!-- +A container to hide our template: +--> +<div style="display:none"> + +<!-- +This is the template div. It will be copied and attached to the div above. +--> +<div id="t1"> + <h1 jscontent="title"></h1> + <ul><li jscontent="$this" jsselect="favs"></li></ul> +</div> + +</div> + +<p> +<a href="#" onclick="favdata.favs.push('packages');showData(true);">Reprocess</a> +</p> +</body> +</html> diff --git a/third_party/jstemplate/tutorial_examples/03-environ.html b/third_party/jstemplate/tutorial_examples/03-environ.html new file mode 100644 index 0000000..2937a5c --- /dev/null +++ b/third_party/jstemplate/tutorial_examples/03-environ.html @@ -0,0 +1,25 @@ +<html> +<head><title>Address Book Using Jstemplates</title> + <script src="../util.js" type="text/javascript"></script> + <script src="../jsevalcontext.js" type="text/javascript"></script> + <script src="../jstemplate.js" type="text/javascript"></script> + <script type="text/javascript"> + function jsinit() { + var mydata = {dataProperty:'Nonny'}; + var context = new JsEvalContext(mydata); + context.setVariable('declaredVar','Ho'); + var template = document.getElementById('witha'); + jstProcess(context, template); + } + </script> + <link rel="stylesheet" type="text/css" href="css/maps2.deb.css"/> +</head> +<body onload="jsinit()"> + +<div id="witha"> +<div id="Hey" jscontent="this.parentNode.id + this.id + dataProperty + + $this.dataProperty + declaredVar"></div> +</div> + +</body> +</html> diff --git a/third_party/jstemplate/tutorial_examples/04-jscontent.html b/third_party/jstemplate/tutorial_examples/04-jscontent.html new file mode 100644 index 0000000..b264f3f --- /dev/null +++ b/third_party/jstemplate/tutorial_examples/04-jscontent.html @@ -0,0 +1,29 @@ +<html> +<head><title>Jstemplates: Quick example</title> + <script src="../util.js" type="text/javascript"></script> + <script src="../jsevalcontext.js" type="text/javascript"></script> + <script src="../jstemplate.js" type="text/javascript"></script> + <script type="text/javascript"> + var tplData = "Joe User"; + + function showData() { + // This is the javascript code that processes the template: + var input = new JsEvalContext(tplData); + var output = document.getElementById('tpl'); + jstProcess(input, output); + } + </script> +</head> +<body onload="showData()"> + +<!-- +This is the template: +--> +<div id="tpl"> +Welcome <span jscontent="$this"> +(This placeholder name will be replaced by the actual username.) +</span> +</div> + +</body> +</html> diff --git a/third_party/jstemplate/tutorial_examples/05-jsselect.html b/third_party/jstemplate/tutorial_examples/05-jsselect.html new file mode 100644 index 0000000..990df0f --- /dev/null +++ b/third_party/jstemplate/tutorial_examples/05-jsselect.html @@ -0,0 +1,42 @@ +<html> +<head><title>Jstemplates: Quick example</title> + <script src="../util.js" type="text/javascript"></script> + <script src="../jsevalcontext.js" type="text/javascript"></script> + <script src="../jstemplate.js" type="text/javascript"></script> + <script type="text/javascript"> + + var tplData = {username:"Jane User", + addresses:[ + {location:"111 8th Av.", label:"NYC front door"}, + {location:"76 9th Av.", label:"NYC back door"}, + {location:"Mountain View", label:"Mothership"} + ] + }; + + function showData() { + // This is the javascript code that processes the template: + var input = new JsEvalContext(tplData); + var output = document.getElementById('tpl'); + jstProcess(input, output); + } + </script> +</head> +<body onload="showData()"> + +<!-- +This is the template: +--> + +<div id="tpl"> +<h1> + <span jsselect="username" jscontent="$this">User de Fault</span>'s + Address Book +</h1> +<table cellpadding="5"> +<tr><td><h2>Location:</h2></td><td><h2>Label:</h2></td></tr> +<tr jsselect="addresses"><td jscontent="location"></td><td jscontent="label"></td></tr> +</table> +</div> + +</body> +</html> diff --git a/third_party/jstemplate/tutorial_examples/06-jsdisplay.html b/third_party/jstemplate/tutorial_examples/06-jsdisplay.html new file mode 100644 index 0000000..cd06982 --- /dev/null +++ b/third_party/jstemplate/tutorial_examples/06-jsdisplay.html @@ -0,0 +1,40 @@ +<html> +<head><title>Jstemplates: Quick example</title> + <script src="../util.js" type="text/javascript"></script> + <script src="../jsevalcontext.js" type="text/javascript"></script> + <script src="../jstemplate.js" type="text/javascript"></script> + <script type="text/javascript"> + var tplData = {username:"Joe User", + addresses:[ + {location:"111 8th Av.", label:"NYC front door"}, + {location:"76 9th Av.", label:"NYC back door"}, + {location:"Mountain View", label:"Mothership"} + ]}; + + function showData() { + // This is the javascript code that processes the template: + var input = new JsEvalContext(tplData); + var output = document.getElementById('tpl'); + jstProcess(input, output); + } + </script> +</head> +<body onload="showData()"> + +<!-- +This is the template: +--> +<div id="tpl"> +<h1> + <span jsselect="username" jscontent="$this">User de Fault</span>'s + Address Book +</h1> +<span jsdisplay="addresses.length==0">Address book is empty.</span> +<table cellpadding="5" jsdisplay="addresses.length"> +<tr><td><h2>Location:</h2></td><td><h2>Label:</h2></td></tr> +<tr jsselect="addresses"><td jscontent="location"></td><td jscontent="label"></td></tr> +</table> +</div> + +</body> +</html> diff --git a/third_party/jstemplate/tutorial_examples/07-jsdisplay-empty.html b/third_party/jstemplate/tutorial_examples/07-jsdisplay-empty.html new file mode 100644 index 0000000..d5da9b3 --- /dev/null +++ b/third_party/jstemplate/tutorial_examples/07-jsdisplay-empty.html @@ -0,0 +1,36 @@ +<html> +<head><title>Jstemplates: Quick example</title> + <script src="../util.js" type="text/javascript"></script> + <script src="../jsevalcontext.js" type="text/javascript"></script> + <script src="../jstemplate.js" type="text/javascript"></script> + <script type="text/javascript"> + var tplData = {username:"Joe User", + addresses:[]}; + + function showData() { + // This is the javascript code that processes the template: + var input = new JsEvalContext(tplData); + var output = document.getElementById('tpl'); + jstProcess(input, output); + } + </script> +</head> +<body onload="showData()"> + +<!-- +This is the template: +--> +<div id="tpl"> +<h1> + <span jsselect="username" jscontent="$this">User de Fault</span>'s + Address Book +</h1> +<span jsdisplay="addresses.length==0">Address book is empty.</span> +<table cellpadding="5" jsdisplay="addresses.length"> +<tr><td><h2>Location:</h2></td><td><h2>Label:</h2></td></tr> +<tr jsselect="addresses"><td jscontent="location"></td><td jscontent="label"></td></tr> +</table> +</div> + +</body> +</html> diff --git a/third_party/jstemplate/tutorial_examples/08-transclude.html b/third_party/jstemplate/tutorial_examples/08-transclude.html new file mode 100644 index 0000000..ebab76f --- /dev/null +++ b/third_party/jstemplate/tutorial_examples/08-transclude.html @@ -0,0 +1,82 @@ +<html> +<head><title>Outline Tree Using Jstemplates</title> + <script src="../util.js" type="text/javascript"></script> + <script src="../jsevalcontext.js" type="text/javascript"></script> + <script src="../jstemplate.js" type="text/javascript"></script> + <script type="text/javascript"> + // Hierarchical data: + var tplData = + { title: "Jstemplates", items: [ + { title: "Using Jstemplates", items: [ + { title: "The Jstemplates Module"}, + { title: "Javascript Data"}, + { title: "Template HTML"}, + { title: "Processing Templates with Javascript Statements"} + ] + }, + { title: "Template Processing Instructions", items: [ + { title: "Processing Environment" }, + { title: "Instruction Attributes", items: [ + {title: "jscontent"}, {title: "jsselect"}, {title: "jsdisplay"}, + {title: "transclude"},{title: "jsvalues"}, {title: "jsskip"}, {title: "jseval"} + ]} + ]} + ]}; + + var PEG_NAME = 'peg'; + var TEMPLATE_NAME = 'tpl'; + + // Called by the body onload handler: + function jsinit() { + pegElement = domGetElementById(document, PEG_NAME); + loadData(pegElement, TEMPLATE_NAME, tplData); + } + + function loadData(peg, templateId, data) { + // Get a copy of the template: + var templateToProcess = jstGetTemplate(templateId); + + // Wrap our data in a context object: + var processingContext = new JsEvalContext(data); + + // Process the template + jstProcess(processingContext, templateToProcess); + + // Clear the element to which we'll attach the processed template: + peg.innerHTML = ''; + + // Attach the template: + domAppendChild(peg, templateToProcess); + } + </script> + <link rel="stylesheet" type="text/css" href="css/maps2.deb.css"/> +</head> +<body onload="jsinit()"> + +<!-- +This is the div to which the instantiated template will be attached. +--> +<div id="peg"></div> + +<!-- +A container to hide our template: +--> +<div style="display:none"> +<!-- +This is the template div. It will be copied and attached to the div above with: + var apt = jstGetTemplate('apt'); + appendChild(panel, apt) +--> + <div id="tpl"> + <span jscontent="title">Outline heading</span> + <ul jsdisplay="items.length"> + <li jsselect="items"> + <!--Recursive tranclusion: --> + <div transclude="tpl"></div> + </li> + </ul> + </div> + +</div> +</body> +</html> diff --git a/third_party/jstemplate/tutorial_examples/09-jsvalues.html b/third_party/jstemplate/tutorial_examples/09-jsvalues.html new file mode 100644 index 0000000..9267846 --- /dev/null +++ b/third_party/jstemplate/tutorial_examples/09-jsvalues.html @@ -0,0 +1,23 @@ +<html> +<head><title>Address Book Using Jstemplates</title> + <script src="../util.js" type="text/javascript"></script> + <script src="../jsevalcontext.js" type="text/javascript"></script> + <script src="../jstemplate.js" type="text/javascript"></script> + <script type="text/javascript"> + function jsinit() { + var mydata = {end: 'Bar'}; + var context = new JsEvalContext(mydata); + var template = document.getElementById('out'); + jstProcess(context, template); + } + </script> + <link rel="stylesheet" type="text/css" href="css/maps2.deb.css"/> +</head> +<body onload="jsinit()"> + +<div id="out"> +<div id="Food" jsvalues=".id:'Joe';.style.fontSize:'30pt'" jscontent="this.parentNode.id + this.id + $this.end"></div> +</div> + +</body> +</html> diff --git a/third_party/jstemplate/tutorial_examples/10-jsvalues.html b/third_party/jstemplate/tutorial_examples/10-jsvalues.html new file mode 100644 index 0000000..a24d645 --- /dev/null +++ b/third_party/jstemplate/tutorial_examples/10-jsvalues.html @@ -0,0 +1,96 @@ +<html> +<head><title>Outline Tree Using Jstemplates</title> + <script src="../util.js" type="text/javascript"></script> + <script src="../jsevalcontext.js" type="text/javascript"></script> + <script src="../jstemplate.js" type="text/javascript"></script> + <script type="text/javascript"> + // Hierarchical data: + var tplData = + { title: "Jstemplates", items: [ + { title: "Using Jstemplates", items: [ + { title: "The Jstemplates Module"}, + { title: "Javascript Data"}, + { title: "Template HTML"}, + { title: "Processing Templates with Javascript Statements"} + ] + }, + { title: "Template Processing Instructions", items: [ + { title: "Processing Environment" }, + { title: "Instruction Attributes", items: [ + {title: "jscontent"}, {title: "jsselect"}, {title: "jsdisplay"}, + {title: "transclude"},{title: "jsvalues"}, {title: "jsskip"}, {title: "jseval"} + ]} + ]} + ]}; + + var PEG_NAME = 'peg'; + var TEMPLATE_NAME = 'tpl'; + + // Called by the body onload handler: + function loadAll() { + var pegElement = domGetElementById(document, PEG_NAME); + loadData(pegElement, TEMPLATE_NAME, tplData); + } + + function loadData(peg, templateId, data) { + // Get a copy of the template: + var templateToProcess = jstGetTemplate(templateId); + + // Wrap our data in a context object: + var processingContext = new JsEvalContext(data); + + // Process the template + jstProcess(processingContext, templateToProcess); + + // Clear the element to which we'll attach the processed template: + peg.innerHTML = ''; + + // Attach the template: + domAppendChild(peg, templateToProcess); + } + + // Function called by onclick to record state of closedness and + // refresh the outline display + function setClosed(jstdata, closedVal) { + jstdata.closed = closedVal; + loadAll(); + } + </script> + <link rel="stylesheet" type="text/css" href="css/maps2.deb.css"/> +</head> +<body onload="loadAll()"> + +<!-- +This is the div to which the instantiated template will be attached. +--> +<div id="peg"></div> + +<!-- +A container to hide our template: +--> +<div style="display:none"> +<!-- +This is the template div. It will be copied and attached to the div above with: + var apt = jstGetTemplate('apt'); + appendChild(panel, apt) +--> + <div id="tpl"> + <!-- + Links to open and close outline sections: + --> + <a href="#" jsdisplay="closed" jsvalues=".jstdata:$this" onclick="setClosed(this.jstdata,0)">[Open]</a> + <a href="#" jsdisplay="!closed && items.length" jsvalues=".jstdata:$this" + onclick="setClosed(this.jstdata,1)">[Close]</a> + + <span jscontent="title">Outline heading</span> + <ul jsdisplay="items.length && !closed"> + <li jsselect="items"> + <!--Recursive tranclusion: --> + <div transclude="tpl"></div> + </li> + </ul> + </div> + +</div> +</body> +</html> diff --git a/third_party/jstemplate/tutorial_examples/11-jseval.html b/third_party/jstemplate/tutorial_examples/11-jseval.html new file mode 100644 index 0000000..ad9b7e2 --- /dev/null +++ b/third_party/jstemplate/tutorial_examples/11-jseval.html @@ -0,0 +1,118 @@ +<html> +<head><title>Outline Tree Using Jstemplates</title> + <script src="../util.js" type="text/javascript"></script> + <script src="../jsevalcontext.js" type="text/javascript"></script> + <script src="../jstemplate.js" type="text/javascript"></script> + <script type="text/javascript"> + // Hierarchical data: + var tplData = + { title: "Jstemplates", items: [ + { title: "", items: [ + { title: "The Jstemplates Module"}, + { title: "Javascript Data"}, + { title: "Template HTML"}, + { title: "Processing Templates with Javascript Statements"} + ] + }, + { title: "Template Processing Instructions", items: [ + { title: "Processing Environment" }, + { title: "", items: [ + {title: "jscontent"}, {title: "jsselect"}, {title: "jsdisplay"}, + {title: "transclude"},{title: "jsvalues"}, {title: "jsskip"}, {title: "jseval"} + ]} + ]} + ]}; + + var PEG_NAME = 'peg'; + var TEMPLATE_NAME = 'tpl'; + var TITLE_COUNT_NAME = 'titleCountPeg'; + var TITLE_TEMPLATE_NAME = 'titleCountTpl'; + + // Called by the body onload handler: + function loadAll() { + var titleCountElement = domGetElementById(document, TITLE_COUNT_NAME); + var pegElement = domGetElementById(document, PEG_NAME); + var counter = {full: 0, empty: 0}; + + loadData(pegElement, TEMPLATE_NAME, tplData, counter); + loadData(titleCountElement, TITLE_TEMPLATE_NAME, tplData, counter); + } + + + function loadData(peg, templateId, data, counter) { + // Get a copy of the template: + var templateToProcess = jstGetTemplate(templateId); + + // Wrap our data in a context object: + var processingContext = new JsEvalContext(data); + + processingContext.setVariable('$counter', counter); + + // Process the template + jstProcess(processingContext, templateToProcess); + + // Clear the element to which we'll attach the processed template: + peg.innerHTML = ''; + + // Attach the template: + domAppendChild(peg, templateToProcess); + } + + // Function called by onclick to record state of closedness and + // refresh the outline display + function setClosed(jstdata, closedVal) { + jstdata.closed = closedVal; + loadAll(); + } + </script> + <link rel="stylesheet" type="text/css" href="css/maps2.deb.css"/> +</head> +<body onload="loadAll()"> + +<!-- +This is the div to which the instantiated template will be attached. +--> +<div id="peg"></div> +<div id="titleCountPeg"></div> +<!-- +A container to hide our template: +--> +<div style="display:none"> +<!-- +This is the template div. It will be copied and attached to the div above with: + var apt = jstGetTemplate('apt'); + appendChild(panel, apt) +--> + <div id="tpl"> + <!-- + Links to open and close outline sections: + --> + <a href="#" jsdisplay="closed" + jsvalues=".jstdata:$this" + onclick="setClosed(this.jstdata,0)">[Open]</a> + + <a href="#" jsdisplay="!closed && items.length" + jsvalues=".jstdata:$this" + onclick="setClosed(this.jstdata,1)">[Close]</a> + + <span jscontent="title" + jseval="title? $counter.full++: $counter.empty++"> + Outline heading + </span> + <ul jsdisplay="items.length && !closed"> + <li jsselect="items"> + <!--Recursive tranclusion: --> + <div transclude="tpl"></div> + </li> + </ul> + </div> + + <div id="titleCountTpl"> + <p> + This outline has <span jscontent="$counter.empty"></span> empty titles + and <span jscontent="$counter.full"></span> titles with content. + </p> + </div> +</div> +</body> +</html> diff --git a/third_party/jstemplate/tutorial_examples/12-parent.html b/third_party/jstemplate/tutorial_examples/12-parent.html new file mode 100644 index 0000000..04f9797 --- /dev/null +++ b/third_party/jstemplate/tutorial_examples/12-parent.html @@ -0,0 +1,59 @@ +<html> +<head><title>Jstemplates: Quick example</title> + <script src="../util.js" type="text/javascript"></script> + <script src="../jsevalcontext.js" type="text/javascript"></script> + <script src="../jstemplate.js" type="text/javascript"></script> + <script type="text/javascript"> + var user = "Jane User"; + + var tpl1Data = {addresses:[ + {location:"111 8th Av.", label:"NYC front door"}, + {location:"76 9th Av.", label:"NYC back door"}, + {location:"Mountain View", label:"Mothership"} + ] + }; + + var tpl2Data = {addresses:[ + {location:"534 Carlton Ave."}, + {location:"772 Broadway"} + ] + }; + + function showData() { + // This is the javascript code that processes the template: + var parent = new JsEvalContext(); + parent.setVariable('username', user); + + var input1 = new JsEvalContext( tpl1Data, parent); + var output1 = document.getElementById('tpl1'); + jstProcess(input1, output1); + + var input2 = new JsEvalContext( tpl2Data, parent); + var output2 = document.getElementById('tpl2'); + jstProcess(input2, output2); + } + </script> +</head> +<body onload="showData()"> + + +<div id="tpl1"> +<h1> + <span jsselect="username" jscontent="$this">User de Fault</span>'s + Address Book +</h1> +<table cellpadding="5"> +<tr><td><h2>Location:</h2></td><td><h2>Label:</h2></td></tr> +<tr jsselect="addresses"><td jscontent="location"></td><td jscontent="label"></td></tr> +</table> +</div> + +<div id="tpl2"> +<h1 jsselect="username" jscontent="$this + '\'s Previous Searches'"></h1> +<ul> +<li jsselect="addresses" jscontent="location"></li> +</ul> +</div> + +</body> +</html> |