JavaScript-Writer
view release on metacpan or search on metacpan
doc/slides/yapcasia2008.xul view on Meta::CPAN
jQuery("#foo").show()[[EM:;]]
----
print js->show();
----
Enforce
void context
----
void()
----
void( js->foo() )
----
print scalar(js->foo(), js->as_string);
----
Still
researching
----
TODO:
----
ALIGN::left
â variable scope
â context ([[EM:this]] variable)
â object property assignment
â helper based on specific js libraries
----
ALIGN::left
Goal:
â Completely writes a JSAN module
with JavaScript::Writer
----
å®
----
âº
</html:textarea>
<deck flex="1" id="deck">
<vbox flex="1"
onmouseup="Presentation.handleEvent(event);"
onmousedown="Presentation.handleEvent(event);"
onmousemove="Presentation.handleEvent(event);">
<toolbox id="canvasToolbar">
<toolbar>
<toolbarbutton oncommand="Presentation.home()" label="|<<"
observes="canBack"/>
<toolbarbutton oncommand="Presentation.back()" label="<"
observes="canBack"/>
<toolbarbutton oncommand="Presentation.forward()" label=">"
observes="canForward"/>
<toolbarbutton oncommand="Presentation.end()" label=">>|"
observes="canForward"/>
<toolbarseparator/>
<hbox align="center">
<textbox id="current_page" size="4"
oninput="if (this.value) Presentation.showPage(parseInt(this.value)-1);"/>
<toolbarbutton id="pages-list-button"
type="menu"
label="Select Page"
tooltiptext="Select Page"
class="dropmarker-button">
<menupopup id="pages-list"
onpopupshowing="if (event.target == this) Presentation.preventToShowHideToolbar = true;"
onpopuphiding="if (event.target == this) Presentation.preventToShowHideToolbar = false;"
oncommand="Presentation.showPage(parseInt(event.target.value));"/>
</toolbarbutton>
<description value="/"/>
<description id="max_page"/>
</hbox>
<toolbarseparator/>
<vbox flex="2">
<spacer flex="1"/>
<scrollbar id="scroller"
align="center" orient="horizontal"
oncommand="Presentation.showPage(parseInt(event.target.getAttribute('curpos')));"
onclick="Presentation.showPage(parseInt(event.target.getAttribute('curpos')));"
onmousedown="Presentation.onScrollerDragStart();"
onmousemove="Presentation.onScrollerDragMove();"
onmouseup="Presentation.onScrollerDragDrop();"/>
<spacer flex="1"/>
</vbox>
<toolbarseparator/>
<toolbarbutton label="Pen"
id="penButton"
type="checkbox"
autoCheck="false"
oncommand="StrokablePresentationService.toggleCheck();"/>
<spacer flex="1"/>
<toolbarbutton id="func-menu-button"
type="menu"
label="Function">
<menupopup
onpopupshowing="Presentation.preventToShowHideToolbar = true;"
onpopuphiding="Presentation.preventToShowHideToolbar = false;">
<menuitem label="Set Timer"
oncommand="Presentation.setTimer();" />
<menuseparator/>
<menuitem label="Start Auto-Cruise"
id="autoButton"
type="checkbox"
autoCheck="false"
oncommand="Presentation.toggleAutoCruiseMode();" />
<menu id="auto-interval-button"
label="Change Interval">
<menupopup id="auto-interval-list"
onpopupshowing="(this.getElementsByAttribute('value', Presentation.autoCruiseInterval)[0] || this.lastChild).setAttribute('checked', true);"
oncommand="Presentation.changeAutoCruiseInterval(parseInt(event.target.value));">
<menuitem type="radio" radiogroup="autocruise-interval"
label="1 sec" value="1000"/>
<menuitem type="radio" radiogroup="autocruise-interval"
label="2 sec" value="2000"/>
<menuitem type="radio" radiogroup="autocruise-interval"
label="3 sec" value="3000"/>
<menuitem type="radio" radiogroup="autocruise-interval"
label="4 sec" value="4000"/>
<menuitem type="radio" radiogroup="autocruise-interval"
label="5 sec" value="5000"/>
<menuseparator/>
<menuitem type="radio" radiogroup="autocruise-interval"
label="1 min" value="60000"/>
<menuitem type="radio" radiogroup="autocruise-interval"
label="2 min" value="120000"/>
<menuitem type="radio" radiogroup="autocruise-interval"
label="3 min" value="180000"/>
<menuitem type="radio" radiogroup="autocruise-interval"
label="4 min" value="240000"/>
<menuitem type="radio" radiogroup="autocruise-interval"
label="5 min" value="300000"/>
<menuseparator/>
<menuitem type="radio" radiogroup="autocruise-interval"
label="Custom"
oncommand="
var current = Presentation.autoCruiseInterval;
var val = parseInt(prompt('input interval (sec)', parseInt(current/1000)));
if (isNaN(val)) {
event.preventBubble();
return;
}
else
val = val * 1000;
this.value = val;
"/>
</menupopup>
</menu>
<menuseparator/>
<menuitem oncommand="Presentation.print();" label="Print"/>
<menu id="auto-interval-button"
label="Thumbnail Format">
<menupopup
onpopupshowing="(this.getElementsByAttribute('value', Presentation.imageType)[0] || this.firstChild).setAttribute('checked', true);"
oncommand="Presentation.imageType = event.target.value;">
<menuitem type="radio" radiogroup="print-image-type"
label="PNG" value="png"/>
<menuitem type="radio" radiogroup="print-image-type"
label="JPEG (50%)" value="jpeg"/>
</menupopup>
</menu>
<menuseparator/>
<menuitem id="toggleEva" label="Eva Mode"
type="checkbox"
autoCheck="false"
oncommand="Presentation.toggleEvaMode();"/>
</menupopup>
</toolbarbutton>
<toolbarseparator/>
<toolbarbutton label="Edit"
oncommand="Presentation.toggleEditMode();"/>
<toolbarbutton oncommand="Presentation.reload();" label="Reload"/>
</toolbar>
</toolbox>
<vbox flex="1" id="canvas">
<stack flex="1">
<vbox flex="1">
<hbox id="headerBox" flex="1">
<label id="header"/>
<spacer flex="1"/>
<vbox>
<image id="logo"/>
<spacer flex="1"/>
</vbox>
</hbox>
<spacer flex="19"/>
<hbox id="footerBox" flex="1">
<spacer flex="1"/>
<label id="footer"/>
</hbox>
</vbox>
<vbox flex="1"
onclick="Presentation.onPresentationClick(event);">
<spacer flex="1"/>
<hbox flex="1" id="contentBox">
<spacer flex="1"/>
<vbox id="content"/>
<spacer flex="1"/>
</hbox>
<spacer flex="1"/>
</vbox>
</stack>
</vbox>
<hbox id="indicatorBar"
onclick="Presentation.onIndicatorBarClick(event);">
<stack flex="1">
<vbox>
<progressmeter id="remainingPageIndicator"
type="determined" value="0"
flex="1"/>
<progressmeter id="remainingTimeIndicator"
type="determined" value="0"
flex="1"
collapsed="true"/>
</vbox>
<hbox flex="1">
<label value="Next:"/>
<description id="nextPage" flex="1" crop="end"/>
</hbox>
</stack>
</hbox>
</vbox>
<vbox flex="1" id="edit">
<toolbox>
<toolbar>
<menubar flex="1">
<menu label="File">
<menupopup>
<menuitem label="Save"
key="key_save"
oncommand="Presentation.output()"/>
<menuitem label="Reload"
key="key_reload"
oncommand="Presentation.reload()"/>
</menupopup>
</menu>
<menu label="Insert">
<menupopup>
<menuitem label="New Page"
key="key_insert_newpage"
oncommand="Presentation.insert('page')"/>
<menuseparator/>
<menuitem label="Header"
oncommand="Presentation.insert('header')"/>
<menuitem label="Footer"
oncommand="Presentation.insert('footer')"/>
<menuseparator/>
<menuitem label="Link"
oncommand="Presentation.insert('link')"/>
<menuitem label="Emphasis"
oncommand="Presentation.insert('em')"/>
<menuitem label="Preformatted"
oncommand="Presentation.insert('pre')"/>
<menuitem label="Monta"
oncommand="Presentation.insert('monta')"/>
<menuitem label="Image"
oncommand="Presentation.insert('img')"/>
</menupopup>
</menu>
</menubar>
<toolbarseparator/>
<toolbarbutton label="View"
oncommand="Presentation.toggleEditMode();"/>
<toolbarbutton oncommand="Presentation.reload();" label="Reload"/>
</toolbar>
</toolbox>
<textbox id="textField" flex="1" multiline="true"
oninput="Presentation.onEdit()"/>
</vbox>
</deck>
<broadcasterset>
<broadcaster id="canBack"/>
<broadcaster id="canForward"/>
</broadcasterset>
<commandset>
<command id="cmd_forward"
oncommand="if (Presentation.isPresentationMode) Presentation.forward();"/>
<command id="cmd_forwardStep"
oncommand="if (Presentation.isPresentationMode) Presentation.forwardStep();"/>
<command id="cmd_back"
oncommand="if (Presentation.isPresentationMode) Presentation.back();"/>
<command id="cmd_home"
oncommand="if (Presentation.isPresentationMode) Presentation.home();"/>
<command id="cmd_end"
oncommand="if (Presentation.isPresentationMode) Presentation.end();"/>
</commandset>
<keyset>
<key keycode="VK_ENTER" command="cmd_forwardStep"/>
<key keycode="32" command="cmd_forwardStep"/>
<key keycode="VK_RETURN" command="cmd_forwardStep"/>
<key keycode="VK_PAGE_DOWN" command="cmd_forwardStep"/>
<key keycode="VK_RIGHT" command="cmd_forwardStep"/>
<key keycode="VK_DOWN" command="cmd_forwardStep"/>
<!--key keycode="VK_BACK_SPACE" command="cmd_back"/-->
<key keycode="VK_PAGE_UP" command="cmd_back"/>
<key keycode="VK_UP" command="cmd_back"/>
<key keycode="VK_LEFT" command="cmd_back"/>
<key keycode="VK_HOME" command="cmd_home"/>
<key keycode="VK_END" command="cmd_end"/>
<key id="key_insert_newpage"
key="n" modifiers="accel" oncommand="Presentation.insert('page');"/>
<key id="key_save"
key="s" modifiers="accel" oncommand="Presentation.output();"/>
<key id="key_reload"
key="r" modifiers="accel" oncommand="Presentation.reload();"/>
<key id="key_reload"
key="p" modifiers="accel" oncommand="Presentation.print();"/>
<key key="e" modifiers="accel" oncommand="Presentation.toggleEditMode();"/>
<key key="e" modifiers="accel,shift" oncommand="Presentation.toggleEvaMode();"/>
</keyset>
doc/slides/yapcasia2008.xul view on Meta::CPAN
// so, we must concat all the text nodes.
this.textbox.value = "";
for (var i = 0; i < codes.childNodes.length; i++) {
this.textbox.value += codes.childNodes[i].nodeValue;
}
this._data = this.textbox.value.split(/----+/);
this.initData();
}
if (codes)
codes.parentNode.removeChild(codes);
return this._data;
},
set data(aValue){
this._data = aValue.split(/----+/);
this.initData();
return aValue;
},
initData : function()
{
var range = document.createRange();
range.selectNodeContents(this.list);
range.deleteContents();
var regexp = [
/^[\r\n\s]+/g,
/[\r\n\s]+$/g,
/(\r\n|[\r\n])/g
];
var title;
var titleRegExp = /^(TITLE::)([^\n]*)\n?/im;
var header = '';
var headerRegExp = /^(HEADER::)([^\n]*)\n?/im;
var footer = '';
var footerRegExp = /^(FOOTER::)([^\n]*)\n?/im;
var chapter = '';
var chapterRegExp = /^(CHAPTER::)([^\n]*)\n?/im;
var lastChapter;
var alignGlobal = 'center';
var align;
var alignRegExp = /^((GLOBAL-)?ALIGN::)(left|right|center|start|end)?\n?/im;
var imageMatchResults;
var imagesRegExp = this.makePhraseRegExp('%O%Oima?ge? +src="[^"]+" +width="[0-9]+" +height="[0-9]+"[^%C]*%C%C', 'gi');
var imagesRegExp2 = this.makePhraseRegExp('%O%Oima?ge? +src="([^"]+)"', 'i');
var image_src;
var plainTextRegExp = this.makePhraseRegExp('(%O%O\#[^:]+:(.+)%C%C|%O%OEM:(.+)(:EM)?%C%C|%O%OPRE:(.+)(:PRE)?%C%C|%O%Oima?ge? +src="[^"]*"[^%C]+%C%C|%O%O([^\\|%C]+)(\\|[^%C]+)?%C%C|%O([^%O]+)%C)', 'gi');
var hiddenRegExp = /^(HIDDEN|IGNORE)::true\n?/im;
var loadRegExp = /^LOAD::(.+)\n?/im;
var dataObj;
var i, j,
max = this._data.length;
var fragment = document.createDocumentFragment();
var popup;
var dataPath;
for (i = 0; i < max; i++)
{
image_src = null;
align = null;
dataPath = '';
this._data[i] = this._data[i]
.replace(regexp[0], '')
.replace(regexp[1], '')
.replace(regexp[2], '\n');
if (loadRegExp.test(this._data[i])) {
this._data[i] = this._data[i].replace(loadRegExp, '');
dataPath = RegExp.$1;
}
if (hiddenRegExp.test(this._data[i])) {
this._data.splice(i, 1);
max--;
i--;
continue;
}
while (titleRegExp.test(this._data[i])) {
this._data[i] = this._data[i].replace(titleRegExp, '');
if (String(RegExp.$1).toUpperCase() == 'TITLE::')
title = RegExp.$2 || '' ;
}
while (headerRegExp.test(this._data[i])) {
this._data[i] = this._data[i].replace(headerRegExp, '');
if (String(RegExp.$1).toUpperCase() == 'HEADER::')
header = RegExp.$2 || '' ;
}
while (footerRegExp.test(this._data[i])) {
this._data[i] = this._data[i].replace(footerRegExp, '');
if (String(RegExp.$1).toUpperCase() == 'FOOTER::')
footer = RegExp.$2 || '' ;
}
while (chapterRegExp.test(this._data[i])) {
this._data[i] = this._data[i].replace(chapterRegExp, '');
if (String(RegExp.$1).toUpperCase() == 'CHAPTER::')
chapter = RegExp.$2 || '' ;
}
while (alignRegExp.test(this._data[i])) {
this._data[i] = this._data[i].replace(alignRegExp, '');
align = (RegExp.$3 || '').toLowerCase();
if (align == 'left')
align = 'start';
else if (align == 'right')
align = 'end';
if (String(RegExp.$1).toUpperCase() == 'GLOBAL-ALIGN::') {
alignGlobal = align;
align = null;
}
}
imageMatchResults = this._data[i].match(imagesRegExp);
if (imageMatchResults) {
for (j = imageMatchResults.length-1; j > -1; j--)
image_src = this.preloadImage(imageMatchResults[j].match(imagesRegExp2)[1]);
}
this._data[i] = {
load : dataPath,
header : header,
footer : footer,
text : this._data[i].split('\n'),
image : image_src,
align : align || alignGlobal
};
this._data[i].plain = this._data[i].text
.join('\n')
.replace(plainTextRegExp, '$2$3$5$7$9')
.split('\n');
if (title !== void(0))
this._data[i].title = title;
this._data[i].chapter = chapter || title || '';
if (lastChapter === void(0) ||
lastChapter != this._data[i].chapter) {
lastChapter = this._data[i].chapter;
if (popup && popup.childNodes.length == 1) {
fragment.removeChild(fragment.lastChild);
fragment.appendChild(popup.removeChild(popup.lastChild));
}
popup = document.createElement('menupopup');
fragment.appendChild(document.createElement('menu'));
fragment.lastChild.setAttribute('label', this._data[i].chapter);
fragment.lastChild.appendChild(popup);
}
popup.appendChild(document.createElement('menuitem'));
popup.lastChild.setAttribute('type', 'radio');
popup.lastChild.setAttribute('radiogroup', 'pages');
popup.lastChild.setAttribute('label', (i+1)+': '+(
(this._data[i].plain.join('') || this._data[i].text.join(' ')).replace(/\s+/g, ' ')
));
popup.lastChild.setAttribute('value', i);
// if (image_src) {
// popup.lastChild.setAttribute('image', image_src);
// popup.lastChild.setAttribute('class', 'menuitem-iconic');
// }
}
if (fragment.childNodes.length == 1) {
range.selectNodeContents(fragment.firstChild.firstChild);
fragment = range.extractContents();
}
this.list.appendChild(fragment);
range.detach();
this.shownMontaLabels = [];
},
preloadImage : function(aURI)
{
if (aURI in this.imageRequests) return;
if (aURI.indexOf('http://') < 0 &&
aURI.indexOf('https://') < 0)
aURI = this.dataFolder+aURI;
this.imageRequests[aURI] = new XMLHttpRequest();
try {
this.imageRequests[aURI].open('GET', aURI);
this.imageRequests[aURI].onload = function() {
Presentation.imageRequests[aURI] = null;
};
this.imageRequests[aURI].send(null);
}
catch(e) {
this.imageRequests[aURI] = null;
}
return aURI;
},
imageRequests : {},
get isPresentationMode(){
return (this.deck.selectedIndex == 0);
},
get dataPath(){
if (!this._dataPath)
this.dataPath = String(location.href).replace(/#.+$/, '');
return this._dataPath;
},
set dataPath(aValue){
var oldDataPath = this._dataPath;
this._dataPath = aValue;
if (oldDataPath != aValue) {
this._dataFolder = this._dataPath.split('?')[0].replace(/[^\/]+$/, '');
}
return this._dataPath;
},
get dataFolder(){
if (!this._dataFolder)
( run in 1.025 second using v1.01-cache-2.11-cpan-364913b4093 )