Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make javascript external plus some details
- Loading branch information
Showing
6 changed files
with
73 additions
and
59 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
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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,54 +1,13 @@ | |||
<div id="left" class="container"> | <div id="left" class="container"> | ||
<h2>Markup ${FormHelper.Select("type", markupTypes, {@onchange: 'site.process();'})}</h2> | <h2>Markup ${FormHelper.Select("type", markupTypes)}</h2> | ||
<div class="inner"> | <div class="inner">${FormHelper.TextArea("source", {@rows:20, @cols: 60})}</div> | ||
${FormHelper.TextArea("source", {@rows:20, @cols: 80, @onchange: 'site.process();', @onkeypress: 'site.resizeTextarea(this);', @onkeyup: 'site.resizeTextarea(this);'})} | |||
</div> | </div> | ||
</div> | |||
|
|||
<div id="right" class="container"> | <div id="right" class="container"> | ||
<h2>HTML</h2> | <h2>HTML</h2> | ||
<div id="destination" class="inner"></div> | <div id="destination" class="inner"></div> | ||
</div> | </div> | ||
|
<script type="text/javascript"> | ||
<script type="text/javascript"> /*<![CDATA[*/ | /*<![CDATA[*/ | ||
var Site = new Class.create({ | var site = new Site("${UrlHelper.For({@controller:'home', @action:'process'})}"); | ||
|
/*]]>*/ | ||
previousValue: '', | </script> | ||
previousType: -1, | |||
|
|||
initialize: function() { | |||
this.previousValue = ''; | |||
new PeriodicalExecuter(this.process, 2); | |||
$('source').focus(); | |||
}, | |||
|
|||
process: function() { | |||
var newValue = $('source').value; | |||
var newType =$("type").value; | |||
if (newValue != this.previousValue || newType != this.previousType) { | |||
new Ajax.Request("${UrlHelper.For({@controller:'home', @action:'process'})}", { | |||
parameters: { source: newValue, type: newType } | |||
}); | |||
this.previousValue = newValue; | |||
this.previousType = newType; | |||
} | |||
}, | |||
|
|||
// based on http://blog.bigsmoke.us/2007/02/18/automatic-html-textarea-resizing | |||
resizeTextarea: function(textArea) { | |||
if (!textArea.originalRowCount) { | |||
textArea.originalRowCount = textArea.rows; | |||
} | |||
var rows = textArea.value.split('\n'); | |||
var neededRows = 1; | |||
for (var i = 0; i < rows.length; i++) { | |||
var row = rows[i]; | |||
neededRows += (row.length > textArea.cols) ? Math.floor(row.length / textArea.cols) : 1; | |||
} | |||
textArea.rows = Math.max(neededRows, textArea.originalRowCount); | |||
} | |||
}); | |||
|
|||
var site = new Site(); | |||
|
|||
/*]]>*/</script> |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,51 @@ | |||
var Site = new Class.create({ | |||
|
|||
previousValue: '', | |||
previousType: -1, | |||
updateUrl: '', | |||
|
|||
initialize: function(updateUrl) { | |||
new PeriodicalExecuter(this.process.bind(this), 2); | |||
this.updateUrl = updateUrl; | |||
this.previousValue = ''; | |||
this.previousType = -1; | |||
$('type') | |||
.observe("change", this.process.bind(this)) | |||
$('source') | |||
.observe("change", this.process.bind(this)) | |||
.observe("keyup", this.resizeTextarea) | |||
.observe("keypress", this.resizeTextarea) | |||
.focus(); | |||
}, | |||
|
|||
process: function() { | |||
var newValue = $("source").value; | |||
var newType = $("type").value; | |||
if (newValue != this.previousValue || newType != this.previousType) { | |||
if (!newValue) { | |||
Element.update("destination", ""); | |||
} else { | |||
new Ajax.Request(this.updateUrl, { | |||
parameters: { source: newValue, type: newType } | |||
}); | |||
} | |||
this.previousValue = newValue; | |||
this.previousType = newType; | |||
} | |||
}, | |||
|
|||
// based on http://blog.bigsmoke.us/2007/02/18/automatic-html-textarea-resizing | |||
resizeTextarea: function() { | |||
var textArea = $('source'); | |||
if (!textArea.originalRowCount) { | |||
textArea.originalRowCount = textArea.rows; | |||
} | |||
var rows = textArea.value.split('\n'); | |||
var neededRows = 1; | |||
for (var i = 0; i < rows.length; i++) { | |||
var row = rows[i]; | |||
neededRows += (row.length > textArea.cols) ? Math.floor(row.length / textArea.cols) : 1; | |||
} | |||
textArea.rows = Math.max(neededRows, textArea.originalRowCount); | |||
} | |||
}); |