Update selenium on rails using 'official' git repo

git://github.com/paytonrules/selenium-on-rails.git
This commit is contained in:
Reinier Balt 2008-12-02 10:05:41 +01:00
parent 198f3240b8
commit 9b504b3e47
159 changed files with 16409 additions and 11794 deletions

View file

@ -0,0 +1,8 @@
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
</head>
<body>
<h3>selenium-rc initial page</h3>
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
</head>
<body>
<h3>selenium-rc initial page</h3>
</body>
</html>

View file

@ -0,0 +1,109 @@
<html>
<!--
Copyright 2004 ThoughtWorks, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<HTA:APPLICATION ID="SeleniumHTARunner" APPLICATIONNAME="Selenium" >
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>Selenium Functional Test Runner</title>
<link rel="stylesheet" type="text/css" href="selenium.css" />
<script language="JavaScript" type="text/javascript" src="jsunit/app/jsUnitCore.js"></script>
<script type="text/javascript" src="scripts/xmlextras.js"></script>
<script language="JavaScript" type="text/javascript" src="lib/prototype.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/htmlutils.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserdetect.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserbot.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/find_matching_child.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-api.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-commandhandlers.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-executionloop.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-remoterunner.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-logging.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-version.js"></script>
<script language="JavaScript" type="text/javascript" src="xpath/misc.js"></script>
<script language="JavaScript" type="text/javascript" src="xpath/dom.js"></script>
<script language="JavaScript" type="text/javascript" src="xpath/xpath.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/user-extensions.js"></script>
<script language="JavaScript" type="text/javascript">
function openDomViewer() {
var autFrame = document.getElementById('myiframe');
var autFrameDocument = getIframeDocument(autFrame);
var domViewer = window.open(getDocumentBase(document) + 'domviewer/domviewer.html');
domViewer.rootDocument = autFrameDocument;
return false;
}
function cleanUp() {
if (LOG != null) {
LOG.close();
}
}
</script>
</head>
<body onLoad="setTimeout(function(){runSeleniumTest();},1000)" onUnload="cleanUp()">
<table border="1" style="height: 100%;">
<tr>
<td width="50%" height="30%">
<table>
<tr>
<td>
<img src="selenium-logo.png">
</td>
<td>
<h1><a href="http://selenium.thoughtworks.com" >Selenium</a> Functional Testing for Web Apps</h1>
Open Source From <a href="http://www.thoughtworks.com">ThoughtWorks, Inc</a> and Friends
<form action="">
<br/>Slow Mode:<INPUT TYPE="CHECKBOX" NAME="FASTMODE" VALUE="YES" onmouseup="slowClicked()">
<fieldset>
<legend>Tools</legend>
<button type="button" id="domViewer1" onclick="openDomViewer();">
View DOM
</button>
<button type="button" onclick="LOG.show();">
Show Log
</button>
</fieldset>
</form>
</td>
</tr>
</table>
<form action="">
<label id="context" name="context"></label>
</form>
</td>
<td width="50%" height="30%">
<b>Last Four Test Commands:</b><br/>
<div id="commandList"></div>
</td>
</tr>
<tr>
<td colspan="2" height="70%">
<iframe name="myiframe" id="myiframe" src="" height="100%" width="100%"></iframe>
</td>
</tr>
</table>
</body>
</html>

View file

@ -0,0 +1,74 @@
<html>
<head>
<title>Selenium Log Console</title>
<link id="cssLink" rel="stylesheet" href="selenium.css" />
</head>
<body id="logging-console">
<script language="JavaScript">
var logLevels = {
debug: 0,
info: 1,
warn: 2,
error: 3
};
function getThresholdLevel() {
var buttons = document.getElementById('logLevelChooser').level;
for (var i = 0; i < buttons.length; i++) {
if (buttons[i].checked) {
return buttons[i].value;
}
}
}
function setThresholdLevel(logLevel) {
var buttons = document.getElementById('logLevelChooser').level;
for (var i = 0; i < buttons.length; i++) {
if (buttons[i].value==logLevel) {
buttons[i].checked = true;
}
else {
buttons[i].checked = false;
}
}
}
function append(message, logLevel) {
var logLevelThreshold = getThresholdLevel();
if (logLevels[logLevel] < logLevels[logLevelThreshold]) {
return;
}
var log = document.getElementById('log');
var newEntry = document.createElement('li');
newEntry.className = logLevel;
newEntry.appendChild(document.createTextNode(message));
log.appendChild(newEntry);
if (newEntry.scrollIntoView) {
newEntry.scrollIntoView();
}
}
</script>
<div id="banner">
<form id="logLevelChooser">
<input id="level-error" type="radio" name="level"
value="error" /><label for="level-error">Error</label>
<input id="level-warn" type="radio" name="level"
value="warn" /><label for="level-warn">Warn</label>
<input id="level-info" type="radio" name="level"
value="info" /><label for="level-info">Info</label>
<input id="level-debug" type="radio" name="level" checked="yes"
value="debug" /><label for="level-debug">Debug</label>
</form>
<h1>Selenium Log Console</h1>
</div>
<ul id="log"></ul>
</body>
</html>

View file

@ -0,0 +1,123 @@
<html>
<!--
Copyright 2004 ThoughtWorks, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>Select a Test Suite</title>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserdetect.js"></script>
<script>
function load() {
if (browserVersion.isHTA) {
document.getElementById("save-div").style.display = "inline";
}
}
function autoCheck() {
var auto = document.getElementById("auto");
var autoDiv = document.getElementById("auto-div");
if (auto.checked) {
autoDiv.style.display = "inline";
} else {
autoDiv.style.display = "none";
}
}
function saveCheck() {
var results = document.getElementById("results");
var check = document.getElementById("save").checked;
if (check) {
results.firstChild.nodeValue = "Results file ";
document.getElementById("resultsUrl").value = "results.html";
} else {
results.firstChild.nodeValue = "Results URL ";
document.getElementById("resultsUrl").value = "../postResults";
}
}
function go() {
if (!browserVersion.isHTA) return true;
var inputs = document.getElementsByTagName("input");
var queryString = "";
for (var i = 0; i < inputs.length; i++) {
var elem = inputs[i];
var name = elem.name;
var value = elem.value;
if (elem.type == "checkbox") {
value = elem.checked;
}
queryString += escape(name) + "=" + escape(value);
if (i < (inputs.length - 1)) {
queryString += "&";
}
}
window.parent.selenium = null;
window.parent.htmlTestRunner.controlPanel.queryString = queryString;
window.parent.htmlTestRunner.loadSuiteFrame();
return false;
}
</script>
</head>
<body onload="load()" style="font-size: x-small">
<form id="prompt" target="_top" method="GET" onsubmit="return go();" action="TestRunner.html">
<p>
Test Suite:
<input id="test" name="test" size="30" value="../tests/TestSuite.html"/>
</p>
<p align="center"><input type="submit" value="Go"/></p>
<fieldset>
<legend>Options</legend>
<p>
<input id="multiWindow" type="checkbox" name="multiWindow" onclick="autoCheck();"/> <label
for="multiWindow">AUT in separate window</label>
<p>
<p>
<input id="auto" type="checkbox" name="auto" onclick="autoCheck();"/> <label for="auto">Run
automatically</label>
</p>
<div id="auto-div" style="display: none">
<p>
<input id="close" type="checkbox" name="close"/> <label for="close">Close afterwards </label>
</p>
<div id="save-div" style="display: none">
<br/><label for="save">Save to file </label><input id="save" type="checkbox" name="save"
onclick="saveCheck();"/>
</div>
<p id="results">
Results URL:
<input id="resultsUrl" name="resultsUrl" value="../postResults"/>
</p>
</div>
</fieldset>
</form>
</body>
</html>

View file

@ -0,0 +1,55 @@
<!--
Copyright 2005 ThoughtWorks, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<link rel="stylesheet" type="text/css" href="selenium.css" />
<body>
<table width="100%">
<tr>
<th>&uarr;</th>
<th>&uarr;</th>
<th>&uarr;</th>
</tr>
<tr>
<th width="25%">Test Suite</th>
<th width="50%">Current Test</th>
<th width="25%">Control Panel</th>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td></td>
<td class="selenium splash">
<img src="selenium-logo.png" align="right">
<h1>Selenium</h1>
<h2>by <a href="http://www.thoughtworks.com">ThoughtWorks</a> and friends</h2>
<p>
For more information on Selenium, visit
<pre>
<a href="http://selenium.openqa.org" target="_blank">http://selenium.openqa.org</a>
</pre>
</td>
<tr>
</table>
</body>
</html>

View file

@ -0,0 +1,175 @@
<html>
<head>
<HTA:APPLICATION ID="SeleniumHTARunner" APPLICATIONNAME="Selenium">
<!-- the previous line is only relevant if you rename this
file to "TestRunner.hta" -->
<!-- The copyright notice and other comments have been moved to after the HTA declaration,
to work-around a bug in IE on Win2K whereby the HTA application doesn't function correctly -->
<!--
Copyright 2004 ThoughtWorks, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"/>
<title>Selenium Functional Test Runner</title>
<link rel="stylesheet" type="text/css" href="selenium.css"/>
<script type="text/javascript" src="scripts/narcissus-defs.js"></script>
<script type="text/javascript" src="scripts/narcissus-parse.js"></script>
<script type="text/javascript" src="scripts/narcissus-exec.js"></script>
<script language="JavaScript" type="text/javascript" src="lib/prototype.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/htmlutils.js"></script>
<script language="JavaScript" type="text/javascript" src="lib/scriptaculous/scriptaculous.js"></script>
<script language="JavaScript" type="text/javascript" src="lib/cssQuery/cssQuery-p.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserdetect.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserbot.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/find_matching_child.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-api.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-commandhandlers.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-executionloop.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-testrunner.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-logging.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-version.js"></script>
<script language="JavaScript" type="text/javascript" src="xpath/misc.js"></script>
<script language="JavaScript" type="text/javascript" src="xpath/dom.js"></script>
<script language="JavaScript" type="text/javascript" src="xpath/xpath.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/user-extensions.js"></script>
<script language="JavaScript" type="text/javascript">
function openDomViewer() {
var autFrame = document.getElementById('myiframe');
var autFrameDocument = new SeleniumFrame(autFrame).getDocument();
this.rootDocument = autFrameDocument;
var domViewer = window.open(getDocumentBase(document) + 'domviewer/domviewer.html');
return false;
}
</script>
</head>
<body onLoad="onSeleniumLoad();">
<table class="layout">
<form action="" name="controlPanel">
<!-- Suite, Test, Control Panel -->
<tr class="selenium">
<td width="25%" height="30%">
<iframe name="testSuiteFrame" id="testSuiteFrame" src="./TestPrompt.html" application="yes"></iframe>
</td>
<td width="50%" height="30%">
<iframe name="testFrame" id="testFrame" application="yes"></iframe>
</td>
<td width="25%">
<table class="layout">
<tr class="selenium">
<th width="25%" height="1" class="header">
<h1><a href="http://selenium.thoughtworks.com" title="The Selenium Project">Selenium</a> TestRunner
</h1>
</th>
</tr>
<tr>
<td width="25%" height="30%" id="controlPanel">
<fieldset>
<legend>Execute Tests</legend>
<div id="imageButtonPanel">
<button type="button" id="runSuite" onClick="htmlTestRunner.startTestSuite();"
title="Run All tests">
</button>
<button type="button" id="runSeleniumTest" onClick="htmlTestRunner.runSingleTest();"
title="Run the Selected test">
</button>
<button type="button" id="pauseTest" disabled="disabled"
title="Pause/Continue" class="cssPauseTest">
</button>
<button type="button" id="stepTest" disabled="disabled"
title="Step">
</button>
</div>
<div style="float:left">Fast</div>
<div style="float:right">Slow</div>
<br/>
<div id="speedSlider">
<div id="speedTrack">&nbsp;</div>
<div id="speedHandle">&nbsp;</div>
</div>
<div class="executionOptions">
<input id="highlightOption" type="checkbox" name="highlightOption" value="0"/>
<label for="highlightOption">Highlight elements</label>
</div>
</fieldset>
<table id="stats" align="center">
<tr>
<td colspan="2" align="right">Elapsed:</td>
<td id="elapsedTime" colspan="2">00.00</td>
</tr>
<tr>
<th colspan="2">Tests</th>
<th colspan="2">Commands</th>
</tr>
<tr>
<td class="count" id="testRuns">0</td>
<td>run</td>
<td class="count" id="commandPasses">0</td>
<td>passed</td>
</tr>
<tr>
<td class="count" id="testFailures">0</td>
<td>failed</td>
<td class="count" id="commandFailures">0</td>
<td>failed</td>
</tr>
<tr>
<td colspan="2"></td>
<td class="count" id="commandErrors">0</td>
<td>incomplete</td>
</tr>
</table>
<fieldset>
<legend>Tools</legend>
<button type="button" id="domViewer1" onClick="openDomViewer();">
View DOM
</button>
<button type="button" onClick="LOG.show();">
Show Log
</button>
</fieldset>
</td>
</tr>
</table>
</td>
</tr>
<!-- AUT -->
<tr>
<td colspan="3" height="70%">
<iframe name="myiframe" id="myiframe" src="TestRunner-splash.html"></iframe>
</td>
</tr>
</form>
</table>
</body>
</html>

View file

@ -0,0 +1,175 @@
<html>
<head>
<HTA:APPLICATION ID="SeleniumHTARunner" APPLICATIONNAME="Selenium">
<!-- the previous line is only relevant if you rename this
file to "TestRunner.hta" -->
<!-- The copyright notice and other comments have been moved to after the HTA declaration,
to work-around a bug in IE on Win2K whereby the HTA application doesn't function correctly -->
<!--
Copyright 2004 ThoughtWorks, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"/>
<title>Selenium Functional Test Runner</title>
<link rel="stylesheet" type="text/css" href="selenium.css"/>
<script type="text/javascript" src="scripts/narcissus-defs.js"></script>
<script type="text/javascript" src="scripts/narcissus-parse.js"></script>
<script type="text/javascript" src="scripts/narcissus-exec.js"></script>
<script language="JavaScript" type="text/javascript" src="lib/prototype.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/htmlutils.js"></script>
<script language="JavaScript" type="text/javascript" src="lib/scriptaculous/scriptaculous.js"></script>
<script language="JavaScript" type="text/javascript" src="lib/cssQuery/cssQuery-p.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserdetect.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserbot.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/find_matching_child.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-api.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-commandhandlers.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-executionloop.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-testrunner.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-logging.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/selenium-version.js"></script>
<script language="JavaScript" type="text/javascript" src="xpath/misc.js"></script>
<script language="JavaScript" type="text/javascript" src="xpath/dom.js"></script>
<script language="JavaScript" type="text/javascript" src="xpath/xpath.js"></script>
<script language="JavaScript" type="text/javascript" src="scripts/user-extensions.js"></script>
<script language="JavaScript" type="text/javascript">
function openDomViewer() {
var autFrame = document.getElementById('myiframe');
var autFrameDocument = new SeleniumFrame(autFrame).getDocument();
this.rootDocument = autFrameDocument;
var domViewer = window.open(getDocumentBase(document) + 'domviewer/domviewer.html');
return false;
}
</script>
</head>
<body onLoad="onSeleniumLoad();">
<table class="layout">
<form action="" name="controlPanel">
<!-- Suite, Test, Control Panel -->
<tr class="selenium">
<td width="25%" height="30%">
<iframe name="testSuiteFrame" id="testSuiteFrame" src="./TestPrompt.html" application="yes"></iframe>
</td>
<td width="50%" height="30%">
<iframe name="testFrame" id="testFrame" application="yes"></iframe>
</td>
<td width="25%">
<table class="layout">
<tr class="selenium">
<th width="25%" height="1" class="header">
<h1><a href="http://selenium.thoughtworks.com" title="The Selenium Project">Selenium</a> TestRunner
</h1>
</th>
</tr>
<tr>
<td width="25%" height="30%" id="controlPanel">
<fieldset>
<legend>Execute Tests</legend>
<div id="imageButtonPanel">
<button type="button" id="runSuite" onClick="htmlTestRunner.startTestSuite();"
title="Run All tests">
</button>
<button type="button" id="runSeleniumTest" onClick="htmlTestRunner.runSingleTest();"
title="Run the Selected test">
</button>
<button type="button" id="pauseTest" disabled="disabled"
title="Pause/Continue" class="cssPauseTest">
</button>
<button type="button" id="stepTest" disabled="disabled"
title="Step">
</button>
</div>
<div style="float:left">Fast</div>
<div style="float:right">Slow</div>
<br/>
<div id="speedSlider">
<div id="speedTrack">&nbsp;</div>
<div id="speedHandle">&nbsp;</div>
</div>
<div class="executionOptions">
<input id="highlightOption" type="checkbox" name="highlightOption" value="0"/>
<label for="highlightOption">Highlight elements</label>
</div>
</fieldset>
<table id="stats" align="center">
<tr>
<td colspan="2" align="right">Elapsed:</td>
<td id="elapsedTime" colspan="2">00.00</td>
</tr>
<tr>
<th colspan="2">Tests</th>
<th colspan="2">Commands</th>
</tr>
<tr>
<td class="count" id="testRuns">0</td>
<td>run</td>
<td class="count" id="commandPasses">0</td>
<td>passed</td>
</tr>
<tr>
<td class="count" id="testFailures">0</td>
<td>failed</td>
<td class="count" id="commandFailures">0</td>
<td>failed</td>
</tr>
<tr>
<td colspan="2"></td>
<td class="count" id="commandErrors">0</td>
<td>incomplete</td>
</tr>
</table>
<fieldset>
<legend>Tools</legend>
<button type="button" id="domViewer1" onClick="openDomViewer();">
View DOM
</button>
<button type="button" onClick="LOG.show();">
Show Log
</button>
</fieldset>
</td>
</tr>
</table>
</td>
</tr>
<!-- AUT -->
<tr>
<td colspan="3" height="70%">
<iframe name="myiframe" id="myiframe" src="TestRunner-splash.html"></iframe>
</td>
</tr>
</form>
</table>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 843 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 848 B

View file

@ -0,0 +1,298 @@
/******************************************************************************
* Defines default styles for site pages. *
******************************************************************************/
.hidden {
display: none;
}
img{
display: inline;
border: none;
}
.box{
background: #fcfcfc;
border: 1px solid #000;
border-color: blue;
color: #000000;
margin: 10px auto;
padding: 3px;
vertical-align: bottom;
}
a {
text-decoration: none;
}
body {
background-color: #ffffff;
color: #000000;
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
}
h2 {
font-size: 140%;
}
h3 {
font-size: 120%;
}
h4 {
font-size: 100%;
}
pre {
font-family: Courier New, Courier, monospace;
font-size: 80%;
}
td, th {
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
text-align: left;
vertical-align: top;
}
th {
font-weight: bold;
vertical-align: bottom;
}
ul {
list-style-type: square;
}
#demoBox {
border-color: #000000;
border-style: solid;
border-width: 1px;
padding: 8px;
width: 24em;
}
.footer {
margin-bottom: 0px;
text-align: center;
}
/* Boxed table styles */
table.boxed {
border-spacing: 2px;
empty-cells: hide;
}
td.boxed, th.boxed, th.boxedHeader {
background-color: #ffffff;
border-color: #000000;
border-style: solid;
border-width: 1px;
color: #000000;
padding: 2px;
padding-left: 8px;
padding-right: 8px;
}
th.boxed {
background-color: #c0c0c0;
}
th.boxedHeader {
background-color: #808080;
color: #ffffff;
}
a.object {
color: #0000ff;
}
li {
white-space: nowrap;
}
ul {
list-style-type: square;
margin-left: 0px;
padding-left: 1em;
}
.boxlevel1{
background: #FFD700;
}
.boxlevel2{
background: #D2691E;
}
.boxlevel3{
background: #DCDCDC;
}
.boxlevel4{
background: #F5F5F5;
}
.boxlevel5{
background: #BEBEBE;
}
.boxlevel6{
background: #D3D3D3;
}
.boxlevel7{
background: #A9A9A9;
}
.boxlevel8{
background: #191970;
}
.boxlevel9{
background: #000080;
}
.boxlevel10{
background: #6495ED;
}
.boxlevel11{
background: #483D8B;
}
.boxlevel12{
background: #6A5ACD;
}
.boxlevel13{
background: #7B68EE;
}
.boxlevel14{
background: #8470FF;
}
.boxlevel15{
background: #0000CD;
}
.boxlevel16{
background: #4169E1;
}
.boxlevel17{
background: #0000FF;
}
.boxlevel18{
background: #1E90FF;
}
.boxlevel19{
background: #00BFFF;
}
.boxlevel20{
background: #87CEEB;
}
.boxlevel21{
background: #B0C4DE;
}
.boxlevel22{
background: #ADD8E6;
}
.boxlevel23{
background: #00CED1;
}
.boxlevel24{
background: #48D1CC;
}
.boxlevel25{
background: #40E0D0;
}
.boxlevel26{
background: #008B8B;
}
.boxlevel27{
background: #00FFFF;
}
.boxlevel28{
background: #E0FFFF;
}
.boxlevel29{
background: #5F9EA0;
}
.boxlevel30{
background: #66CDAA;
}
.boxlevel31{
background: #7FFFD4;
}
.boxlevel32{
background: #006400;
}
.boxlevel33{
background: #556B2F;
}
.boxlevel34{
background: #8FBC8F;
}
.boxlevel35{
background: #2E8B57;
}
.boxlevel36{
background: #3CB371;
}
.boxlevel37{
background: #20B2AA;
}
.boxlevel38{
background: #00FF7F;
}
.boxlevel39{
background: #7CFC00;
}
.boxlevel40{
background: #90EE90;
}
.boxlevel41{
background: #00FF00;
}
.boxlevel41{
background: #7FFF00;
}
.boxlevel42{
background: #00FA9A;
}
.boxlevel43{
background: #ADFF2F;
}
.boxlevel44{
background: #32CD32;
}

View file

@ -0,0 +1,16 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>DOM Viewer</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" type="text/css" href="domviewer.css"/>
<script type="text/javascript" src="selenium-domviewer.js"></script>
</head>
<body onload="loadDomViewer();">
<h3>DOM Viewer</h3>
<p> This page is generated using JavaScript. If you see this text, your
browser doesn't support JavaScript.</p>
</body>
</html>

View file

@ -0,0 +1,205 @@
var HIDDEN="hidden";
var LEVEL = "level";
var PLUS_SRC="butplus.gif";
var MIN_SRC="butmin.gif";
var newRoot;
var maxColumns=1;
function loadDomViewer() {
// See if the rootDocument variable has been set on this window.
var rootDocument = window.rootDocument;
// If not look to the opener for an explicity rootDocument variable, otherwise, use the opener document
if (!rootDocument && window.opener) {
rootDocument = window.opener.rootDocument || window.opener.document;
}
if (rootDocument) {
document.body.innerHTML = displayDOM(rootDocument);
}
else {
document.body.innerHTML = "<b>Must specify rootDocument for window. This can be done by setting the rootDocument variable on this window, or on the opener window for a popup window.</b>";
}
}
function displayDOM(root){
var str = "";
str+="<table>";
str += treeTraversal(root,0);
// to make table columns work well.
str += "<tr>";
for (var i=0; i < maxColumns; i++) {
str+= "<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>";
}
str += "</tr>";
str += "</table>";
return str;
}
function checkForChildren(element){
if(!element.hasChildNodes())
return false;
var nodes = element.childNodes;
var size = nodes.length;
var count=0;
for(var i=0; i< size; i++){
var node = nodes.item(i);
//if(node.toString()=="[object Text]"){
//this is equalent to the above
//but will work with more browsers
if(node.nodeType!=1){
count++;
}
}
if(count == size)
return false;
else
return true;
}
function treeTraversal(root, level){
var str = "";
var nodes= null;
var size = null;
//it is supposed to show the last node,
//but the last node is always nodeText type
//and we don't show it
if(!root.hasChildNodes())
return "";//displayNode(root,level,false);
nodes = root.childNodes;
size = nodes.length;
for(var i=0; i< size; i++){
var element = nodes.item(i);
//if the node is textNode, don't display
if(element.nodeType==1){
str+= displayNode(element,level,checkForChildren(element));
str+=treeTraversal(element, level+1);
}
}
return str;
}
function displayNode(element, level, isLink){
nodeContent = getNodeContent(element);
columns = Math.round((nodeContent.length / 12) + 0.5);
if (columns + level > maxColumns) {
maxColumns = columns + level;
}
var str ="<tr class='"+LEVEL+level+"'>";
for (var i=0; i < level; i++)
str+= "<td> </td>";
str+="<td colspan='"+ columns +"' class='box"+" boxlevel"+level+"' >";
if(isLink){
str+='<a onclick="hide(this);return false;" href="javascript:void();">';
str+='<img src="'+MIN_SRC+'" />';
}
str += nodeContent;
if(isLink)
str+="</a></td></tr>";
return str;
}
function getNodeContent(element) {
str = "";
id ="";
if (element.id != null && element.id != "") {
id = " ID(" + element.id +")";
}
name ="";
if (element.name != null && element.name != "") {
name = " NAME(" + element.name + ")";
}
value ="";
if (element.value != null && element.value != "") {
value = " VALUE(" + element.value + ")";
}
href ="";
if (element.href != null && element.href != "") {
href = " HREF(" + element.href + ")";
}
clazz = "";
if (element.className != null && element.className != "") {
clazz = " CLASS(" + element.className + ")";
}
src = "";
if (element.src != null && element.src != "") {
src = " SRC(" + element.src + ")";
}
alt = "";
if (element.alt != null && element.alt != "") {
alt = " ALT(" + element.alt + ")";
}
type = "";
if (element.type != null && element.type != "") {
type = " TYPE(" + element.type + ")";
}
text ="";
if (element.text != null && element.text != "" && element.text != "undefined") {
text = " #TEXT(" + trim(element.text) +")";
}
str+=" <b>"+ element.nodeName + id + alt + type + clazz + name + value + href + src + text + "</b>";
return str;
}
function trim(val) {
val2 = val.substring(0,40) + " ";
var spaceChr = String.fromCharCode(32);
var length = val2.length;
var retVal = "";
var ix = length -1;
while(ix > -1){
if(val2.charAt(ix) == spaceChr) {
} else {
retVal = val2.substring(0, ix +1);
break;
}
ix = ix-1;
}
if (val.length > 40) {
retVal += "...";
}
return retVal;
}
function hide(hlink){
var isHidden = false;
var image = hlink.firstChild;
if(image.src.toString().indexOf(MIN_SRC)!=-1){
image.src=PLUS_SRC;
isHidden=true;
}else{
image.src=MIN_SRC;
}
var rowObj= hlink.parentNode.parentNode;
var rowLevel = parseInt(rowObj.className.substring(LEVEL.length));
var sibling = rowObj.nextSibling;
var siblingLevel = sibling.className.substring(LEVEL.length);
if(siblingLevel.indexOf(HIDDEN)!=-1){
siblingLevel = siblingLevel.substring(0,siblingLevel.length - HIDDEN.length-1);
}
siblingLevel=parseInt(siblingLevel);
while(sibling!=null && rowLevel<siblingLevel){
if(isHidden){
sibling.className += " "+ HIDDEN;
}else if(!isHidden && sibling.className.indexOf(HIDDEN)!=-1){
var str = sibling.className;
sibling.className=str.substring(0, str.length - HIDDEN.length-1);
}
sibling = sibling.nextSibling;
siblingLevel = parseInt(sibling.className.substring(LEVEL.length));
}
}
function LOG(message) {
window.opener.LOG.warn(message);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 405 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 275 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 668 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 B

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,142 @@
/*
cssQuery, version 2.0.2 (2005-08-19)
Copyright: 2004-2005, Dean Edwards (http://dean.edwards.name/)
License: http://creativecommons.org/licenses/LGPL/2.1/
*/
cssQuery.addModule("css-level2", function() {
// -----------------------------------------------------------------------
// selectors
// -----------------------------------------------------------------------
// child selector
selectors[">"] = function($results, $from, $tagName, $namespace) {
var $element, i, j;
for (i = 0; i < $from.length; i++) {
var $subset = childElements($from[i]);
for (j = 0; ($element = $subset[j]); j++)
if (compareTagName($element, $tagName, $namespace))
$results.push($element);
}
};
// sibling selector
selectors["+"] = function($results, $from, $tagName, $namespace) {
for (var i = 0; i < $from.length; i++) {
var $element = nextElementSibling($from[i]);
if ($element && compareTagName($element, $tagName, $namespace))
$results.push($element);
}
};
// attribute selector
selectors["@"] = function($results, $from, $attributeSelectorID) {
var $test = attributeSelectors[$attributeSelectorID].test;
var $element, i;
for (i = 0; ($element = $from[i]); i++)
if ($test($element)) $results.push($element);
};
// -----------------------------------------------------------------------
// pseudo-classes
// -----------------------------------------------------------------------
pseudoClasses["first-child"] = function($element) {
return !previousElementSibling($element);
};
pseudoClasses["lang"] = function($element, $code) {
$code = new RegExp("^" + $code, "i");
while ($element && !$element.getAttribute("lang")) $element = $element.parentNode;
return $element && $code.test($element.getAttribute("lang"));
};
// -----------------------------------------------------------------------
// attribute selectors
// -----------------------------------------------------------------------
// constants
AttributeSelector.NS_IE = /\\:/g;
AttributeSelector.PREFIX = "@";
// properties
AttributeSelector.tests = {};
// methods
AttributeSelector.replace = function($match, $attribute, $namespace, $compare, $value) {
var $key = this.PREFIX + $match;
if (!attributeSelectors[$key]) {
$attribute = this.create($attribute, $compare || "", $value || "");
// store the selector
attributeSelectors[$key] = $attribute;
attributeSelectors.push($attribute);
}
return attributeSelectors[$key].id;
};
AttributeSelector.parse = function($selector) {
$selector = $selector.replace(this.NS_IE, "|");
var $match;
while ($match = $selector.match(this.match)) {
var $replace = this.replace($match[0], $match[1], $match[2], $match[3], $match[4]);
$selector = $selector.replace(this.match, $replace);
}
return $selector;
};
AttributeSelector.create = function($propertyName, $test, $value) {
var $attributeSelector = {};
$attributeSelector.id = this.PREFIX + attributeSelectors.length;
$attributeSelector.name = $propertyName;
$test = this.tests[$test];
$test = $test ? $test(this.getAttribute($propertyName), getText($value)) : false;
$attributeSelector.test = new Function("e", "return " + $test);
return $attributeSelector;
};
AttributeSelector.getAttribute = function($name) {
switch ($name.toLowerCase()) {
case "id":
return "e.id";
case "class":
return "e.className";
case "for":
return "e.htmlFor";
case "href":
if (isMSIE) {
// IE always returns the full path not the fragment in the href attribute
// so we RegExp it out of outerHTML. Opera does the same thing but there
// is no way to get the original attribute.
return "String((e.outerHTML.match(/href=\\x22?([^\\s\\x22]*)\\x22?/)||[])[1]||'')";
}
}
return "e.getAttribute('" + $name.replace($NAMESPACE, ":") + "')";
};
// -----------------------------------------------------------------------
// attribute selector tests
// -----------------------------------------------------------------------
AttributeSelector.tests[""] = function($attribute) {
return $attribute;
};
AttributeSelector.tests["="] = function($attribute, $value) {
return $attribute + "==" + Quote.add($value);
};
AttributeSelector.tests["~="] = function($attribute, $value) {
return "/(^| )" + regEscape($value) + "( |$)/.test(" + $attribute + ")";
};
AttributeSelector.tests["|="] = function($attribute, $value) {
return "/^" + regEscape($value) + "(-|$)/.test(" + $attribute + ")";
};
// -----------------------------------------------------------------------
// parsing
// -----------------------------------------------------------------------
// override parseSelector to parse out attribute selectors
var _parseSelector = parseSelector;
parseSelector = function($selector) {
return _parseSelector(AttributeSelector.parse($selector));
};
}); // addModule

View file

@ -0,0 +1,150 @@
/*
cssQuery, version 2.0.2 (2005-08-19)
Copyright: 2004-2005, Dean Edwards (http://dean.edwards.name/)
License: http://creativecommons.org/licenses/LGPL/2.1/
*/
/* Thanks to Bill Edney */
cssQuery.addModule("css-level3", function() {
// -----------------------------------------------------------------------
// selectors
// -----------------------------------------------------------------------
// indirect sibling selector
selectors["~"] = function($results, $from, $tagName, $namespace) {
var $element, i;
for (i = 0; ($element = $from[i]); i++) {
while ($element = nextElementSibling($element)) {
if (compareTagName($element, $tagName, $namespace))
$results.push($element);
}
}
};
// -----------------------------------------------------------------------
// pseudo-classes
// -----------------------------------------------------------------------
// I'm hoping these pseudo-classes are pretty readable. Let me know if
// any need explanation.
pseudoClasses["contains"] = function($element, $text) {
$text = new RegExp(regEscape(getText($text)));
return $text.test(getTextContent($element));
};
pseudoClasses["root"] = function($element) {
return $element == getDocument($element).documentElement;
};
pseudoClasses["empty"] = function($element) {
var $node, i;
for (i = 0; ($node = $element.childNodes[i]); i++) {
if (thisElement($node) || $node.nodeType == 3) return false;
}
return true;
};
pseudoClasses["last-child"] = function($element) {
return !nextElementSibling($element);
};
pseudoClasses["only-child"] = function($element) {
$element = $element.parentNode;
return firstElementChild($element) == lastElementChild($element);
};
pseudoClasses["not"] = function($element, $selector) {
var $negated = cssQuery($selector, getDocument($element));
for (var i = 0; i < $negated.length; i++) {
if ($negated[i] == $element) return false;
}
return true;
};
pseudoClasses["nth-child"] = function($element, $arguments) {
return nthChild($element, $arguments, previousElementSibling);
};
pseudoClasses["nth-last-child"] = function($element, $arguments) {
return nthChild($element, $arguments, nextElementSibling);
};
pseudoClasses["target"] = function($element) {
return $element.id == location.hash.slice(1);
};
// UI element states
pseudoClasses["checked"] = function($element) {
return $element.checked;
};
pseudoClasses["enabled"] = function($element) {
return $element.disabled === false;
};
pseudoClasses["disabled"] = function($element) {
return $element.disabled;
};
pseudoClasses["indeterminate"] = function($element) {
return $element.indeterminate;
};
// -----------------------------------------------------------------------
// attribute selector tests
// -----------------------------------------------------------------------
AttributeSelector.tests["^="] = function($attribute, $value) {
return "/^" + regEscape($value) + "/.test(" + $attribute + ")";
};
AttributeSelector.tests["$="] = function($attribute, $value) {
return "/" + regEscape($value) + "$/.test(" + $attribute + ")";
};
AttributeSelector.tests["*="] = function($attribute, $value) {
return "/" + regEscape($value) + "/.test(" + $attribute + ")";
};
// -----------------------------------------------------------------------
// nth child support (Bill Edney)
// -----------------------------------------------------------------------
function nthChild($element, $arguments, $traverse) {
switch ($arguments) {
case "n": return true;
case "even": $arguments = "2n"; break;
case "odd": $arguments = "2n+1";
}
var $$children = childElements($element.parentNode);
function _checkIndex($index) {
var $index = ($traverse == nextElementSibling) ? $$children.length - $index : $index - 1;
return $$children[$index] == $element;
};
// it was just a number (no "n")
if (!isNaN($arguments)) return _checkIndex($arguments);
$arguments = $arguments.split("n");
var $multiplier = parseInt($arguments[0]);
var $step = parseInt($arguments[1]);
if ((isNaN($multiplier) || $multiplier == 1) && $step == 0) return true;
if ($multiplier == 0 && !isNaN($step)) return _checkIndex($step);
if (isNaN($step)) $step = 0;
var $count = 1;
while ($element = $traverse($element)) $count++;
if (isNaN($multiplier) || $multiplier == 1)
return ($traverse == nextElementSibling) ? ($count <= $step) : ($step >= $count);
return ($count % $multiplier) == $step;
};
}); // addModule

View file

@ -0,0 +1,53 @@
/*
cssQuery, version 2.0.2 (2005-08-19)
Copyright: 2004-2005, Dean Edwards (http://dean.edwards.name/)
License: http://creativecommons.org/licenses/LGPL/2.1/
*/
cssQuery.addModule("css-standard", function() { // override IE optimisation
// cssQuery was originally written as the CSS engine for IE7. It is
// optimised (in terms of size not speed) for IE so this module is
// provided separately to provide cross-browser support.
// -----------------------------------------------------------------------
// browser compatibility
// -----------------------------------------------------------------------
// sniff for Win32 Explorer
isMSIE = eval("false;/*@cc_on@if(@\x5fwin32)isMSIE=true@end@*/");
if (!isMSIE) {
getElementsByTagName = function($element, $tagName, $namespace) {
return $namespace ? $element.getElementsByTagNameNS("*", $tagName) :
$element.getElementsByTagName($tagName);
};
compareNamespace = function($element, $namespace) {
return !$namespace || ($namespace == "*") || ($element.prefix == $namespace);
};
isXML = document.contentType ? function($element) {
return /xml/i.test(getDocument($element).contentType);
} : function($element) {
return getDocument($element).documentElement.tagName != "HTML";
};
getTextContent = function($element) {
// mozilla || opera || other
return $element.textContent || $element.innerText || _getTextContent($element);
};
function _getTextContent($element) {
var $textContent = "", $node, i;
for (i = 0; ($node = $element.childNodes[i]); i++) {
switch ($node.nodeType) {
case 11: // document fragment
case 1: $textContent += _getTextContent($node); break;
case 3: $textContent += $node.nodeValue; break;
}
}
return $textContent;
};
}
}); // addModule

View file

@ -0,0 +1,356 @@
/*
cssQuery, version 2.0.2 (2005-08-19)
Copyright: 2004-2005, Dean Edwards (http://dean.edwards.name/)
License: http://creativecommons.org/licenses/LGPL/2.1/
*/
// the following functions allow querying of the DOM using CSS selectors
var cssQuery = function() {
var version = "2.0.2";
// -----------------------------------------------------------------------
// main query function
// -----------------------------------------------------------------------
var $COMMA = /\s*,\s*/;
var cssQuery = function($selector, $$from) {
try {
var $match = [];
var $useCache = arguments.callee.caching && !$$from;
var $base = ($$from) ? ($$from.constructor == Array) ? $$from : [$$from] : [document];
// process comma separated selectors
var $$selectors = parseSelector($selector).split($COMMA), i;
for (i = 0; i < $$selectors.length; i++) {
// convert the selector to a stream
$selector = _toStream($$selectors[i]);
// faster chop if it starts with id (MSIE only)
if (isMSIE && $selector.slice(0, 3).join("") == " *#") {
$selector = $selector.slice(2);
$$from = _msie_selectById([], $base, $selector[1]);
} else $$from = $base;
// process the stream
var j = 0, $token, $filter, $arguments, $cacheSelector = "";
while (j < $selector.length) {
$token = $selector[j++];
$filter = $selector[j++];
$cacheSelector += $token + $filter;
// some pseudo-classes allow arguments to be passed
// e.g. nth-child(even)
$arguments = "";
if ($selector[j] == "(") {
while ($selector[j++] != ")" && j < $selector.length) {
$arguments += $selector[j];
}
$arguments = $arguments.slice(0, -1);
$cacheSelector += "(" + $arguments + ")";
}
// process a token/filter pair use cached results if possible
$$from = ($useCache && cache[$cacheSelector]) ?
cache[$cacheSelector] : select($$from, $token, $filter, $arguments);
if ($useCache) cache[$cacheSelector] = $$from;
}
$match = $match.concat($$from);
}
delete cssQuery.error;
return $match;
} catch ($error) {
cssQuery.error = $error;
return [];
}};
// -----------------------------------------------------------------------
// public interface
// -----------------------------------------------------------------------
cssQuery.toString = function() {
return "function cssQuery() {\n [version " + version + "]\n}";
};
// caching
var cache = {};
cssQuery.caching = false;
cssQuery.clearCache = function($selector) {
if ($selector) {
$selector = _toStream($selector).join("");
delete cache[$selector];
} else cache = {};
};
// allow extensions
var modules = {};
var loaded = false;
cssQuery.addModule = function($name, $script) {
if (loaded) eval("$script=" + String($script));
modules[$name] = new $script();;
};
// hackery
cssQuery.valueOf = function($code) {
return $code ? eval($code) : this;
};
// -----------------------------------------------------------------------
// declarations
// -----------------------------------------------------------------------
var selectors = {};
var pseudoClasses = {};
// a safari bug means that these have to be declared here
var AttributeSelector = {match: /\[([\w-]+(\|[\w-]+)?)\s*(\W?=)?\s*([^\]]*)\]/};
var attributeSelectors = [];
// -----------------------------------------------------------------------
// selectors
// -----------------------------------------------------------------------
// descendant selector
selectors[" "] = function($results, $from, $tagName, $namespace) {
// loop through current selection
var $element, i, j;
for (i = 0; i < $from.length; i++) {
// get descendants
var $subset = getElementsByTagName($from[i], $tagName, $namespace);
// loop through descendants and add to results selection
for (j = 0; ($element = $subset[j]); j++) {
if (thisElement($element) && compareNamespace($element, $namespace))
$results.push($element);
}
}
};
// ID selector
selectors["#"] = function($results, $from, $id) {
// loop through current selection and check ID
var $element, j;
for (j = 0; ($element = $from[j]); j++) if ($element.id == $id) $results.push($element);
};
// class selector
selectors["."] = function($results, $from, $className) {
// create a RegExp version of the class
$className = new RegExp("(^|\\s)" + $className + "(\\s|$)");
// loop through current selection and check class
var $element, i;
for (i = 0; ($element = $from[i]); i++)
if ($className.test($element.className)) $results.push($element);
};
// pseudo-class selector
selectors[":"] = function($results, $from, $pseudoClass, $arguments) {
// retrieve the cssQuery pseudo-class function
var $test = pseudoClasses[$pseudoClass], $element, i;
// loop through current selection and apply pseudo-class filter
if ($test) for (i = 0; ($element = $from[i]); i++)
// if the cssQuery pseudo-class function returns "true" add the element
if ($test($element, $arguments)) $results.push($element);
};
// -----------------------------------------------------------------------
// pseudo-classes
// -----------------------------------------------------------------------
pseudoClasses["link"] = function($element) {
var $document = getDocument($element);
if ($document.links) for (var i = 0; i < $document.links.length; i++) {
if ($document.links[i] == $element) return true;
}
};
pseudoClasses["visited"] = function($element) {
// can't do this without jiggery-pokery
};
// -----------------------------------------------------------------------
// DOM traversal
// -----------------------------------------------------------------------
// IE5/6 includes comments (LOL) in it's elements collections.
// so we have to check for this. the test is tagName != "!". LOL (again).
var thisElement = function($element) {
return ($element && $element.nodeType == 1 && $element.tagName != "!") ? $element : null;
};
// return the previous element to the supplied element
// previousSibling is not good enough as it might return a text or comment node
var previousElementSibling = function($element) {
while ($element && ($element = $element.previousSibling) && !thisElement($element)) continue;
return $element;
};
// return the next element to the supplied element
var nextElementSibling = function($element) {
while ($element && ($element = $element.nextSibling) && !thisElement($element)) continue;
return $element;
};
// return the first child ELEMENT of an element
// NOT the first child node (though they may be the same thing)
var firstElementChild = function($element) {
return thisElement($element.firstChild) || nextElementSibling($element.firstChild);
};
var lastElementChild = function($element) {
return thisElement($element.lastChild) || previousElementSibling($element.lastChild);
};
// return child elements of an element (not child nodes)
var childElements = function($element) {
var $childElements = [];
$element = firstElementChild($element);
while ($element) {
$childElements.push($element);
$element = nextElementSibling($element);
}
return $childElements;
};
// -----------------------------------------------------------------------
// browser compatibility
// -----------------------------------------------------------------------
// all of the functions in this section can be overwritten. the default
// configuration is for IE. The functions below reflect this. standard
// methods are included in a separate module. It would probably be better
// the other way round of course but this makes it easier to keep IE7 trim.
var isMSIE = true;
var isXML = function($element) {
var $document = getDocument($element);
return (typeof $document.mimeType == "unknown") ?
/\.xml$/i.test($document.URL) :
Boolean($document.mimeType == "XML Document");
};
// return the element's containing document
var getDocument = function($element) {
return $element.ownerDocument || $element.document;
};
var getElementsByTagName = function($element, $tagName) {
return ($tagName == "*" && $element.all) ? $element.all : $element.getElementsByTagName($tagName);
};
var compareTagName = function($element, $tagName, $namespace) {
if ($tagName == "*") return thisElement($element);
if (!compareNamespace($element, $namespace)) return false;
if (!isXML($element)) $tagName = $tagName.toUpperCase();
return $element.tagName == $tagName;
};
var compareNamespace = function($element, $namespace) {
return !$namespace || ($namespace == "*") || ($element.scopeName == $namespace);
};
var getTextContent = function($element) {
return $element.innerText;
};
function _msie_selectById($results, $from, id) {
var $match, i, j;
for (i = 0; i < $from.length; i++) {
if ($match = $from[i].all.item(id)) {
if ($match.id == id) $results.push($match);
else if ($match.length != null) {
for (j = 0; j < $match.length; j++) {
if ($match[j].id == id) $results.push($match[j]);
}
}
}
}
return $results;
};
// for IE5.0
if (![].push) Array.prototype.push = function() {
for (var i = 0; i < arguments.length; i++) {
this[this.length] = arguments[i];
}
return this.length;
};
// -----------------------------------------------------------------------
// query support
// -----------------------------------------------------------------------
// select a set of matching elements.
// "from" is an array of elements.
// "token" is a character representing the type of filter
// e.g. ">" means child selector
// "filter" represents the tag name, id or class name that is being selected
// the function returns an array of matching elements
var $NAMESPACE = /\|/;
function select($$from, $token, $filter, $arguments) {
if ($NAMESPACE.test($filter)) {
$filter = $filter.split($NAMESPACE);
$arguments = $filter[0];
$filter = $filter[1];
}
var $results = [];
if (selectors[$token]) {
selectors[$token]($results, $$from, $filter, $arguments);
}
return $results;
};
// -----------------------------------------------------------------------
// parsing
// -----------------------------------------------------------------------
// convert css selectors to a stream of tokens and filters
// it's not a real stream. it's just an array of strings.
var $STANDARD_SELECT = /^[^\s>+~]/;
var $$STREAM = /[\s#.:>+~()@]|[^\s#.:>+~()@]+/g;
function _toStream($selector) {
if ($STANDARD_SELECT.test($selector)) $selector = " " + $selector;
return $selector.match($$STREAM) || [];
};
var $WHITESPACE = /\s*([\s>+~(),]|^|$)\s*/g;
var $IMPLIED_ALL = /([\s>+~,]|[^(]\+|^)([#.:@])/g;
var parseSelector = function($selector) {
return $selector
// trim whitespace
.replace($WHITESPACE, "$1")
// e.g. ".class1" --> "*.class1"
.replace($IMPLIED_ALL, "$1*$2");
};
var Quote = {
toString: function() {return "'"},
match: /^('[^']*')|("[^"]*")$/,
test: function($string) {
return this.match.test($string);
},
add: function($string) {
return this.test($string) ? $string : this + $string + this;
},
remove: function($string) {
return this.test($string) ? $string.slice(1, -1) : $string;
}
};
var getText = function($text) {
return Quote.remove($text);
};
var $ESCAPE = /([\/()[\]?{}|*+-])/g;
function regEscape($string) {
return $string.replace($ESCAPE, "\\$1");
};
// -----------------------------------------------------------------------
// modules
// -----------------------------------------------------------------------
// -------- >> insert modules here for packaging << -------- \\
loaded = true;
// -----------------------------------------------------------------------
// return the query function
// -----------------------------------------------------------------------
return cssQuery;
}(); // cssQuery

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,101 @@
// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
//
// See scriptaculous.js for full license.
var Builder = {
NODEMAP: {
AREA: 'map',
CAPTION: 'table',
COL: 'table',
COLGROUP: 'table',
LEGEND: 'fieldset',
OPTGROUP: 'select',
OPTION: 'select',
PARAM: 'object',
TBODY: 'table',
TD: 'table',
TFOOT: 'table',
TH: 'table',
THEAD: 'table',
TR: 'table'
},
// note: For Firefox < 1.5, OPTION and OPTGROUP tags are currently broken,
// due to a Firefox bug
node: function(elementName) {
elementName = elementName.toUpperCase();
// try innerHTML approach
var parentTag = this.NODEMAP[elementName] || 'div';
var parentElement = document.createElement(parentTag);
try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
parentElement.innerHTML = "<" + elementName + "></" + elementName + ">";
} catch(e) {}
var element = parentElement.firstChild || null;
// see if browser added wrapping tags
if(element && (element.tagName != elementName))
element = element.getElementsByTagName(elementName)[0];
// fallback to createElement approach
if(!element) element = document.createElement(elementName);
// abort if nothing could be created
if(!element) return;
// attributes (or text)
if(arguments[1])
if(this._isStringOrNumber(arguments[1]) ||
(arguments[1] instanceof Array)) {
this._children(element, arguments[1]);
} else {
var attrs = this._attributes(arguments[1]);
if(attrs.length) {
try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
parentElement.innerHTML = "<" +elementName + " " +
attrs + "></" + elementName + ">";
} catch(e) {}
element = parentElement.firstChild || null;
// workaround firefox 1.0.X bug
if(!element) {
element = document.createElement(elementName);
for(attr in arguments[1])
element[attr == 'class' ? 'className' : attr] = arguments[1][attr];
}
if(element.tagName != elementName)
element = parentElement.getElementsByTagName(elementName)[0];
}
}
// text, or array of children
if(arguments[2])
this._children(element, arguments[2]);
return element;
},
_text: function(text) {
return document.createTextNode(text);
},
_attributes: function(attributes) {
var attrs = [];
for(attribute in attributes)
attrs.push((attribute=='className' ? 'class' : attribute) +
'="' + attributes[attribute].toString().escapeHTML() + '"');
return attrs.join(" ");
},
_children: function(element, children) {
if(typeof children=='object') { // array can hold nodes and text
children.flatten().each( function(e) {
if(typeof e=='object')
element.appendChild(e)
else
if(Builder._isStringOrNumber(e))
element.appendChild(Builder._text(e));
});
} else
if(Builder._isStringOrNumber(children))
element.appendChild(Builder._text(children));
},
_isStringOrNumber: function(param) {
return(typeof param=='string' || typeof param=='number');
}
}

View file

@ -0,0 +1,815 @@
// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
// (c) 2005 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
// (c) 2005 Jon Tirsen (http://www.tirsen.com)
// Contributors:
// Richard Livsey
// Rahul Bhargava
// Rob Wills
//
// See scriptaculous.js for full license.
// Autocompleter.Base handles all the autocompletion functionality
// that's independent of the data source for autocompletion. This
// includes drawing the autocompletion menu, observing keyboard
// and mouse events, and similar.
//
// Specific autocompleters need to provide, at the very least,
// a getUpdatedChoices function that will be invoked every time
// the text inside the monitored textbox changes. This method
// should get the text for which to provide autocompletion by
// invoking this.getToken(), NOT by directly accessing
// this.element.value. This is to allow incremental tokenized
// autocompletion. Specific auto-completion logic (AJAX, etc)
// belongs in getUpdatedChoices.
//
// Tokenized incremental autocompletion is enabled automatically
// when an autocompleter is instantiated with the 'tokens' option
// in the options parameter, e.g.:
// new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' });
// will incrementally autocomplete with a comma as the token.
// Additionally, ',' in the above example can be replaced with
// a token array, e.g. { tokens: [',', '\n'] } which
// enables autocompletion on multiple tokens. This is most
// useful when one of the tokens is \n (a newline), as it
// allows smart autocompletion after linebreaks.
var Autocompleter = {}
Autocompleter.Base = function() {};
Autocompleter.Base.prototype = {
baseInitialize: function(element, update, options) {
this.element = $(element);
this.update = $(update);
this.hasFocus = false;
this.changed = false;
this.active = false;
this.index = 0;
this.entryCount = 0;
if (this.setOptions)
this.setOptions(options);
else
this.options = options || {};
this.options.paramName = this.options.paramName || this.element.name;
this.options.tokens = this.options.tokens || [];
this.options.frequency = this.options.frequency || 0.4;
this.options.minChars = this.options.minChars || 1;
this.options.onShow = this.options.onShow ||
function(element, update){
if(!update.style.position || update.style.position=='absolute') {
update.style.position = 'absolute';
Position.clone(element, update, {setHeight: false, offsetTop: element.offsetHeight});
}
Effect.Appear(update,{duration:0.15});
};
this.options.onHide = this.options.onHide ||
function(element, update){ new Effect.Fade(update,{duration:0.15}) };
if (typeof(this.options.tokens) == 'string')
this.options.tokens = new Array(this.options.tokens);
this.observer = null;
this.element.setAttribute('autocomplete','off');
Element.hide(this.update);
Event.observe(this.element, "blur", this.onBlur.bindAsEventListener(this));
Event.observe(this.element, "keypress", this.onKeyPress.bindAsEventListener(this));
},
show: function() {
if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
if(!this.iefix &&
(navigator.appVersion.indexOf('MSIE')>0) &&
(navigator.userAgent.indexOf('Opera')<0) &&
(Element.getStyle(this.update, 'position')=='absolute')) {
new Insertion.After(this.update,
'<iframe id="' + this.update.id + '_iefix" '+
'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
this.iefix = $(this.update.id+'_iefix');
}
if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50);
},
fixIEOverlapping: function() {
Position.clone(this.update, this.iefix);
this.iefix.style.zIndex = 1;
this.update.style.zIndex = 2;
Element.show(this.iefix);
},
hide: function() {
this.stopIndicator();
if(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update);
if(this.iefix) Element.hide(this.iefix);
},
startIndicator: function() {
if(this.options.indicator) Element.show(this.options.indicator);
},
stopIndicator: function() {
if(this.options.indicator) Element.hide(this.options.indicator);
},
onKeyPress: function(event) {
if(this.active)
switch(event.keyCode) {
case Event.KEY_TAB:
case Event.KEY_RETURN:
this.selectEntry();
Event.stop(event);
case Event.KEY_ESC:
this.hide();
this.active = false;
Event.stop(event);
return;
case Event.KEY_LEFT:
case Event.KEY_RIGHT:
return;
case Event.KEY_UP:
this.markPrevious();
this.render();
if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event);
return;
case Event.KEY_DOWN:
this.markNext();
this.render();
if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event);
return;
}
else
if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
(navigator.appVersion.indexOf('AppleWebKit') > 0 && event.keyCode == 0)) return;
this.changed = true;
this.hasFocus = true;
if(this.observer) clearTimeout(this.observer);
this.observer =
setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
},
activate: function() {
this.changed = false;
this.hasFocus = true;
this.getUpdatedChoices();
},
onHover: function(event) {
var element = Event.findElement(event, 'LI');
if(this.index != element.autocompleteIndex)
{
this.index = element.autocompleteIndex;
this.render();
}
Event.stop(event);
},
onClick: function(event) {
var element = Event.findElement(event, 'LI');
this.index = element.autocompleteIndex;
this.selectEntry();
this.hide();
},
onBlur: function(event) {
// needed to make click events working
setTimeout(this.hide.bind(this), 250);
this.hasFocus = false;
this.active = false;
},
render: function() {
if(this.entryCount > 0) {
for (var i = 0; i < this.entryCount; i++)
this.index==i ?
Element.addClassName(this.getEntry(i),"selected") :
Element.removeClassName(this.getEntry(i),"selected");
if(this.hasFocus) {
this.show();
this.active = true;
}
} else {
this.active = false;
this.hide();
}
},
markPrevious: function() {
if(this.index > 0) this.index--
else this.index = this.entryCount-1;
},
markNext: function() {
if(this.index < this.entryCount-1) this.index++
else this.index = 0;
},
getEntry: function(index) {
return this.update.firstChild.childNodes[index];
},
getCurrentEntry: function() {
return this.getEntry(this.index);
},
selectEntry: function() {
this.active = false;
this.updateElement(this.getCurrentEntry());
},
updateElement: function(selectedElement) {
if (this.options.updateElement) {
this.options.updateElement(selectedElement);
return;
}
var value = '';
if (this.options.select) {
var nodes = document.getElementsByClassName(this.options.select, selectedElement) || [];
if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
} else
value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
var lastTokenPos = this.findLastToken();
if (lastTokenPos != -1) {
var newValue = this.element.value.substr(0, lastTokenPos + 1);
var whitespace = this.element.value.substr(lastTokenPos + 1).match(/^\s+/);
if (whitespace)
newValue += whitespace[0];
this.element.value = newValue + value;
} else {
this.element.value = value;
}
this.element.focus();
if (this.options.afterUpdateElement)
this.options.afterUpdateElement(this.element, selectedElement);
},
updateChoices: function(choices) {
if(!this.changed && this.hasFocus) {
this.update.innerHTML = choices;
Element.cleanWhitespace(this.update);
Element.cleanWhitespace(this.update.firstChild);
if(this.update.firstChild && this.update.firstChild.childNodes) {
this.entryCount =
this.update.firstChild.childNodes.length;
for (var i = 0; i < this.entryCount; i++) {
var entry = this.getEntry(i);
entry.autocompleteIndex = i;
this.addObservers(entry);
}
} else {
this.entryCount = 0;
}
this.stopIndicator();
this.index = 0;
this.render();
}
},
addObservers: function(element) {
Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this));
Event.observe(element, "click", this.onClick.bindAsEventListener(this));
},
onObserverEvent: function() {
this.changed = false;
if(this.getToken().length>=this.options.minChars) {
this.startIndicator();
this.getUpdatedChoices();
} else {
this.active = false;
this.hide();
}
},
getToken: function() {
var tokenPos = this.findLastToken();
if (tokenPos != -1)
var ret = this.element.value.substr(tokenPos + 1).replace(/^\s+/,'').replace(/\s+$/,'');
else
var ret = this.element.value;
return /\n/.test(ret) ? '' : ret;
},
findLastToken: function() {
var lastTokenPos = -1;
for (var i=0; i<this.options.tokens.length; i++) {
var thisTokenPos = this.element.value.lastIndexOf(this.options.tokens[i]);
if (thisTokenPos > lastTokenPos)
lastTokenPos = thisTokenPos;
}
return lastTokenPos;
}
}
Ajax.Autocompleter = Class.create();
Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.prototype), {
initialize: function(element, update, url, options) {
this.baseInitialize(element, update, options);
this.options.asynchronous = true;
this.options.onComplete = this.onComplete.bind(this);
this.options.defaultParams = this.options.parameters || null;
this.url = url;
},
getUpdatedChoices: function() {
entry = encodeURIComponent(this.options.paramName) + '=' +
encodeURIComponent(this.getToken());
this.options.parameters = this.options.callback ?
this.options.callback(this.element, entry) : entry;
if(this.options.defaultParams)
this.options.parameters += '&' + this.options.defaultParams;
new Ajax.Request(this.url, this.options);
},
onComplete: function(request) {
this.updateChoices(request.responseText);
}
});
// The local array autocompleter. Used when you'd prefer to
// inject an array of autocompletion options into the page, rather
// than sending out Ajax queries, which can be quite slow sometimes.
//
// The constructor takes four parameters. The first two are, as usual,
// the id of the monitored textbox, and id of the autocompletion menu.
// The third is the array you want to autocomplete from, and the fourth
// is the options block.
//
// Extra local autocompletion options:
// - choices - How many autocompletion choices to offer
//
// - partialSearch - If false, the autocompleter will match entered
// text only at the beginning of strings in the
// autocomplete array. Defaults to true, which will
// match text at the beginning of any *word* in the
// strings in the autocomplete array. If you want to
// search anywhere in the string, additionally set
// the option fullSearch to true (default: off).
//
// - fullSsearch - Search anywhere in autocomplete array strings.
//
// - partialChars - How many characters to enter before triggering
// a partial match (unlike minChars, which defines
// how many characters are required to do any match
// at all). Defaults to 2.
//
// - ignoreCase - Whether to ignore case when autocompleting.
// Defaults to true.
//
// It's possible to pass in a custom function as the 'selector'
// option, if you prefer to write your own autocompletion logic.
// In that case, the other options above will not apply unless
// you support them.
Autocompleter.Local = Class.create();
Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), {
initialize: function(element, update, array, options) {
this.baseInitialize(element, update, options);
this.options.array = array;
},
getUpdatedChoices: function() {
this.updateChoices(this.options.selector(this));
},
setOptions: function(options) {
this.options = Object.extend({
choices: 10,
partialSearch: true,
partialChars: 2,
ignoreCase: true,
fullSearch: false,
selector: function(instance) {
var ret = []; // Beginning matches
var partial = []; // Inside matches
var entry = instance.getToken();
var count = 0;
for (var i = 0; i < instance.options.array.length &&
ret.length < instance.options.choices ; i++) {
var elem = instance.options.array[i];
var foundPos = instance.options.ignoreCase ?
elem.toLowerCase().indexOf(entry.toLowerCase()) :
elem.indexOf(entry);
while (foundPos != -1) {
if (foundPos == 0 && elem.length != entry.length) {
ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
elem.substr(entry.length) + "</li>");
break;
} else if (entry.length >= instance.options.partialChars &&
instance.options.partialSearch && foundPos != -1) {
if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
elem.substr(foundPos, entry.length) + "</strong>" + elem.substr(
foundPos + entry.length) + "</li>");
break;
}
}
foundPos = instance.options.ignoreCase ?
elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
elem.indexOf(entry, foundPos + 1);
}
}
if (partial.length)
ret = ret.concat(partial.slice(0, instance.options.choices - ret.length))
return "<ul>" + ret.join('') + "</ul>";
}
}, options || {});
}
});
// AJAX in-place editor
//
// see documentation on http://wiki.script.aculo.us/scriptaculous/show/Ajax.InPlaceEditor
// Use this if you notice weird scrolling problems on some browsers,
// the DOM might be a bit confused when this gets called so do this
// waits 1 ms (with setTimeout) until it does the activation
Field.scrollFreeActivate = function(field) {
setTimeout(function() {
Field.activate(field);
}, 1);
}
Ajax.InPlaceEditor = Class.create();
Ajax.InPlaceEditor.defaultHighlightColor = "#FFFF99";
Ajax.InPlaceEditor.prototype = {
initialize: function(element, url, options) {
this.url = url;
this.element = $(element);
this.options = Object.extend({
okButton: true,
okText: "ok",
cancelLink: true,
cancelText: "cancel",
savingText: "Saving...",
clickToEditText: "Click to edit",
okText: "ok",
rows: 1,
onComplete: function(transport, element) {
new Effect.Highlight(element, {startcolor: this.options.highlightcolor});
},
onFailure: function(transport) {
alert("Error communicating with the server: " + transport.responseText.stripTags());
},
callback: function(form) {
return Form.serialize(form);
},
handleLineBreaks: true,
loadingText: 'Loading...',
savingClassName: 'inplaceeditor-saving',
loadingClassName: 'inplaceeditor-loading',
formClassName: 'inplaceeditor-form',
highlightcolor: Ajax.InPlaceEditor.defaultHighlightColor,
highlightendcolor: "#FFFFFF",
externalControl: null,
submitOnBlur: false,
ajaxOptions: {},
evalScripts: false
}, options || {});
if(!this.options.formId && this.element.id) {
this.options.formId = this.element.id + "-inplaceeditor";
if ($(this.options.formId)) {
// there's already a form with that name, don't specify an id
this.options.formId = null;
}
}
if (this.options.externalControl) {
this.options.externalControl = $(this.options.externalControl);
}
this.originalBackground = Element.getStyle(this.element, 'background-color');
if (!this.originalBackground) {
this.originalBackground = "transparent";
}
this.element.title = this.options.clickToEditText;
this.onclickListener = this.enterEditMode.bindAsEventListener(this);
this.mouseoverListener = this.enterHover.bindAsEventListener(this);
this.mouseoutListener = this.leaveHover.bindAsEventListener(this);
Event.observe(this.element, 'click', this.onclickListener);
Event.observe(this.element, 'mouseover', this.mouseoverListener);
Event.observe(this.element, 'mouseout', this.mouseoutListener);
if (this.options.externalControl) {
Event.observe(this.options.externalControl, 'click', this.onclickListener);
Event.observe(this.options.externalControl, 'mouseover', this.mouseoverListener);
Event.observe(this.options.externalControl, 'mouseout', this.mouseoutListener);
}
},
enterEditMode: function(evt) {
if (this.saving) return;
if (this.editing) return;
this.editing = true;
this.onEnterEditMode();
if (this.options.externalControl) {
Element.hide(this.options.externalControl);
}
Element.hide(this.element);
this.createForm();
this.element.parentNode.insertBefore(this.form, this.element);
Field.scrollFreeActivate(this.editField);
// stop the event to avoid a page refresh in Safari
if (evt) {
Event.stop(evt);
}
return false;
},
createForm: function() {
this.form = document.createElement("form");
this.form.id = this.options.formId;
Element.addClassName(this.form, this.options.formClassName)
this.form.onsubmit = this.onSubmit.bind(this);
this.createEditField();
if (this.options.textarea) {
var br = document.createElement("br");
this.form.appendChild(br);
}
if (this.options.okButton) {
okButton = document.createElement("input");
okButton.type = "submit";
okButton.value = this.options.okText;
okButton.className = 'editor_ok_button';
this.form.appendChild(okButton);
}
if (this.options.cancelLink) {
cancelLink = document.createElement("a");
cancelLink.href = "#";
cancelLink.appendChild(document.createTextNode(this.options.cancelText));
cancelLink.onclick = this.onclickCancel.bind(this);
cancelLink.className = 'editor_cancel';
this.form.appendChild(cancelLink);
}
},
hasHTMLLineBreaks: function(string) {
if (!this.options.handleLineBreaks) return false;
return string.match(/<br/i) || string.match(/<p>/i);
},
convertHTMLLineBreaks: function(string) {
return string.replace(/<br>/gi, "\n").replace(/<br\/>/gi, "\n").replace(/<\/p>/gi, "\n").replace(/<p>/gi, "");
},
createEditField: function() {
var text;
if(this.options.loadTextURL) {
text = this.options.loadingText;
} else {
text = this.getText();
}
var obj = this;
if (this.options.rows == 1 && !this.hasHTMLLineBreaks(text)) {
this.options.textarea = false;
var textField = document.createElement("input");
textField.obj = this;
textField.type = "text";
textField.name = "value";
textField.value = text;
textField.style.backgroundColor = this.options.highlightcolor;
textField.className = 'editor_field';
var size = this.options.size || this.options.cols || 0;
if (size != 0) textField.size = size;
if (this.options.submitOnBlur)
textField.onblur = this.onSubmit.bind(this);
this.editField = textField;
} else {
this.options.textarea = true;
var textArea = document.createElement("textarea");
textArea.obj = this;
textArea.name = "value";
textArea.value = this.convertHTMLLineBreaks(text);
textArea.rows = this.options.rows;
textArea.cols = this.options.cols || 40;
textArea.className = 'editor_field';
if (this.options.submitOnBlur)
textArea.onblur = this.onSubmit.bind(this);
this.editField = textArea;
}
if(this.options.loadTextURL) {
this.loadExternalText();
}
this.form.appendChild(this.editField);
},
getText: function() {
return this.element.innerHTML;
},
loadExternalText: function() {
Element.addClassName(this.form, this.options.loadingClassName);
this.editField.disabled = true;
new Ajax.Request(
this.options.loadTextURL,
Object.extend({
asynchronous: true,
onComplete: this.onLoadedExternalText.bind(this)
}, this.options.ajaxOptions)
);
},
onLoadedExternalText: function(transport) {
Element.removeClassName(this.form, this.options.loadingClassName);
this.editField.disabled = false;
this.editField.value = transport.responseText.stripTags();
},
onclickCancel: function() {
this.onComplete();
this.leaveEditMode();
return false;
},
onFailure: function(transport) {
this.options.onFailure(transport);
if (this.oldInnerHTML) {
this.element.innerHTML = this.oldInnerHTML;
this.oldInnerHTML = null;
}
return false;
},
onSubmit: function() {
// onLoading resets these so we need to save them away for the Ajax call
var form = this.form;
var value = this.editField.value;
// do this first, sometimes the ajax call returns before we get a chance to switch on Saving...
// which means this will actually switch on Saving... *after* we've left edit mode causing Saving...
// to be displayed indefinitely
this.onLoading();
if (this.options.evalScripts) {
new Ajax.Request(
this.url, Object.extend({
parameters: this.options.callback(form, value),
onComplete: this.onComplete.bind(this),
onFailure: this.onFailure.bind(this),
asynchronous:true,
evalScripts:true
}, this.options.ajaxOptions));
} else {
new Ajax.Updater(
{ success: this.element,
// don't update on failure (this could be an option)
failure: null },
this.url, Object.extend({
parameters: this.options.callback(form, value),
onComplete: this.onComplete.bind(this),
onFailure: this.onFailure.bind(this)
}, this.options.ajaxOptions));
}
// stop the event to avoid a page refresh in Safari
if (arguments.length > 1) {
Event.stop(arguments[0]);
}
return false;
},
onLoading: function() {
this.saving = true;
this.removeForm();
this.leaveHover();
this.showSaving();
},
showSaving: function() {
this.oldInnerHTML = this.element.innerHTML;
this.element.innerHTML = this.options.savingText;
Element.addClassName(this.element, this.options.savingClassName);
this.element.style.backgroundColor = this.originalBackground;
Element.show(this.element);
},
removeForm: function() {
if(this.form) {
if (this.form.parentNode) Element.remove(this.form);
this.form = null;
}
},
enterHover: function() {
if (this.saving) return;
this.element.style.backgroundColor = this.options.highlightcolor;
if (this.effect) {
this.effect.cancel();
}
Element.addClassName(this.element, this.options.hoverClassName)
},
leaveHover: function() {
if (this.options.backgroundColor) {
this.element.style.backgroundColor = this.oldBackground;
}
Element.removeClassName(this.element, this.options.hoverClassName)
if (this.saving) return;
this.effect = new Effect.Highlight(this.element, {
startcolor: this.options.highlightcolor,
endcolor: this.options.highlightendcolor,
restorecolor: this.originalBackground
});
},
leaveEditMode: function() {
Element.removeClassName(this.element, this.options.savingClassName);
this.removeForm();
this.leaveHover();
this.element.style.backgroundColor = this.originalBackground;
Element.show(this.element);
if (this.options.externalControl) {
Element.show(this.options.externalControl);
}
this.editing = false;
this.saving = false;
this.oldInnerHTML = null;
this.onLeaveEditMode();
},
onComplete: function(transport) {
this.leaveEditMode();
this.options.onComplete.bind(this)(transport, this.element);
},
onEnterEditMode: function() {},
onLeaveEditMode: function() {},
dispose: function() {
if (this.oldInnerHTML) {
this.element.innerHTML = this.oldInnerHTML;
}
this.leaveEditMode();
Event.stopObserving(this.element, 'click', this.onclickListener);
Event.stopObserving(this.element, 'mouseover', this.mouseoverListener);
Event.stopObserving(this.element, 'mouseout', this.mouseoutListener);
if (this.options.externalControl) {
Event.stopObserving(this.options.externalControl, 'click', this.onclickListener);
Event.stopObserving(this.options.externalControl, 'mouseover', this.mouseoverListener);
Event.stopObserving(this.options.externalControl, 'mouseout', this.mouseoutListener);
}
}
};
Ajax.InPlaceCollectionEditor = Class.create();
Object.extend(Ajax.InPlaceCollectionEditor.prototype, Ajax.InPlaceEditor.prototype);
Object.extend(Ajax.InPlaceCollectionEditor.prototype, {
createEditField: function() {
if (!this.cached_selectTag) {
var selectTag = document.createElement("select");
var collection = this.options.collection || [];
var optionTag;
collection.each(function(e,i) {
optionTag = document.createElement("option");
optionTag.value = (e instanceof Array) ? e[0] : e;
if(this.options.value==optionTag.value) optionTag.selected = true;
optionTag.appendChild(document.createTextNode((e instanceof Array) ? e[1] : e));
selectTag.appendChild(optionTag);
}.bind(this));
this.cached_selectTag = selectTag;
}
this.editField = this.cached_selectTag;
if(this.options.loadTextURL) this.loadExternalText();
this.form.appendChild(this.editField);
this.options.callback = function(form, value) {
return "value=" + encodeURIComponent(value);
}
}
});
// Delayed observer, like Form.Element.Observer,
// but waits for delay after last key input
// Ideal for live-search fields
Form.Element.DelayedObserver = Class.create();
Form.Element.DelayedObserver.prototype = {
initialize: function(element, delay, callback) {
this.delay = delay || 0.5;
this.element = $(element);
this.callback = callback;
this.timer = null;
this.lastValue = $F(this.element);
Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this));
},
delayedListener: function(event) {
if(this.lastValue == $F(this.element)) return;
if(this.timer) clearTimeout(this.timer);
this.timer = setTimeout(this.onTimerEvent.bind(this), this.delay * 1000);
this.lastValue = $F(this.element);
},
onTimerEvent: function() {
this.timer = null;
this.callback(this.element, $F(this.element));
}
};

View file

@ -0,0 +1,915 @@
// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
// (c) 2005 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz)
//
// See scriptaculous.js for full license.
/*--------------------------------------------------------------------------*/
var Droppables = {
drops: [],
remove: function(element) {
this.drops = this.drops.reject(function(d) { return d.element==$(element) });
},
add: function(element) {
element = $(element);
var options = Object.extend({
greedy: true,
hoverclass: null,
tree: false
}, arguments[1] || {});
// cache containers
if(options.containment) {
options._containers = [];
var containment = options.containment;
if((typeof containment == 'object') &&
(containment.constructor == Array)) {
containment.each( function(c) { options._containers.push($(c)) });
} else {
options._containers.push($(containment));
}
}
if(options.accept) options.accept = [options.accept].flatten();
Element.makePositioned(element); // fix IE
options.element = element;
this.drops.push(options);
},
findDeepestChild: function(drops) {
deepest = drops[0];
for (i = 1; i < drops.length; ++i)
if (Element.isParent(drops[i].element, deepest.element))
deepest = drops[i];
return deepest;
},
isContained: function(element, drop) {
var containmentNode;
if(drop.tree) {
containmentNode = element.treeNode;
} else {
containmentNode = element.parentNode;
}
return drop._containers.detect(function(c) { return containmentNode == c });
},
isAffected: function(point, element, drop) {
return (
(drop.element!=element) &&
((!drop._containers) ||
this.isContained(element, drop)) &&
((!drop.accept) ||
(Element.classNames(element).detect(
function(v) { return drop.accept.include(v) } ) )) &&
Position.within(drop.element, point[0], point[1]) );
},
deactivate: function(drop) {
if(drop.hoverclass)
Element.removeClassName(drop.element, drop.hoverclass);
this.last_active = null;
},
activate: function(drop) {
if(drop.hoverclass)
Element.addClassName(drop.element, drop.hoverclass);
this.last_active = drop;
},
show: function(point, element) {
if(!this.drops.length) return;
var affected = [];
if(this.last_active) this.deactivate(this.last_active);
this.drops.each( function(drop) {
if(Droppables.isAffected(point, element, drop))
affected.push(drop);
});
if(affected.length>0) {
drop = Droppables.findDeepestChild(affected);
Position.within(drop.element, point[0], point[1]);
if(drop.onHover)
drop.onHover(element, drop.element, Position.overlap(drop.overlap, drop.element));
Droppables.activate(drop);
}
},
fire: function(event, element) {
if(!this.last_active) return;
Position.prepare();
if (this.isAffected([Event.pointerX(event), Event.pointerY(event)], element, this.last_active))
if (this.last_active.onDrop)
this.last_active.onDrop(element, this.last_active.element, event);
},
reset: function() {
if(this.last_active)
this.deactivate(this.last_active);
}
}
var Draggables = {
drags: [],
observers: [],
register: function(draggable) {
if(this.drags.length == 0) {
this.eventMouseUp = this.endDrag.bindAsEventListener(this);
this.eventMouseMove = this.updateDrag.bindAsEventListener(this);
this.eventKeypress = this.keyPress.bindAsEventListener(this);
Event.observe(document, "mouseup", this.eventMouseUp);
Event.observe(document, "mousemove", this.eventMouseMove);
Event.observe(document, "keypress", this.eventKeypress);
}
this.drags.push(draggable);
},
unregister: function(draggable) {
this.drags = this.drags.reject(function(d) { return d==draggable });
if(this.drags.length == 0) {
Event.stopObserving(document, "mouseup", this.eventMouseUp);
Event.stopObserving(document, "mousemove", this.eventMouseMove);
Event.stopObserving(document, "keypress", this.eventKeypress);
}
},
activate: function(draggable) {
window.focus(); // allows keypress events if window isn't currently focused, fails for Safari
this.activeDraggable = draggable;
},
deactivate: function() {
this.activeDraggable = null;
},
updateDrag: function(event) {
if(!this.activeDraggable) return;
var pointer = [Event.pointerX(event), Event.pointerY(event)];
// Mozilla-based browsers fire successive mousemove events with
// the same coordinates, prevent needless redrawing (moz bug?)
if(this._lastPointer && (this._lastPointer.inspect() == pointer.inspect())) return;
this._lastPointer = pointer;
this.activeDraggable.updateDrag(event, pointer);
},
endDrag: function(event) {
if(!this.activeDraggable) return;
this._lastPointer = null;
this.activeDraggable.endDrag(event);
this.activeDraggable = null;
},
keyPress: function(event) {
if(this.activeDraggable)
this.activeDraggable.keyPress(event);
},
addObserver: function(observer) {
this.observers.push(observer);
this._cacheObserverCallbacks();
},
removeObserver: function(element) { // element instead of observer fixes mem leaks
this.observers = this.observers.reject( function(o) { return o.element==element });
this._cacheObserverCallbacks();
},
notify: function(eventName, draggable, event) { // 'onStart', 'onEnd', 'onDrag'
if(this[eventName+'Count'] > 0)
this.observers.each( function(o) {
if(o[eventName]) o[eventName](eventName, draggable, event);
});
},
_cacheObserverCallbacks: function() {
['onStart','onEnd','onDrag'].each( function(eventName) {
Draggables[eventName+'Count'] = Draggables.observers.select(
function(o) { return o[eventName]; }
).length;
});
}
}
/*--------------------------------------------------------------------------*/
var Draggable = Class.create();
Draggable.prototype = {
initialize: function(element) {
var options = Object.extend({
handle: false,
starteffect: function(element) {
element._opacity = Element.getOpacity(element);
new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7});
},
reverteffect: function(element, top_offset, left_offset) {
var dur = Math.sqrt(Math.abs(top_offset^2)+Math.abs(left_offset^2))*0.02;
element._revert = new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: dur});
},
endeffect: function(element) {
var toOpacity = typeof element._opacity == 'number' ? element._opacity : 1.0
new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity});
},
zindex: 1000,
revert: false,
scroll: false,
scrollSensitivity: 20,
scrollSpeed: 15,
snap: false // false, or xy or [x,y] or function(x,y){ return [x,y] }
}, arguments[1] || {});
this.element = $(element);
if(options.handle && (typeof options.handle == 'string')) {
var h = Element.childrenWithClassName(this.element, options.handle, true);
if(h.length>0) this.handle = h[0];
}
if(!this.handle) this.handle = $(options.handle);
if(!this.handle) this.handle = this.element;
if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML)
options.scroll = $(options.scroll);
Element.makePositioned(this.element); // fix IE
this.delta = this.currentDelta();
this.options = options;
this.dragging = false;
this.eventMouseDown = this.initDrag.bindAsEventListener(this);
Event.observe(this.handle, "mousedown", this.eventMouseDown);
Draggables.register(this);
},
destroy: function() {
Event.stopObserving(this.handle, "mousedown", this.eventMouseDown);
Draggables.unregister(this);
},
currentDelta: function() {
return([
parseInt(Element.getStyle(this.element,'left') || '0'),
parseInt(Element.getStyle(this.element,'top') || '0')]);
},
initDrag: function(event) {
if(Event.isLeftClick(event)) {
// abort on form elements, fixes a Firefox issue
var src = Event.element(event);
if(src.tagName && (
src.tagName=='INPUT' ||
src.tagName=='SELECT' ||
src.tagName=='OPTION' ||
src.tagName=='BUTTON' ||
src.tagName=='TEXTAREA')) return;
if(this.element._revert) {
this.element._revert.cancel();
this.element._revert = null;
}
var pointer = [Event.pointerX(event), Event.pointerY(event)];
var pos = Position.cumulativeOffset(this.element);
this.offset = [0,1].map( function(i) { return (pointer[i] - pos[i]) });
Draggables.activate(this);
Event.stop(event);
}
},
startDrag: function(event) {
this.dragging = true;
if(this.options.zindex) {
this.originalZ = parseInt(Element.getStyle(this.element,'z-index') || 0);
this.element.style.zIndex = this.options.zindex;
}
if(this.options.ghosting) {
this._clone = this.element.cloneNode(true);
Position.absolutize(this.element);
this.element.parentNode.insertBefore(this._clone, this.element);
}
if(this.options.scroll) {
if (this.options.scroll == window) {
var where = this._getWindowScroll(this.options.scroll);
this.originalScrollLeft = where.left;
this.originalScrollTop = where.top;
} else {
this.originalScrollLeft = this.options.scroll.scrollLeft;
this.originalScrollTop = this.options.scroll.scrollTop;
}
}
Draggables.notify('onStart', this, event);
if(this.options.starteffect) this.options.starteffect(this.element);
},
updateDrag: function(event, pointer) {
if(!this.dragging) this.startDrag(event);
Position.prepare();
Droppables.show(pointer, this.element);
Draggables.notify('onDrag', this, event);
this.draw(pointer);
if(this.options.change) this.options.change(this);
if(this.options.scroll) {
this.stopScrolling();
var p;
if (this.options.scroll == window) {
with(this._getWindowScroll(this.options.scroll)) { p = [ left, top, left+width, top+height ]; }
} else {
p = Position.page(this.options.scroll);
p[0] += this.options.scroll.scrollLeft;
p[1] += this.options.scroll.scrollTop;
p.push(p[0]+this.options.scroll.offsetWidth);
p.push(p[1]+this.options.scroll.offsetHeight);
}
var speed = [0,0];
if(pointer[0] < (p[0]+this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[0]+this.options.scrollSensitivity);
if(pointer[1] < (p[1]+this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[1]+this.options.scrollSensitivity);
if(pointer[0] > (p[2]-this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[2]-this.options.scrollSensitivity);
if(pointer[1] > (p[3]-this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[3]-this.options.scrollSensitivity);
this.startScrolling(speed);
}
// fix AppleWebKit rendering
if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0);
Event.stop(event);
},
finishDrag: function(event, success) {
this.dragging = false;
if(this.options.ghosting) {
Position.relativize(this.element);
Element.remove(this._clone);
this._clone = null;
}
if(success) Droppables.fire(event, this.element);
Draggables.notify('onEnd', this, event);
var revert = this.options.revert;
if(revert && typeof revert == 'function') revert = revert(this.element);
var d = this.currentDelta();
if(revert && this.options.reverteffect) {
this.options.reverteffect(this.element,
d[1]-this.delta[1], d[0]-this.delta[0]);
} else {
this.delta = d;
}
if(this.options.zindex)
this.element.style.zIndex = this.originalZ;
if(this.options.endeffect)
this.options.endeffect(this.element);
Draggables.deactivate(this);
Droppables.reset();
},
keyPress: function(event) {
if(event.keyCode!=Event.KEY_ESC) return;
this.finishDrag(event, false);
Event.stop(event);
},
endDrag: function(event) {
if(!this.dragging) return;
this.stopScrolling();
this.finishDrag(event, true);
Event.stop(event);
},
draw: function(point) {
var pos = Position.cumulativeOffset(this.element);
var d = this.currentDelta();
pos[0] -= d[0]; pos[1] -= d[1];
if(this.options.scroll && (this.options.scroll != window)) {
pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft;
pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop;
}
var p = [0,1].map(function(i){
return (point[i]-pos[i]-this.offset[i])
}.bind(this));
if(this.options.snap) {
if(typeof this.options.snap == 'function') {
p = this.options.snap(p[0],p[1],this);
} else {
if(this.options.snap instanceof Array) {
p = p.map( function(v, i) {
return Math.round(v/this.options.snap[i])*this.options.snap[i] }.bind(this))
} else {
p = p.map( function(v) {
return Math.round(v/this.options.snap)*this.options.snap }.bind(this))
}
}}
var style = this.element.style;
if((!this.options.constraint) || (this.options.constraint=='horizontal'))
style.left = p[0] + "px";
if((!this.options.constraint) || (this.options.constraint=='vertical'))
style.top = p[1] + "px";
if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering
},
stopScrolling: function() {
if(this.scrollInterval) {
clearInterval(this.scrollInterval);
this.scrollInterval = null;
Draggables._lastScrollPointer = null;
}
},
startScrolling: function(speed) {
this.scrollSpeed = [speed[0]*this.options.scrollSpeed,speed[1]*this.options.scrollSpeed];
this.lastScrolled = new Date();
this.scrollInterval = setInterval(this.scroll.bind(this), 10);
},
scroll: function() {
var current = new Date();
var delta = current - this.lastScrolled;
this.lastScrolled = current;
if(this.options.scroll == window) {
with (this._getWindowScroll(this.options.scroll)) {
if (this.scrollSpeed[0] || this.scrollSpeed[1]) {
var d = delta / 1000;
this.options.scroll.scrollTo( left + d*this.scrollSpeed[0], top + d*this.scrollSpeed[1] );
}
}
} else {
this.options.scroll.scrollLeft += this.scrollSpeed[0] * delta / 1000;
this.options.scroll.scrollTop += this.scrollSpeed[1] * delta / 1000;
}
Position.prepare();
Droppables.show(Draggables._lastPointer, this.element);
Draggables.notify('onDrag', this);
Draggables._lastScrollPointer = Draggables._lastScrollPointer || $A(Draggables._lastPointer);
Draggables._lastScrollPointer[0] += this.scrollSpeed[0] * delta / 1000;
Draggables._lastScrollPointer[1] += this.scrollSpeed[1] * delta / 1000;
if (Draggables._lastScrollPointer[0] < 0)
Draggables._lastScrollPointer[0] = 0;
if (Draggables._lastScrollPointer[1] < 0)
Draggables._lastScrollPointer[1] = 0;
this.draw(Draggables._lastScrollPointer);
if(this.options.change) this.options.change(this);
},
_getWindowScroll: function(w) {
var T, L, W, H;
with (w.document) {
if (w.document.documentElement && documentElement.scrollTop) {
T = documentElement.scrollTop;
L = documentElement.scrollLeft;
} else if (w.document.body) {
T = body.scrollTop;
L = body.scrollLeft;
}
if (w.innerWidth) {
W = w.innerWidth;
H = w.innerHeight;
} else if (w.document.documentElement && documentElement.clientWidth) {
W = documentElement.clientWidth;
H = documentElement.clientHeight;
} else {
W = body.offsetWidth;
H = body.offsetHeight
}
}
return { top: T, left: L, width: W, height: H };
}
}
/*--------------------------------------------------------------------------*/
var SortableObserver = Class.create();
SortableObserver.prototype = {
initialize: function(element, observer) {
this.element = $(element);
this.observer = observer;
this.lastValue = Sortable.serialize(this.element);
},
onStart: function() {
this.lastValue = Sortable.serialize(this.element);
},
onEnd: function() {
Sortable.unmark();
if(this.lastValue != Sortable.serialize(this.element))
this.observer(this.element)
}
}
var Sortable = {
sortables: {},
_findRootElement: function(element) {
while (element.tagName != "BODY") {
if(element.id && Sortable.sortables[element.id]) return element;
element = element.parentNode;
}
},
options: function(element) {
element = Sortable._findRootElement($(element));
if(!element) return;
return Sortable.sortables[element.id];
},
destroy: function(element){
var s = Sortable.options(element);
if(s) {
Draggables.removeObserver(s.element);
s.droppables.each(function(d){ Droppables.remove(d) });
s.draggables.invoke('destroy');
delete Sortable.sortables[s.element.id];
}
},
create: function(element) {
element = $(element);
var options = Object.extend({
element: element,
tag: 'li', // assumes li children, override with tag: 'tagname'
dropOnEmpty: false,
tree: false,
treeTag: 'ul',
overlap: 'vertical', // one of 'vertical', 'horizontal'
constraint: 'vertical', // one of 'vertical', 'horizontal', false
containment: element, // also takes array of elements (or id's); or false
handle: false, // or a CSS class
only: false,
hoverclass: null,
ghosting: false,
scroll: false,
scrollSensitivity: 20,
scrollSpeed: 15,
format: /^[^_]*_(.*)$/,
onChange: Prototype.emptyFunction,
onUpdate: Prototype.emptyFunction
}, arguments[1] || {});
// clear any old sortable with same element
this.destroy(element);
// build options for the draggables
var options_for_draggable = {
revert: true,
scroll: options.scroll,
scrollSpeed: options.scrollSpeed,
scrollSensitivity: options.scrollSensitivity,
ghosting: options.ghosting,
constraint: options.constraint,
handle: options.handle };
if(options.starteffect)
options_for_draggable.starteffect = options.starteffect;
if(options.reverteffect)
options_for_draggable.reverteffect = options.reverteffect;
else
if(options.ghosting) options_for_draggable.reverteffect = function(element) {
element.style.top = 0;
element.style.left = 0;
};
if(options.endeffect)
options_for_draggable.endeffect = options.endeffect;
if(options.zindex)
options_for_draggable.zindex = options.zindex;
// build options for the droppables
var options_for_droppable = {
overlap: options.overlap,
containment: options.containment,
tree: options.tree,
hoverclass: options.hoverclass,
onHover: Sortable.onHover
//greedy: !options.dropOnEmpty
}
var options_for_tree = {
onHover: Sortable.onEmptyHover,
overlap: options.overlap,
containment: options.containment,
hoverclass: options.hoverclass
}
// fix for gecko engine
Element.cleanWhitespace(element);
options.draggables = [];
options.droppables = [];
// drop on empty handling
if(options.dropOnEmpty || options.tree) {
Droppables.add(element, options_for_tree);
options.droppables.push(element);
}
(this.findElements(element, options) || []).each( function(e) {
// handles are per-draggable
var handle = options.handle ?
Element.childrenWithClassName(e, options.handle)[0] : e;
options.draggables.push(
new Draggable(e, Object.extend(options_for_draggable, { handle: handle })));
Droppables.add(e, options_for_droppable);
if(options.tree) e.treeNode = element;
options.droppables.push(e);
});
if(options.tree) {
(Sortable.findTreeElements(element, options) || []).each( function(e) {
Droppables.add(e, options_for_tree);
e.treeNode = element;
options.droppables.push(e);
});
}
// keep reference
this.sortables[element.id] = options;
// for onupdate
Draggables.addObserver(new SortableObserver(element, options.onUpdate));
},
// return all suitable-for-sortable elements in a guaranteed order
findElements: function(element, options) {
return Element.findChildren(
element, options.only, options.tree ? true : false, options.tag);
},
findTreeElements: function(element, options) {
return Element.findChildren(
element, options.only, options.tree ? true : false, options.treeTag);
},
onHover: function(element, dropon, overlap) {
if(Element.isParent(dropon, element)) return;
if(overlap > .33 && overlap < .66 && Sortable.options(dropon).tree) {
return;
} else if(overlap>0.5) {
Sortable.mark(dropon, 'before');
if(dropon.previousSibling != element) {
var oldParentNode = element.parentNode;
element.style.visibility = "hidden"; // fix gecko rendering
dropon.parentNode.insertBefore(element, dropon);
if(dropon.parentNode!=oldParentNode)
Sortable.options(oldParentNode).onChange(element);
Sortable.options(dropon.parentNode).onChange(element);
}
} else {
Sortable.mark(dropon, 'after');
var nextElement = dropon.nextSibling || null;
if(nextElement != element) {
var oldParentNode = element.parentNode;
element.style.visibility = "hidden"; // fix gecko rendering
dropon.parentNode.insertBefore(element, nextElement);
if(dropon.parentNode!=oldParentNode)
Sortable.options(oldParentNode).onChange(element);
Sortable.options(dropon.parentNode).onChange(element);
}
}
},
onEmptyHover: function(element, dropon, overlap) {
var oldParentNode = element.parentNode;
var droponOptions = Sortable.options(dropon);
if(!Element.isParent(dropon, element)) {
var index;
var children = Sortable.findElements(dropon, {tag: droponOptions.tag});
var child = null;
if(children) {
var offset = Element.offsetSize(dropon, droponOptions.overlap) * (1.0 - overlap);
for (index = 0; index < children.length; index += 1) {
if (offset - Element.offsetSize (children[index], droponOptions.overlap) >= 0) {
offset -= Element.offsetSize (children[index], droponOptions.overlap);
} else if (offset - (Element.offsetSize (children[index], droponOptions.overlap) / 2) >= 0) {
child = index + 1 < children.length ? children[index + 1] : null;
break;
} else {
child = children[index];
break;
}
}
}
dropon.insertBefore(element, child);
Sortable.options(oldParentNode).onChange(element);
droponOptions.onChange(element);
}
},
unmark: function() {
if(Sortable._marker) Element.hide(Sortable._marker);
},
mark: function(dropon, position) {
// mark on ghosting only
var sortable = Sortable.options(dropon.parentNode);
if(sortable && !sortable.ghosting) return;
if(!Sortable._marker) {
Sortable._marker = $('dropmarker') || document.createElement('DIV');
Element.hide(Sortable._marker);
Element.addClassName(Sortable._marker, 'dropmarker');
Sortable._marker.style.position = 'absolute';
document.getElementsByTagName("body").item(0).appendChild(Sortable._marker);
}
var offsets = Position.cumulativeOffset(dropon);
Sortable._marker.style.left = offsets[0] + 'px';
Sortable._marker.style.top = offsets[1] + 'px';
if(position=='after')
if(sortable.overlap == 'horizontal')
Sortable._marker.style.left = (offsets[0]+dropon.clientWidth) + 'px';
else
Sortable._marker.style.top = (offsets[1]+dropon.clientHeight) + 'px';
Element.show(Sortable._marker);
},
_tree: function(element, options, parent) {
var children = Sortable.findElements(element, options) || [];
for (var i = 0; i < children.length; ++i) {
var match = children[i].id.match(options.format);
if (!match) continue;
var child = {
id: encodeURIComponent(match ? match[1] : null),
element: element,
parent: parent,
children: new Array,
position: parent.children.length,
container: Sortable._findChildrenElement(children[i], options.treeTag.toUpperCase())
}
/* Get the element containing the children and recurse over it */
if (child.container)
this._tree(child.container, options, child)
parent.children.push (child);
}
return parent;
},
/* Finds the first element of the given tag type within a parent element.
Used for finding the first LI[ST] within a L[IST]I[TEM].*/
_findChildrenElement: function (element, containerTag) {
if (element && element.hasChildNodes)
for (var i = 0; i < element.childNodes.length; ++i)
if (element.childNodes[i].tagName == containerTag)
return element.childNodes[i];
return null;
},
tree: function(element) {
element = $(element);
var sortableOptions = this.options(element);
var options = Object.extend({
tag: sortableOptions.tag,
treeTag: sortableOptions.treeTag,
only: sortableOptions.only,
name: element.id,
format: sortableOptions.format
}, arguments[1] || {});
var root = {
id: null,
parent: null,
children: new Array,
container: element,
position: 0
}
return Sortable._tree (element, options, root);
},
/* Construct a [i] index for a particular node */
_constructIndex: function(node) {
var index = '';
do {
if (node.id) index = '[' + node.position + ']' + index;
} while ((node = node.parent) != null);
return index;
},
sequence: function(element) {
element = $(element);
var options = Object.extend(this.options(element), arguments[1] || {});
return $(this.findElements(element, options) || []).map( function(item) {
return item.id.match(options.format) ? item.id.match(options.format)[1] : '';
});
},
setSequence: function(element, new_sequence) {
element = $(element);
var options = Object.extend(this.options(element), arguments[2] || {});
var nodeMap = {};
this.findElements(element, options).each( function(n) {
if (n.id.match(options.format))
nodeMap[n.id.match(options.format)[1]] = [n, n.parentNode];
n.parentNode.removeChild(n);
});
new_sequence.each(function(ident) {
var n = nodeMap[ident];
if (n) {
n[1].appendChild(n[0]);
delete nodeMap[ident];
}
});
},
serialize: function(element) {
element = $(element);
var options = Object.extend(Sortable.options(element), arguments[1] || {});
var name = encodeURIComponent(
(arguments[1] && arguments[1].name) ? arguments[1].name : element.id);
if (options.tree) {
return Sortable.tree(element, arguments[1]).children.map( function (item) {
return [name + Sortable._constructIndex(item) + "=" +
encodeURIComponent(item.id)].concat(item.children.map(arguments.callee));
}).flatten().join('&');
} else {
return Sortable.sequence(element, arguments[1]).map( function(item) {
return name + "[]=" + encodeURIComponent(item);
}).join('&');
}
}
}
/* Returns true if child is contained within element */
Element.isParent = function(child, element) {
if (!child.parentNode || child == element) return false;
if (child.parentNode == element) return true;
return Element.isParent(child.parentNode, element);
}
Element.findChildren = function(element, only, recursive, tagName) {
if(!element.hasChildNodes()) return null;
tagName = tagName.toUpperCase();
if(only) only = [only].flatten();
var elements = [];
$A(element.childNodes).each( function(e) {
if(e.tagName && e.tagName.toUpperCase()==tagName &&
(!only || (Element.classNames(e).detect(function(v) { return only.include(v) }))))
elements.push(e);
if(recursive) {
var grandchildren = Element.findChildren(e, only, recursive, tagName);
if(grandchildren) elements.push(grandchildren);
}
});
return (elements.length>0 ? elements.flatten() : []);
}
Element.offsetSize = function (element, type) {
if (type == 'vertical' || type == 'height')
return element.offsetHeight;
else
return element.offsetWidth;
}

View file

@ -0,0 +1,958 @@
// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
// Contributors:
// Justin Palmer (http://encytemedia.com/)
// Mark Pilgrim (http://diveintomark.org/)
// Martin Bialasinki
//
// See scriptaculous.js for full license.
// converts rgb() and #xxx to #xxxxxx format,
// returns self (or first argument) if not convertable
String.prototype.parseColor = function() {
var color = '#';
if(this.slice(0,4) == 'rgb(') {
var cols = this.slice(4,this.length-1).split(',');
var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3);
} else {
if(this.slice(0,1) == '#') {
if(this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase();
if(this.length==7) color = this.toLowerCase();
}
}
return(color.length==7 ? color : (arguments[0] || this));
}
/*--------------------------------------------------------------------------*/
Element.collectTextNodes = function(element) {
return $A($(element).childNodes).collect( function(node) {
return (node.nodeType==3 ? node.nodeValue :
(node.hasChildNodes() ? Element.collectTextNodes(node) : ''));
}).flatten().join('');
}
Element.collectTextNodesIgnoreClass = function(element, className) {
return $A($(element).childNodes).collect( function(node) {
return (node.nodeType==3 ? node.nodeValue :
((node.hasChildNodes() && !Element.hasClassName(node,className)) ?
Element.collectTextNodesIgnoreClass(node, className) : ''));
}).flatten().join('');
}
Element.setContentZoom = function(element, percent) {
element = $(element);
Element.setStyle(element, {fontSize: (percent/100) + 'em'});
if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0);
}
Element.getOpacity = function(element){
var opacity;
if (opacity = Element.getStyle(element, 'opacity'))
return parseFloat(opacity);
if (opacity = (Element.getStyle(element, 'filter') || '').match(/alpha\(opacity=(.*)\)/))
if(opacity[1]) return parseFloat(opacity[1]) / 100;
return 1.0;
}
Element.setOpacity = function(element, value){
element= $(element);
if (value == 1){
Element.setStyle(element, { opacity:
(/Gecko/.test(navigator.userAgent) && !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ?
0.999999 : null });
if(/MSIE/.test(navigator.userAgent))
Element.setStyle(element, {filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'')});
} else {
if(value < 0.00001) value = 0;
Element.setStyle(element, {opacity: value});
if(/MSIE/.test(navigator.userAgent))
Element.setStyle(element,
{ filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'') +
'alpha(opacity='+value*100+')' });
}
}
Element.getInlineOpacity = function(element){
return $(element).style.opacity || '';
}
Element.childrenWithClassName = function(element, className, findFirst) {
var classNameRegExp = new RegExp("(^|\\s)" + className + "(\\s|$)");
var results = $A($(element).getElementsByTagName('*'))[findFirst ? 'detect' : 'select']( function(c) {
return (c.className && c.className.match(classNameRegExp));
});
if(!results) results = [];
return results;
}
Element.forceRerendering = function(element) {
try {
element = $(element);
var n = document.createTextNode(' ');
element.appendChild(n);
element.removeChild(n);
} catch(e) { }
};
/*--------------------------------------------------------------------------*/
Array.prototype.call = function() {
var args = arguments;
this.each(function(f){ f.apply(this, args) });
}
/*--------------------------------------------------------------------------*/
var Effect = {
tagifyText: function(element) {
var tagifyStyle = 'position:relative';
if(/MSIE/.test(navigator.userAgent)) tagifyStyle += ';zoom:1';
element = $(element);
$A(element.childNodes).each( function(child) {
if(child.nodeType==3) {
child.nodeValue.toArray().each( function(character) {
element.insertBefore(
Builder.node('span',{style: tagifyStyle},
character == ' ' ? String.fromCharCode(160) : character),
child);
});
Element.remove(child);
}
});
},
multiple: function(element, effect) {
var elements;
if(((typeof element == 'object') ||
(typeof element == 'function')) &&
(element.length))
elements = element;
else
elements = $(element).childNodes;
var options = Object.extend({
speed: 0.1,
delay: 0.0
}, arguments[2] || {});
var masterDelay = options.delay;
$A(elements).each( function(element, index) {
new effect(element, Object.extend(options, { delay: index * options.speed + masterDelay }));
});
},
PAIRS: {
'slide': ['SlideDown','SlideUp'],
'blind': ['BlindDown','BlindUp'],
'appear': ['Appear','Fade']
},
toggle: function(element, effect) {
element = $(element);
effect = (effect || 'appear').toLowerCase();
var options = Object.extend({
queue: { position:'end', scope:(element.id || 'global'), limit: 1 }
}, arguments[2] || {});
Effect[element.visible() ?
Effect.PAIRS[effect][1] : Effect.PAIRS[effect][0]](element, options);
}
};
var Effect2 = Effect; // deprecated
/* ------------- transitions ------------- */
Effect.Transitions = {}
Effect.Transitions.linear = function(pos) {
return pos;
}
Effect.Transitions.sinoidal = function(pos) {
return (-Math.cos(pos*Math.PI)/2) + 0.5;
}
Effect.Transitions.reverse = function(pos) {
return 1-pos;
}
Effect.Transitions.flicker = function(pos) {
return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4;
}
Effect.Transitions.wobble = function(pos) {
return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5;
}
Effect.Transitions.pulse = function(pos) {
return (Math.floor(pos*10) % 2 == 0 ?
(pos*10-Math.floor(pos*10)) : 1-(pos*10-Math.floor(pos*10)));
}
Effect.Transitions.none = function(pos) {
return 0;
}
Effect.Transitions.full = function(pos) {
return 1;
}
/* ------------- core effects ------------- */
Effect.ScopedQueue = Class.create();
Object.extend(Object.extend(Effect.ScopedQueue.prototype, Enumerable), {
initialize: function() {
this.effects = [];
this.interval = null;
},
_each: function(iterator) {
this.effects._each(iterator);
},
add: function(effect) {
var timestamp = new Date().getTime();
var position = (typeof effect.options.queue == 'string') ?
effect.options.queue : effect.options.queue.position;
switch(position) {
case 'front':
// move unstarted effects after this effect
this.effects.findAll(function(e){ return e.state=='idle' }).each( function(e) {
e.startOn += effect.finishOn;
e.finishOn += effect.finishOn;
});
break;
case 'end':
// start effect after last queued effect has finished
timestamp = this.effects.pluck('finishOn').max() || timestamp;
break;
}
effect.startOn += timestamp;
effect.finishOn += timestamp;
if(!effect.options.queue.limit || (this.effects.length < effect.options.queue.limit))
this.effects.push(effect);
if(!this.interval)
this.interval = setInterval(this.loop.bind(this), 40);
},
remove: function(effect) {
this.effects = this.effects.reject(function(e) { return e==effect });
if(this.effects.length == 0) {
clearInterval(this.interval);
this.interval = null;
}
},
loop: function() {
var timePos = new Date().getTime();
this.effects.invoke('loop', timePos);
}
});
Effect.Queues = {
instances: $H(),
get: function(queueName) {
if(typeof queueName != 'string') return queueName;
if(!this.instances[queueName])
this.instances[queueName] = new Effect.ScopedQueue();
return this.instances[queueName];
}
}
Effect.Queue = Effect.Queues.get('global');
Effect.DefaultOptions = {
transition: Effect.Transitions.sinoidal,
duration: 1.0, // seconds
fps: 25.0, // max. 25fps due to Effect.Queue implementation
sync: false, // true for combining
from: 0.0,
to: 1.0,
delay: 0.0,
queue: 'parallel'
}
Effect.Base = function() {};
Effect.Base.prototype = {
position: null,
start: function(options) {
this.options = Object.extend(Object.extend({},Effect.DefaultOptions), options || {});
this.currentFrame = 0;
this.state = 'idle';
this.startOn = this.options.delay*1000;
this.finishOn = this.startOn + (this.options.duration*1000);
this.event('beforeStart');
if(!this.options.sync)
Effect.Queues.get(typeof this.options.queue == 'string' ?
'global' : this.options.queue.scope).add(this);
},
loop: function(timePos) {
if(timePos >= this.startOn) {
if(timePos >= this.finishOn) {
this.render(1.0);
this.cancel();
this.event('beforeFinish');
if(this.finish) this.finish();
this.event('afterFinish');
return;
}
var pos = (timePos - this.startOn) / (this.finishOn - this.startOn);
var frame = Math.round(pos * this.options.fps * this.options.duration);
if(frame > this.currentFrame) {
this.render(pos);
this.currentFrame = frame;
}
}
},
render: function(pos) {
if(this.state == 'idle') {
this.state = 'running';
this.event('beforeSetup');
if(this.setup) this.setup();
this.event('afterSetup');
}
if(this.state == 'running') {
if(this.options.transition) pos = this.options.transition(pos);
pos *= (this.options.to-this.options.from);
pos += this.options.from;
this.position = pos;
this.event('beforeUpdate');
if(this.update) this.update(pos);
this.event('afterUpdate');
}
},
cancel: function() {
if(!this.options.sync)
Effect.Queues.get(typeof this.options.queue == 'string' ?
'global' : this.options.queue.scope).remove(this);
this.state = 'finished';
},
event: function(eventName) {
if(this.options[eventName + 'Internal']) this.options[eventName + 'Internal'](this);
if(this.options[eventName]) this.options[eventName](this);
},
inspect: function() {
return '#<Effect:' + $H(this).inspect() + ',options:' + $H(this.options).inspect() + '>';
}
}
Effect.Parallel = Class.create();
Object.extend(Object.extend(Effect.Parallel.prototype, Effect.Base.prototype), {
initialize: function(effects) {
this.effects = effects || [];
this.start(arguments[1]);
},
update: function(position) {
this.effects.invoke('render', position);
},
finish: function(position) {
this.effects.each( function(effect) {
effect.render(1.0);
effect.cancel();
effect.event('beforeFinish');
if(effect.finish) effect.finish(position);
effect.event('afterFinish');
});
}
});
Effect.Opacity = Class.create();
Object.extend(Object.extend(Effect.Opacity.prototype, Effect.Base.prototype), {
initialize: function(element) {
this.element = $(element);
// make this work on IE on elements without 'layout'
if(/MSIE/.test(navigator.userAgent) && (!this.element.hasLayout))
this.element.setStyle({zoom: 1});
var options = Object.extend({
from: this.element.getOpacity() || 0.0,
to: 1.0
}, arguments[1] || {});
this.start(options);
},
update: function(position) {
this.element.setOpacity(position);
}
});
Effect.Move = Class.create();
Object.extend(Object.extend(Effect.Move.prototype, Effect.Base.prototype), {
initialize: function(element) {
this.element = $(element);
var options = Object.extend({
x: 0,
y: 0,
mode: 'relative'
}, arguments[1] || {});
this.start(options);
},
setup: function() {
// Bug in Opera: Opera returns the "real" position of a static element or
// relative element that does not have top/left explicitly set.
// ==> Always set top and left for position relative elements in your stylesheets
// (to 0 if you do not need them)
this.element.makePositioned();
this.originalLeft = parseFloat(this.element.getStyle('left') || '0');
this.originalTop = parseFloat(this.element.getStyle('top') || '0');
if(this.options.mode == 'absolute') {
// absolute movement, so we need to calc deltaX and deltaY
this.options.x = this.options.x - this.originalLeft;
this.options.y = this.options.y - this.originalTop;
}
},
update: function(position) {
this.element.setStyle({
left: this.options.x * position + this.originalLeft + 'px',
top: this.options.y * position + this.originalTop + 'px'
});
}
});
// for backwards compatibility
Effect.MoveBy = function(element, toTop, toLeft) {
return new Effect.Move(element,
Object.extend({ x: toLeft, y: toTop }, arguments[3] || {}));
};
Effect.Scale = Class.create();
Object.extend(Object.extend(Effect.Scale.prototype, Effect.Base.prototype), {
initialize: function(element, percent) {
this.element = $(element)
var options = Object.extend({
scaleX: true,
scaleY: true,
scaleContent: true,
scaleFromCenter: false,
scaleMode: 'box', // 'box' or 'contents' or {} with provided values
scaleFrom: 100.0,
scaleTo: percent
}, arguments[2] || {});
this.start(options);
},
setup: function() {
this.restoreAfterFinish = this.options.restoreAfterFinish || false;
this.elementPositioning = this.element.getStyle('position');
this.originalStyle = {};
['top','left','width','height','fontSize'].each( function(k) {
this.originalStyle[k] = this.element.style[k];
}.bind(this));
this.originalTop = this.element.offsetTop;
this.originalLeft = this.element.offsetLeft;
var fontSize = this.element.getStyle('font-size') || '100%';
['em','px','%'].each( function(fontSizeType) {
if(fontSize.indexOf(fontSizeType)>0) {
this.fontSize = parseFloat(fontSize);
this.fontSizeType = fontSizeType;
}
}.bind(this));
this.factor = (this.options.scaleTo - this.options.scaleFrom)/100;
this.dims = null;
if(this.options.scaleMode=='box')
this.dims = [this.element.offsetHeight, this.element.offsetWidth];
if(/^content/.test(this.options.scaleMode))
this.dims = [this.element.scrollHeight, this.element.scrollWidth];
if(!this.dims)
this.dims = [this.options.scaleMode.originalHeight,
this.options.scaleMode.originalWidth];
},
update: function(position) {
var currentScale = (this.options.scaleFrom/100.0) + (this.factor * position);
if(this.options.scaleContent && this.fontSize)
this.element.setStyle({fontSize: this.fontSize * currentScale + this.fontSizeType });
this.setDimensions(this.dims[0] * currentScale, this.dims[1] * currentScale);
},
finish: function(position) {
if (this.restoreAfterFinish) this.element.setStyle(this.originalStyle);
},
setDimensions: function(height, width) {
var d = {};
if(this.options.scaleX) d.width = width + 'px';
if(this.options.scaleY) d.height = height + 'px';
if(this.options.scaleFromCenter) {
var topd = (height - this.dims[0])/2;
var leftd = (width - this.dims[1])/2;
if(this.elementPositioning == 'absolute') {
if(this.options.scaleY) d.top = this.originalTop-topd + 'px';
if(this.options.scaleX) d.left = this.originalLeft-leftd + 'px';
} else {
if(this.options.scaleY) d.top = -topd + 'px';
if(this.options.scaleX) d.left = -leftd + 'px';
}
}
this.element.setStyle(d);
}
});
Effect.Highlight = Class.create();
Object.extend(Object.extend(Effect.Highlight.prototype, Effect.Base.prototype), {
initialize: function(element) {
this.element = $(element);
var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || {});
this.start(options);
},
setup: function() {
// Prevent executing on elements not in the layout flow
if(this.element.getStyle('display')=='none') { this.cancel(); return; }
// Disable background image during the effect
this.oldStyle = {
backgroundImage: this.element.getStyle('background-image') };
this.element.setStyle({backgroundImage: 'none'});
if(!this.options.endcolor)
this.options.endcolor = this.element.getStyle('background-color').parseColor('#ffffff');
if(!this.options.restorecolor)
this.options.restorecolor = this.element.getStyle('background-color');
// init color calculations
this._base = $R(0,2).map(function(i){ return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16) }.bind(this));
this._delta = $R(0,2).map(function(i){ return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i] }.bind(this));
},
update: function(position) {
this.element.setStyle({backgroundColor: $R(0,2).inject('#',function(m,v,i){
return m+(Math.round(this._base[i]+(this._delta[i]*position)).toColorPart()); }.bind(this)) });
},
finish: function() {
this.element.setStyle(Object.extend(this.oldStyle, {
backgroundColor: this.options.restorecolor
}));
}
});
Effect.ScrollTo = Class.create();
Object.extend(Object.extend(Effect.ScrollTo.prototype, Effect.Base.prototype), {
initialize: function(element) {
this.element = $(element);
this.start(arguments[1] || {});
},
setup: function() {
Position.prepare();
var offsets = Position.cumulativeOffset(this.element);
if(this.options.offset) offsets[1] += this.options.offset;
var max = window.innerHeight ?
window.height - window.innerHeight :
document.body.scrollHeight -
(document.documentElement.clientHeight ?
document.documentElement.clientHeight : document.body.clientHeight);
this.scrollStart = Position.deltaY;
this.delta = (offsets[1] > max ? max : offsets[1]) - this.scrollStart;
},
update: function(position) {
Position.prepare();
window.scrollTo(Position.deltaX,
this.scrollStart + (position*this.delta));
}
});
/* ------------- combination effects ------------- */
Effect.Fade = function(element) {
element = $(element);
var oldOpacity = element.getInlineOpacity();
var options = Object.extend({
from: element.getOpacity() || 1.0,
to: 0.0,
afterFinishInternal: function(effect) {
if(effect.options.to!=0) return;
effect.element.hide();
effect.element.setStyle({opacity: oldOpacity});
}}, arguments[1] || {});
return new Effect.Opacity(element,options);
}
Effect.Appear = function(element) {
element = $(element);
var options = Object.extend({
from: (element.getStyle('display') == 'none' ? 0.0 : element.getOpacity() || 0.0),
to: 1.0,
// force Safari to render floated elements properly
afterFinishInternal: function(effect) {
effect.element.forceRerendering();
},
beforeSetup: function(effect) {
effect.element.setOpacity(effect.options.from);
effect.element.show();
}}, arguments[1] || {});
return new Effect.Opacity(element,options);
}
Effect.Puff = function(element) {
element = $(element);
var oldStyle = { opacity: element.getInlineOpacity(), position: element.getStyle('position') };
return new Effect.Parallel(
[ new Effect.Scale(element, 200,
{ sync: true, scaleFromCenter: true, scaleContent: true, restoreAfterFinish: true }),
new Effect.Opacity(element, { sync: true, to: 0.0 } ) ],
Object.extend({ duration: 1.0,
beforeSetupInternal: function(effect) {
effect.effects[0].element.setStyle({position: 'absolute'}); },
afterFinishInternal: function(effect) {
effect.effects[0].element.hide();
effect.effects[0].element.setStyle(oldStyle); }
}, arguments[1] || {})
);
}
Effect.BlindUp = function(element) {
element = $(element);
element.makeClipping();
return new Effect.Scale(element, 0,
Object.extend({ scaleContent: false,
scaleX: false,
restoreAfterFinish: true,
afterFinishInternal: function(effect) {
effect.element.hide();
effect.element.undoClipping();
}
}, arguments[1] || {})
);
}
Effect.BlindDown = function(element) {
element = $(element);
var elementDimensions = element.getDimensions();
return new Effect.Scale(element, 100,
Object.extend({ scaleContent: false,
scaleX: false,
scaleFrom: 0,
scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
restoreAfterFinish: true,
afterSetup: function(effect) {
effect.element.makeClipping();
effect.element.setStyle({height: '0px'});
effect.element.show();
},
afterFinishInternal: function(effect) {
effect.element.undoClipping();
}
}, arguments[1] || {})
);
}
Effect.SwitchOff = function(element) {
element = $(element);
var oldOpacity = element.getInlineOpacity();
return new Effect.Appear(element, {
duration: 0.4,
from: 0,
transition: Effect.Transitions.flicker,
afterFinishInternal: function(effect) {
new Effect.Scale(effect.element, 1, {
duration: 0.3, scaleFromCenter: true,
scaleX: false, scaleContent: false, restoreAfterFinish: true,
beforeSetup: function(effect) {
effect.element.makePositioned();
effect.element.makeClipping();
},
afterFinishInternal: function(effect) {
effect.element.hide();
effect.element.undoClipping();
effect.element.undoPositioned();
effect.element.setStyle({opacity: oldOpacity});
}
})
}
});
}
Effect.DropOut = function(element) {
element = $(element);
var oldStyle = {
top: element.getStyle('top'),
left: element.getStyle('left'),
opacity: element.getInlineOpacity() };
return new Effect.Parallel(
[ new Effect.Move(element, {x: 0, y: 100, sync: true }),
new Effect.Opacity(element, { sync: true, to: 0.0 }) ],
Object.extend(
{ duration: 0.5,
beforeSetup: function(effect) {
effect.effects[0].element.makePositioned();
},
afterFinishInternal: function(effect) {
effect.effects[0].element.hide();
effect.effects[0].element.undoPositioned();
effect.effects[0].element.setStyle(oldStyle);
}
}, arguments[1] || {}));
}
Effect.Shake = function(element) {
element = $(element);
var oldStyle = {
top: element.getStyle('top'),
left: element.getStyle('left') };
return new Effect.Move(element,
{ x: 20, y: 0, duration: 0.05, afterFinishInternal: function(effect) {
new Effect.Move(effect.element,
{ x: -40, y: 0, duration: 0.1, afterFinishInternal: function(effect) {
new Effect.Move(effect.element,
{ x: 40, y: 0, duration: 0.1, afterFinishInternal: function(effect) {
new Effect.Move(effect.element,
{ x: -40, y: 0, duration: 0.1, afterFinishInternal: function(effect) {
new Effect.Move(effect.element,
{ x: 40, y: 0, duration: 0.1, afterFinishInternal: function(effect) {
new Effect.Move(effect.element,
{ x: -20, y: 0, duration: 0.05, afterFinishInternal: function(effect) {
effect.element.undoPositioned();
effect.element.setStyle(oldStyle);
}}) }}) }}) }}) }}) }});
}
Effect.SlideDown = function(element) {
element = $(element);
element.cleanWhitespace();
// SlideDown need to have the content of the element wrapped in a container element with fixed height!
var oldInnerBottom = $(element.firstChild).getStyle('bottom');
var elementDimensions = element.getDimensions();
return new Effect.Scale(element, 100, Object.extend({
scaleContent: false,
scaleX: false,
scaleFrom: window.opera ? 0 : 1,
scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
restoreAfterFinish: true,
afterSetup: function(effect) {
effect.element.makePositioned();
effect.element.firstChild.makePositioned();
if(window.opera) effect.element.setStyle({top: ''});
effect.element.makeClipping();
effect.element.setStyle({height: '0px'});
effect.element.show(); },
afterUpdateInternal: function(effect) {
effect.element.firstChild.setStyle({bottom:
(effect.dims[0] - effect.element.clientHeight) + 'px' });
},
afterFinishInternal: function(effect) {
effect.element.undoClipping();
// IE will crash if child is undoPositioned first
if(/MSIE/.test(navigator.userAgent)){
effect.element.undoPositioned();
effect.element.firstChild.undoPositioned();
}else{
effect.element.firstChild.undoPositioned();
effect.element.undoPositioned();
}
effect.element.firstChild.setStyle({bottom: oldInnerBottom}); }
}, arguments[1] || {})
);
}
Effect.SlideUp = function(element) {
element = $(element);
element.cleanWhitespace();
var oldInnerBottom = $(element.firstChild).getStyle('bottom');
return new Effect.Scale(element, window.opera ? 0 : 1,
Object.extend({ scaleContent: false,
scaleX: false,
scaleMode: 'box',
scaleFrom: 100,
restoreAfterFinish: true,
beforeStartInternal: function(effect) {
effect.element.makePositioned();
effect.element.firstChild.makePositioned();
if(window.opera) effect.element.setStyle({top: ''});
effect.element.makeClipping();
effect.element.show(); },
afterUpdateInternal: function(effect) {
effect.element.firstChild.setStyle({bottom:
(effect.dims[0] - effect.element.clientHeight) + 'px' }); },
afterFinishInternal: function(effect) {
effect.element.hide();
effect.element.undoClipping();
effect.element.firstChild.undoPositioned();
effect.element.undoPositioned();
effect.element.setStyle({bottom: oldInnerBottom}); }
}, arguments[1] || {})
);
}
// Bug in opera makes the TD containing this element expand for a instance after finish
Effect.Squish = function(element) {
return new Effect.Scale(element, window.opera ? 1 : 0,
{ restoreAfterFinish: true,
beforeSetup: function(effect) {
effect.element.makeClipping(effect.element); },
afterFinishInternal: function(effect) {
effect.element.hide(effect.element);
effect.element.undoClipping(effect.element); }
});
}
Effect.Grow = function(element) {
element = $(element);
var options = Object.extend({
direction: 'center',
moveTransition: Effect.Transitions.sinoidal,
scaleTransition: Effect.Transitions.sinoidal,
opacityTransition: Effect.Transitions.full
}, arguments[1] || {});
var oldStyle = {
top: element.style.top,
left: element.style.left,
height: element.style.height,
width: element.style.width,
opacity: element.getInlineOpacity() };
var dims = element.getDimensions();
var initialMoveX, initialMoveY;
var moveX, moveY;
switch (options.direction) {
case 'top-left':
initialMoveX = initialMoveY = moveX = moveY = 0;
break;
case 'top-right':
initialMoveX = dims.width;
initialMoveY = moveY = 0;
moveX = -dims.width;
break;
case 'bottom-left':
initialMoveX = moveX = 0;
initialMoveY = dims.height;
moveY = -dims.height;
break;
case 'bottom-right':
initialMoveX = dims.width;
initialMoveY = dims.height;
moveX = -dims.width;
moveY = -dims.height;
break;
case 'center':
initialMoveX = dims.width / 2;
initialMoveY = dims.height / 2;
moveX = -dims.width / 2;
moveY = -dims.height / 2;
break;
}
return new Effect.Move(element, {
x: initialMoveX,
y: initialMoveY,
duration: 0.01,
beforeSetup: function(effect) {
effect.element.hide();
effect.element.makeClipping();
effect.element.makePositioned();
},
afterFinishInternal: function(effect) {
new Effect.Parallel(
[ new Effect.Opacity(effect.element, { sync: true, to: 1.0, from: 0.0, transition: options.opacityTransition }),
new Effect.Move(effect.element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition }),
new Effect.Scale(effect.element, 100, {
scaleMode: { originalHeight: dims.height, originalWidth: dims.width },
sync: true, scaleFrom: window.opera ? 1 : 0, transition: options.scaleTransition, restoreAfterFinish: true})
], Object.extend({
beforeSetup: function(effect) {
effect.effects[0].element.setStyle({height: '0px'});
effect.effects[0].element.show();
},
afterFinishInternal: function(effect) {
effect.effects[0].element.undoClipping();
effect.effects[0].element.undoPositioned();
effect.effects[0].element.setStyle(oldStyle);
}
}, options)
)
}
});
}
Effect.Shrink = function(element) {
element = $(element);
var options = Object.extend({
direction: 'center',
moveTransition: Effect.Transitions.sinoidal,
scaleTransition: Effect.Transitions.sinoidal,
opacityTransition: Effect.Transitions.none
}, arguments[1] || {});
var oldStyle = {
top: element.style.top,
left: element.style.left,
height: element.style.height,
width: element.style.width,
opacity: element.getInlineOpacity() };
var dims = element.getDimensions();
var moveX, moveY;
switch (options.direction) {
case 'top-left':
moveX = moveY = 0;
break;
case 'top-right':
moveX = dims.width;
moveY = 0;
break;
case 'bottom-left':
moveX = 0;
moveY = dims.height;
break;
case 'bottom-right':
moveX = dims.width;
moveY = dims.height;
break;
case 'center':
moveX = dims.width / 2;
moveY = dims.height / 2;
break;
}
return new Effect.Parallel(
[ new Effect.Opacity(element, { sync: true, to: 0.0, from: 1.0, transition: options.opacityTransition }),
new Effect.Scale(element, window.opera ? 1 : 0, { sync: true, transition: options.scaleTransition, restoreAfterFinish: true}),
new Effect.Move(element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition })
], Object.extend({
beforeStartInternal: function(effect) {
effect.effects[0].element.makePositioned();
effect.effects[0].element.makeClipping(); },
afterFinishInternal: function(effect) {
effect.effects[0].element.hide();
effect.effects[0].element.undoClipping();
effect.effects[0].element.undoPositioned();
effect.effects[0].element.setStyle(oldStyle); }
}, options)
);
}
Effect.Pulsate = function(element) {
element = $(element);
var options = arguments[1] || {};
var oldOpacity = element.getInlineOpacity();
var transition = options.transition || Effect.Transitions.sinoidal;
var reverser = function(pos){ return transition(1-Effect.Transitions.pulse(pos)) };
reverser.bind(transition);
return new Effect.Opacity(element,
Object.extend(Object.extend({ duration: 3.0, from: 0,
afterFinishInternal: function(effect) { effect.element.setStyle({opacity: oldOpacity}); }
}, options), {transition: reverser}));
}
Effect.Fold = function(element) {
element = $(element);
var oldStyle = {
top: element.style.top,
left: element.style.left,
width: element.style.width,
height: element.style.height };
Element.makeClipping(element);
return new Effect.Scale(element, 5, Object.extend({
scaleContent: false,
scaleX: false,
afterFinishInternal: function(effect) {
new Effect.Scale(element, 1, {
scaleContent: false,
scaleY: false,
afterFinishInternal: function(effect) {
effect.element.hide();
effect.element.undoClipping();
effect.element.setStyle(oldStyle);
} });
}}, arguments[1] || {}));
};
['setOpacity','getOpacity','getInlineOpacity','forceRerendering','setContentZoom',
'collectTextNodes','collectTextNodesIgnoreClass','childrenWithClassName'].each(
function(f) { Element.Methods[f] = Element[f]; }
);
Element.Methods.visualEffect = function(element, effect, options) {
s = effect.gsub(/_/, '-').camelize();
effect_class = s.charAt(0).toUpperCase() + s.substring(1);
new Effect[effect_class](element, options);
return $(element);
};
Element.addMethods();

View file

@ -0,0 +1,47 @@
// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
var Scriptaculous = {
Version: '1.6.1',
require: function(libraryName) {
// inserting via DOM fails in Safari 2.0, so brute force approach
document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
},
load: function() {
if((typeof Prototype=='undefined') ||
(typeof Element == 'undefined') ||
(typeof Element.Methods=='undefined') ||
parseFloat(Prototype.Version.split(".")[0] + "." +
Prototype.Version.split(".")[1]) < 1.5)
throw("script.aculo.us requires the Prototype JavaScript framework >= 1.5.0");
$A(document.getElementsByTagName("script")).findAll( function(s) {
return (s.src && s.src.match(/scriptaculous\.js(\?.*)?$/))
}).each( function(s) {
var path = s.src.replace(/scriptaculous\.js(\?.*)?$/,'');
var includes = s.src.match(/\?.*load=([a-z,]*)/);
(includes ? includes[1] : 'builder,effects,dragdrop,controls,slider').split(',').each(
function(include) { Scriptaculous.require(path+include+'.js') });
});
}
}
Scriptaculous.load();

View file

@ -0,0 +1,283 @@
// Copyright (c) 2005 Marty Haught, Thomas Fuchs
//
// See http://script.aculo.us for more info
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
if(!Control) var Control = {};
Control.Slider = Class.create();
// options:
// axis: 'vertical', or 'horizontal' (default)
//
// callbacks:
// onChange(value)
// onSlide(value)
Control.Slider.prototype = {
initialize: function(handle, track, options) {
var slider = this;
if(handle instanceof Array) {
this.handles = handle.collect( function(e) { return $(e) });
} else {
this.handles = [$(handle)];
}
this.track = $(track);
this.options = options || {};
this.axis = this.options.axis || 'horizontal';
this.increment = this.options.increment || 1;
this.step = parseInt(this.options.step || '1');
this.range = this.options.range || $R(0,1);
this.value = 0; // assure backwards compat
this.values = this.handles.map( function() { return 0 });
this.spans = this.options.spans ? this.options.spans.map(function(s){ return $(s) }) : false;
this.options.startSpan = $(this.options.startSpan || null);
this.options.endSpan = $(this.options.endSpan || null);
this.restricted = this.options.restricted || false;
this.maximum = this.options.maximum || this.range.end;
this.minimum = this.options.minimum || this.range.start;
// Will be used to align the handle onto the track, if necessary
this.alignX = parseInt(this.options.alignX || '0');
this.alignY = parseInt(this.options.alignY || '0');
this.trackLength = this.maximumOffset() - this.minimumOffset();
this.handleLength = this.isVertical() ? this.handles[0].offsetHeight : this.handles[0].offsetWidth;
this.active = false;
this.dragging = false;
this.disabled = false;
if(this.options.disabled) this.setDisabled();
// Allowed values array
this.allowedValues = this.options.values ? this.options.values.sortBy(Prototype.K) : false;
if(this.allowedValues) {
this.minimum = this.allowedValues.min();
this.maximum = this.allowedValues.max();
}
this.eventMouseDown = this.startDrag.bindAsEventListener(this);
this.eventMouseUp = this.endDrag.bindAsEventListener(this);
this.eventMouseMove = this.update.bindAsEventListener(this);
// Initialize handles in reverse (make sure first handle is active)
this.handles.each( function(h,i) {
i = slider.handles.length-1-i;
slider.setValue(parseFloat(
(slider.options.sliderValue instanceof Array ?
slider.options.sliderValue[i] : slider.options.sliderValue) ||
slider.range.start), i);
Element.makePositioned(h); // fix IE
Event.observe(h, "mousedown", slider.eventMouseDown);
});
Event.observe(this.track, "mousedown", this.eventMouseDown);
Event.observe(document, "mouseup", this.eventMouseUp);
Event.observe(document, "mousemove", this.eventMouseMove);
this.initialized = true;
},
dispose: function() {
var slider = this;
Event.stopObserving(this.track, "mousedown", this.eventMouseDown);
Event.stopObserving(document, "mouseup", this.eventMouseUp);
Event.stopObserving(document, "mousemove", this.eventMouseMove);
this.handles.each( function(h) {
Event.stopObserving(h, "mousedown", slider.eventMouseDown);
});
},
setDisabled: function(){
this.disabled = true;
},
setEnabled: function(){
this.disabled = false;
},
getNearestValue: function(value){
if(this.allowedValues){
if(value >= this.allowedValues.max()) return(this.allowedValues.max());
if(value <= this.allowedValues.min()) return(this.allowedValues.min());
var offset = Math.abs(this.allowedValues[0] - value);
var newValue = this.allowedValues[0];
this.allowedValues.each( function(v) {
var currentOffset = Math.abs(v - value);
if(currentOffset <= offset){
newValue = v;
offset = currentOffset;
}
});
return newValue;
}
if(value > this.range.end) return this.range.end;
if(value < this.range.start) return this.range.start;
return value;
},
setValue: function(sliderValue, handleIdx){
if(!this.active) {
this.activeHandle = this.handles[handleIdx];
this.activeHandleIdx = handleIdx;
this.updateStyles();
}
handleIdx = handleIdx || this.activeHandleIdx || 0;
if(this.initialized && this.restricted) {
if((handleIdx>0) && (sliderValue<this.values[handleIdx-1]))
sliderValue = this.values[handleIdx-1];
if((handleIdx < (this.handles.length-1)) && (sliderValue>this.values[handleIdx+1]))
sliderValue = this.values[handleIdx+1];
}
sliderValue = this.getNearestValue(sliderValue);
this.values[handleIdx] = sliderValue;
this.value = this.values[0]; // assure backwards compat
this.handles[handleIdx].style[this.isVertical() ? 'top' : 'left'] =
this.translateToPx(sliderValue);
this.drawSpans();
if(!this.dragging || !this.event) this.updateFinished();
},
setValueBy: function(delta, handleIdx) {
this.setValue(this.values[handleIdx || this.activeHandleIdx || 0] + delta,
handleIdx || this.activeHandleIdx || 0);
},
translateToPx: function(value) {
return Math.round(
((this.trackLength-this.handleLength)/(this.range.end-this.range.start)) *
(value - this.range.start)) + "px";
},
translateToValue: function(offset) {
return ((offset/(this.trackLength-this.handleLength) *
(this.range.end-this.range.start)) + this.range.start);
},
getRange: function(range) {
var v = this.values.sortBy(Prototype.K);
range = range || 0;
return $R(v[range],v[range+1]);
},
minimumOffset: function(){
return(this.isVertical() ? this.alignY : this.alignX);
},
maximumOffset: function(){
return(this.isVertical() ?
this.track.offsetHeight - this.alignY : this.track.offsetWidth - this.alignX);
},
isVertical: function(){
return (this.axis == 'vertical');
},
drawSpans: function() {
var slider = this;
if(this.spans)
$R(0, this.spans.length-1).each(function(r) { slider.setSpan(slider.spans[r], slider.getRange(r)) });
if(this.options.startSpan)
this.setSpan(this.options.startSpan,
$R(0, this.values.length>1 ? this.getRange(0).min() : this.value ));
if(this.options.endSpan)
this.setSpan(this.options.endSpan,
$R(this.values.length>1 ? this.getRange(this.spans.length-1).max() : this.value, this.maximum));
},
setSpan: function(span, range) {
if(this.isVertical()) {
span.style.top = this.translateToPx(range.start);
span.style.height = this.translateToPx(range.end - range.start + this.range.start);
} else {
span.style.left = this.translateToPx(range.start);
span.style.width = this.translateToPx(range.end - range.start + this.range.start);
}
},
updateStyles: function() {
this.handles.each( function(h){ Element.removeClassName(h, 'selected') });
Element.addClassName(this.activeHandle, 'selected');
},
startDrag: function(event) {
if(Event.isLeftClick(event)) {
if(!this.disabled){
this.active = true;
var handle = Event.element(event);
var pointer = [Event.pointerX(event), Event.pointerY(event)];
if(handle==this.track) {
var offsets = Position.cumulativeOffset(this.track);
this.event = event;
this.setValue(this.translateToValue(
(this.isVertical() ? pointer[1]-offsets[1] : pointer[0]-offsets[0])-(this.handleLength/2)
));
var offsets = Position.cumulativeOffset(this.activeHandle);
this.offsetX = (pointer[0] - offsets[0]);
this.offsetY = (pointer[1] - offsets[1]);
} else {
// find the handle (prevents issues with Safari)
while((this.handles.indexOf(handle) == -1) && handle.parentNode)
handle = handle.parentNode;
this.activeHandle = handle;
this.activeHandleIdx = this.handles.indexOf(this.activeHandle);
this.updateStyles();
var offsets = Position.cumulativeOffset(this.activeHandle);
this.offsetX = (pointer[0] - offsets[0]);
this.offsetY = (pointer[1] - offsets[1]);
}
}
Event.stop(event);
}
},
update: function(event) {
if(this.active) {
if(!this.dragging) this.dragging = true;
this.draw(event);
// fix AppleWebKit rendering
if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0);
Event.stop(event);
}
},
draw: function(event) {
var pointer = [Event.pointerX(event), Event.pointerY(event)];
var offsets = Position.cumulativeOffset(this.track);
pointer[0] -= this.offsetX + offsets[0];
pointer[1] -= this.offsetY + offsets[1];
this.event = event;
this.setValue(this.translateToValue( this.isVertical() ? pointer[1] : pointer[0] ));
if(this.initialized && this.options.onSlide)
this.options.onSlide(this.values.length>1 ? this.values : this.value, this);
},
endDrag: function(event) {
if(this.active && this.dragging) {
this.finishDrag(event, true);
Event.stop(event);
}
this.active = false;
this.dragging = false;
},
finishDrag: function(event, success) {
this.active = false;
this.dragging = false;
this.updateFinished();
},
updateFinished: function() {
if(this.initialized && this.options.onChange)
this.options.onChange(this.values.length>1 ? this.values : this.value, this);
this.event = null;
}
}

View file

@ -0,0 +1,383 @@
// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
// (c) 2005 Jon Tirsen (http://www.tirsen.com)
// (c) 2005 Michael Schuerig (http://www.schuerig.de/michael/)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// experimental, Firefox-only
Event.simulateMouse = function(element, eventName) {
var options = Object.extend({
pointerX: 0,
pointerY: 0,
buttons: 0
}, arguments[2] || {});
var oEvent = document.createEvent("MouseEvents");
oEvent.initMouseEvent(eventName, true, true, document.defaultView,
options.buttons, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
false, false, false, false, 0, $(element));
if(this.mark) Element.remove(this.mark);
this.mark = document.createElement('div');
this.mark.appendChild(document.createTextNode(" "));
document.body.appendChild(this.mark);
this.mark.style.position = 'absolute';
this.mark.style.top = options.pointerY + "px";
this.mark.style.left = options.pointerX + "px";
this.mark.style.width = "5px";
this.mark.style.height = "5px;";
this.mark.style.borderTop = "1px solid red;"
this.mark.style.borderLeft = "1px solid red;"
if(this.step)
alert('['+new Date().getTime().toString()+'] '+eventName+'/'+Test.Unit.inspect(options));
$(element).dispatchEvent(oEvent);
};
// Note: Due to a fix in Firefox 1.0.5/6 that probably fixed "too much", this doesn't work in 1.0.6 or DP2.
// You need to downgrade to 1.0.4 for now to get this working
// See https://bugzilla.mozilla.org/show_bug.cgi?id=289940 for the fix that fixed too much
Event.simulateKey = function(element, eventName) {
var options = Object.extend({
ctrlKey: false,
altKey: false,
shiftKey: false,
metaKey: false,
keyCode: 0,
charCode: 0
}, arguments[2] || {});
var oEvent = document.createEvent("KeyEvents");
oEvent.initKeyEvent(eventName, true, true, window,
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey,
options.keyCode, options.charCode );
$(element).dispatchEvent(oEvent);
};
Event.simulateKeys = function(element, command) {
for(var i=0; i<command.length; i++) {
Event.simulateKey(element,'keypress',{charCode:command.charCodeAt(i)});
}
};
var Test = {}
Test.Unit = {};
// security exception workaround
Test.Unit.inspect = Object.inspect;
Test.Unit.Logger = Class.create();
Test.Unit.Logger.prototype = {
initialize: function(log) {
this.log = $(log);
if (this.log) {
this._createLogTable();
}
},
start: function(testName) {
if (!this.log) return;
this.testName = testName;
this.lastLogLine = document.createElement('tr');
this.statusCell = document.createElement('td');
this.nameCell = document.createElement('td');
this.nameCell.appendChild(document.createTextNode(testName));
this.messageCell = document.createElement('td');
this.lastLogLine.appendChild(this.statusCell);
this.lastLogLine.appendChild(this.nameCell);
this.lastLogLine.appendChild(this.messageCell);
this.loglines.appendChild(this.lastLogLine);
},
finish: function(status, summary) {
if (!this.log) return;
this.lastLogLine.className = status;
this.statusCell.innerHTML = status;
this.messageCell.innerHTML = this._toHTML(summary);
},
message: function(message) {
if (!this.log) return;
this.messageCell.innerHTML = this._toHTML(message);
},
summary: function(summary) {
if (!this.log) return;
this.logsummary.innerHTML = this._toHTML(summary);
},
_createLogTable: function() {
this.log.innerHTML =
'<div id="logsummary"></div>' +
'<table id="logtable">' +
'<thead><tr><th>Status</th><th>Test</th><th>Message</th></tr></thead>' +
'<tbody id="loglines"></tbody>' +
'</table>';
this.logsummary = $('logsummary')
this.loglines = $('loglines');
},
_toHTML: function(txt) {
return txt.escapeHTML().replace(/\n/g,"<br/>");
}
}
Test.Unit.Runner = Class.create();
Test.Unit.Runner.prototype = {
initialize: function(testcases) {
this.options = Object.extend({
testLog: 'testlog'
}, arguments[1] || {});
this.options.resultsURL = this.parseResultsURLQueryParameter();
if (this.options.testLog) {
this.options.testLog = $(this.options.testLog) || null;
}
if(this.options.tests) {
this.tests = [];
for(var i = 0; i < this.options.tests.length; i++) {
if(/^test/.test(this.options.tests[i])) {
this.tests.push(new Test.Unit.Testcase(this.options.tests[i], testcases[this.options.tests[i]], testcases["setup"], testcases["teardown"]));
}
}
} else {
if (this.options.test) {
this.tests = [new Test.Unit.Testcase(this.options.test, testcases[this.options.test], testcases["setup"], testcases["teardown"])];
} else {
this.tests = [];
for(var testcase in testcases) {
if(/^test/.test(testcase)) {
this.tests.push(new Test.Unit.Testcase(testcase, testcases[testcase], testcases["setup"], testcases["teardown"]));
}
}
}
}
this.currentTest = 0;
this.logger = new Test.Unit.Logger(this.options.testLog);
setTimeout(this.runTests.bind(this), 1000);
},
parseResultsURLQueryParameter: function() {
return window.location.search.parseQuery()["resultsURL"];
},
// Returns:
// "ERROR" if there was an error,
// "FAILURE" if there was a failure, or
// "SUCCESS" if there was neither
getResult: function() {
var hasFailure = false;
for(var i=0;i<this.tests.length;i++) {
if (this.tests[i].errors > 0) {
return "ERROR";
}
if (this.tests[i].failures > 0) {
hasFailure = true;
}
}
if (hasFailure) {
return "FAILURE";
} else {
return "SUCCESS";
}
},
postResults: function() {
if (this.options.resultsURL) {
new Ajax.Request(this.options.resultsURL,
{ method: 'get', parameters: 'result=' + this.getResult(), asynchronous: false });
}
},
runTests: function() {
var test = this.tests[this.currentTest];
if (!test) {
// finished!
this.postResults();
this.logger.summary(this.summary());
return;
}
if(!test.isWaiting) {
this.logger.start(test.name);
}
test.run();
if(test.isWaiting) {
this.logger.message("Waiting for " + test.timeToWait + "ms");
setTimeout(this.runTests.bind(this), test.timeToWait || 1000);
} else {
this.logger.finish(test.status(), test.summary());
this.currentTest++;
// tail recursive, hopefully the browser will skip the stackframe
this.runTests();
}
},
summary: function() {
var assertions = 0;
var failures = 0;
var errors = 0;
var messages = [];
for(var i=0;i<this.tests.length;i++) {
assertions += this.tests[i].assertions;
failures += this.tests[i].failures;
errors += this.tests[i].errors;
}
return (
this.tests.length + " tests, " +
assertions + " assertions, " +
failures + " failures, " +
errors + " errors");
}
}
Test.Unit.Assertions = Class.create();
Test.Unit.Assertions.prototype = {
initialize: function() {
this.assertions = 0;
this.failures = 0;
this.errors = 0;
this.messages = [];
},
summary: function() {
return (
this.assertions + " assertions, " +
this.failures + " failures, " +
this.errors + " errors" + "\n" +
this.messages.join("\n"));
},
pass: function() {
this.assertions++;
},
fail: function(message) {
this.failures++;
this.messages.push("Failure: " + message);
},
info: function(message) {
this.messages.push("Info: " + message);
},
error: function(error) {
this.errors++;
this.messages.push(error.name + ": "+ error.message + "(" + Test.Unit.inspect(error) +")");
},
status: function() {
if (this.failures > 0) return 'failed';
if (this.errors > 0) return 'error';
return 'passed';
},
assert: function(expression) {
var message = arguments[1] || 'assert: got "' + Test.Unit.inspect(expression) + '"';
try { expression ? this.pass() :
this.fail(message); }
catch(e) { this.error(e); }
},
assertEqual: function(expected, actual) {
var message = arguments[2] || "assertEqual";
try { (expected == actual) ? this.pass() :
this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
'", actual "' + Test.Unit.inspect(actual) + '"'); }
catch(e) { this.error(e); }
},
assertEnumEqual: function(expected, actual) {
var message = arguments[2] || "assertEnumEqual";
try { $A(expected).length == $A(actual).length &&
expected.zip(actual).all(function(pair) { return pair[0] == pair[1] }) ?
this.pass() : this.fail(message + ': expected ' + Test.Unit.inspect(expected) +
', actual ' + Test.Unit.inspect(actual)); }
catch(e) { this.error(e); }
},
assertNotEqual: function(expected, actual) {
var message = arguments[2] || "assertNotEqual";
try { (expected != actual) ? this.pass() :
this.fail(message + ': got "' + Test.Unit.inspect(actual) + '"'); }
catch(e) { this.error(e); }
},
assertNull: function(obj) {
var message = arguments[1] || 'assertNull'
try { (obj==null) ? this.pass() :
this.fail(message + ': got "' + Test.Unit.inspect(obj) + '"'); }
catch(e) { this.error(e); }
},
assertHidden: function(element) {
var message = arguments[1] || 'assertHidden';
this.assertEqual("none", element.style.display, message);
},
assertNotNull: function(object) {
var message = arguments[1] || 'assertNotNull';
this.assert(object != null, message);
},
assertInstanceOf: function(expected, actual) {
var message = arguments[2] || 'assertInstanceOf';
try {
(actual instanceof expected) ? this.pass() :
this.fail(message + ": object was not an instance of the expected type"); }
catch(e) { this.error(e); }
},
assertNotInstanceOf: function(expected, actual) {
var message = arguments[2] || 'assertNotInstanceOf';
try {
!(actual instanceof expected) ? this.pass() :
this.fail(message + ": object was an instance of the not expected type"); }
catch(e) { this.error(e); }
},
_isVisible: function(element) {
element = $(element);
if(!element.parentNode) return true;
this.assertNotNull(element);
if(element.style && Element.getStyle(element, 'display') == 'none')
return false;
return this._isVisible(element.parentNode);
},
assertNotVisible: function(element) {
this.assert(!this._isVisible(element), Test.Unit.inspect(element) + " was not hidden and didn't have a hidden parent either. " + ("" || arguments[1]));
},
assertVisible: function(element) {
this.assert(this._isVisible(element), Test.Unit.inspect(element) + " was not visible. " + ("" || arguments[1]));
},
benchmark: function(operation, iterations) {
var startAt = new Date();
(iterations || 1).times(operation);
var timeTaken = ((new Date())-startAt);
this.info((arguments[2] || 'Operation') + ' finished ' +
iterations + ' iterations in ' + (timeTaken/1000)+'s' );
return timeTaken;
}
}
Test.Unit.Testcase = Class.create();
Object.extend(Object.extend(Test.Unit.Testcase.prototype, Test.Unit.Assertions.prototype), {
initialize: function(name, test, setup, teardown) {
Test.Unit.Assertions.prototype.initialize.bind(this)();
this.name = name;
this.test = test || function() {};
this.setup = setup || function() {};
this.teardown = teardown || function() {};
this.isWaiting = false;
this.timeToWait = 1000;
},
wait: function(time, nextPart) {
this.isWaiting = true;
this.test = nextPart;
this.timeToWait = time;
},
run: function() {
try {
try {
if (!this.isWaiting) this.setup.bind(this)();
this.isWaiting = false;
this.test.bind(this)();
} finally {
if(!this.isWaiting) {
this.teardown.bind(this)();
}
}
}
catch(e) { this.error(e); }
}
});

View file

@ -0,0 +1,69 @@
/*
* Copyright 2004 ThoughtWorks, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
elementFindMatchingChildren = function(element, selector) {
var matches = [];
var childCount = element.childNodes.length;
for (var i=0; i<childCount; i++) {
var child = element.childNodes[i];
if (selector(child)) {
matches.push(child);
} else {
childMatches = elementFindMatchingChildren(child, selector);
matches.push(childMatches);
}
}
return matches.flatten();
}
ELEMENT_NODE_TYPE = 1;
elementFindFirstMatchingChild = function(element, selector) {
var childCount = element.childNodes.length;
for (var i=0; i<childCount; i++) {
var child = element.childNodes[i];
if (child.nodeType == ELEMENT_NODE_TYPE) {
if (selector(child)) {
return child;
}
result = elementFindFirstMatchingChild(child, selector);
if (result) {
return result;
}
}
}
return null;
}
elementFindFirstMatchingParent = function(element, selector) {
var current = element.parentNode;
while (current != null) {
if (selector(current)) {
break;
}
current = current.parentNode;
}
return current;
}
elementFindMatchingChildById = function(element, id) {
return elementFindFirstMatchingChild(element, function(element){return element.id==id} );
}

View file

@ -0,0 +1,842 @@
/*
* Copyright 2004 ThoughtWorks, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
// This script contains a badly-organised collection of miscellaneous
// functions that really better homes.
function classCreate() {
return function() {
this.initialize.apply(this, arguments);
}
}
function objectExtend(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
function $() {
var results = [], element;
for (var i = 0; i < arguments.length; i++) {
element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);
results[results.length] = element;
}
return results.length < 2 ? results[0] : results;
}
function $A(iterable) {
if (!iterable) return [];
if (iterable.toArray) {
return iterable.toArray();
} else {
var results = [];
for (var i = 0; i < iterable.length; i++)
results.push(iterable[i]);
return results;
}
}
function fnBind() {
var args = $A(arguments), __method = args.shift(), object = args.shift();
var retval = function() {
return __method.apply(object, args.concat($A(arguments)));
}
retval.__method = __method;
return retval;
}
function fnBindAsEventListener(fn, object) {
var __method = fn;
return function(event) {
return __method.call(object, event || window.event);
}
}
function removeClassName(element, name) {
var re = new RegExp("\\b" + name + "\\b", "g");
element.className = element.className.replace(re, "");
}
function addClassName(element, name) {
element.className = element.className + ' ' + name;
}
function elementSetStyle(element, style) {
for (var name in style) {
var value = style[name];
if (value == null) value = "";
element.style[name] = value;
}
}
function elementGetStyle(element, style) {
var value = element.style[style];
if (!value) {
if (document.defaultView && document.defaultView.getComputedStyle) {
var css = document.defaultView.getComputedStyle(element, null);
value = css ? css.getPropertyValue(style) : null;
} else if (element.currentStyle) {
value = element.currentStyle[style];
}
}
/** DGF necessary?
if (window.opera && ['left', 'top', 'right', 'bottom'].include(style))
if (Element.getStyle(element, 'position') == 'static') value = 'auto'; */
return value == 'auto' ? null : value;
}
String.prototype.trim = function() {
var result = this.replace(/^\s+/g, "");
// strip leading
return result.replace(/\s+$/g, "");
// strip trailing
};
String.prototype.lcfirst = function() {
return this.charAt(0).toLowerCase() + this.substr(1);
};
String.prototype.ucfirst = function() {
return this.charAt(0).toUpperCase() + this.substr(1);
};
String.prototype.startsWith = function(str) {
return this.indexOf(str) == 0;
};
// Returns the text in this element
function getText(element) {
var text = "";
var isRecentFirefox = (browserVersion.isFirefox && browserVersion.firefoxVersion >= "1.5");
if (isRecentFirefox || browserVersion.isKonqueror || browserVersion.isSafari || browserVersion.isOpera) {
text = getTextContent(element);
} else if (element.textContent) {
text = element.textContent;
} else if (element.innerText) {
text = element.innerText;
}
text = normalizeNewlines(text);
text = normalizeSpaces(text);
return text.trim();
}
function getTextContent(element, preformatted) {
if (element.nodeType == 3 /*Node.TEXT_NODE*/) {
var text = element.data;
if (!preformatted) {
text = text.replace(/\n|\r|\t/g, " ");
}
return text;
}
if (element.nodeType == 1 /*Node.ELEMENT_NODE*/) {
var childrenPreformatted = preformatted || (element.tagName == "PRE");
var text = "";
for (var i = 0; i < element.childNodes.length; i++) {
var child = element.childNodes.item(i);
text += getTextContent(child, childrenPreformatted);
}
// Handle block elements that introduce newlines
// -- From HTML spec:
//<!ENTITY % block
// "P | %heading; | %list; | %preformatted; | DL | DIV | NOSCRIPT |
// BLOCKQUOTE | F:wORM | HR | TABLE | FIELDSET | ADDRESS">
//
// TODO: should potentially introduce multiple newlines to separate blocks
if (element.tagName == "P" || element.tagName == "BR" || element.tagName == "HR" || element.tagName == "DIV") {
text += "\n";
}
return text;
}
return '';
}
/**
* Convert all newlines to \m
*/
function normalizeNewlines(text)
{
return text.replace(/\r\n|\r/g, "\n");
}
/**
* Replace multiple sequential spaces with a single space, and then convert &nbsp; to space.
*/
function normalizeSpaces(text)
{
// IE has already done this conversion, so doing it again will remove multiple nbsp
if (browserVersion.isIE)
{
return text;
}
// Replace multiple spaces with a single space
// TODO - this shouldn't occur inside PRE elements
text = text.replace(/\ +/g, " ");
// Replace &nbsp; with a space
var nbspPattern = new RegExp(String.fromCharCode(160), "g");
if (browserVersion.isSafari) {
return replaceAll(text, String.fromCharCode(160), " ");
} else {
return text.replace(nbspPattern, " ");
}
}
function replaceAll(text, oldText, newText) {
while (text.indexOf(oldText) != -1) {
text = text.replace(oldText, newText);
}
return text;
}
function xmlDecode(text) {
text = text.replace(/&quot;/g, '"');
text = text.replace(/&apos;/g, "'");
text = text.replace(/&lt;/g, "<");
text = text.replace(/&gt;/g, ">");
text = text.replace(/&amp;/g, "&");
return text;
}
// Sets the text in this element
function setText(element, text) {
if (element.textContent != null) {
element.textContent = text;
} else if (element.innerText != null) {
element.innerText = text;
}
}
// Get the value of an <input> element
function getInputValue(inputElement) {
if (inputElement.type) {
if (inputElement.type.toUpperCase() == 'CHECKBOX' ||
inputElement.type.toUpperCase() == 'RADIO')
{
return (inputElement.checked ? 'on' : 'off');
}
}
if (inputElement.value == null) {
throw new SeleniumError("This element has no value; is it really a form field?");
}
return inputElement.value;
}
/* Fire an event in a browser-compatible manner */
function triggerEvent(element, eventType, canBubble, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown) {
canBubble = (typeof(canBubble) == undefined) ? true : canBubble;
if (element.fireEvent) {
var evt = createEventObject(element, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown);
element.fireEvent('on' + eventType, evt);
}
else {
var evt = document.createEvent('HTMLEvents');
try {
evt.shiftKey = shiftKeyDown;
evt.metaKey = metaKeyDown;
evt.altKey = altKeyDown;
evt.ctrlKey = controlKeyDown;
} catch (e) {
// On Firefox 1.0, you can only set these during initMouseEvent or initKeyEvent
// we'll have to ignore them here
LOG.exception(e);
}
evt.initEvent(eventType, canBubble, true);
element.dispatchEvent(evt);
}
}
function getKeyCodeFromKeySequence(keySequence) {
var match = /^\\(\d{1,3})$/.exec(keySequence);
if (match != null) {
return match[1];
}
match = /^.$/.exec(keySequence);
if (match != null) {
return match[0].charCodeAt(0);
}
// this is for backward compatibility with existing tests
// 1 digit ascii codes will break however because they are used for the digit chars
match = /^\d{2,3}$/.exec(keySequence);
if (match != null) {
return match[0];
}
throw new SeleniumError("invalid keySequence");
}
function createEventObject(element, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown) {
var evt = element.ownerDocument.createEventObject();
evt.shiftKey = shiftKeyDown;
evt.metaKey = metaKeyDown;
evt.altKey = altKeyDown;
evt.ctrlKey = controlKeyDown;
return evt;
}
function triggerKeyEvent(element, eventType, keySequence, canBubble, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown) {
var keycode = getKeyCodeFromKeySequence(keySequence);
canBubble = (typeof(canBubble) == undefined) ? true : canBubble;
if (element.fireEvent) {
var keyEvent = createEventObject(element, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown);
keyEvent.keyCode = keycode;
element.fireEvent('on' + eventType, keyEvent);
}
else {
var evt;
if (window.KeyEvent) {
evt = document.createEvent('KeyEvents');
evt.initKeyEvent(eventType, true, true, window, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown, keycode, keycode);
} else {
evt = document.createEvent('UIEvents');
evt.shiftKey = shiftKeyDown;
evt.metaKey = metaKeyDown;
evt.altKey = altKeyDown;
evt.ctrlKey = controlKeyDown;
evt.initUIEvent(eventType, true, true, window, 1);
evt.keyCode = keycode;
evt.which = keycode;
}
element.dispatchEvent(evt);
}
}
function removeLoadListener(element, command) {
LOG.info('Removing loadListenter for ' + element + ', ' + command);
if (window.removeEventListener)
element.removeEventListener("load", command, true);
else if (window.detachEvent)
element.detachEvent("onload", command);
}
function addLoadListener(element, command) {
LOG.info('Adding loadListenter for ' + element + ', ' + command);
var augmentedCommand = function() {
command.call(this, element);
}
if (window.addEventListener && !browserVersion.isOpera)
element.addEventListener("load", augmentedCommand, true);
else if (window.attachEvent)
element.attachEvent("onload", augmentedCommand);
}
/**
* Override the broken getFunctionName() method from JsUnit
* This file must be loaded _after_ the jsunitCore.js
*/
function getFunctionName(aFunction) {
var regexpResult = aFunction.toString().match(/function (\w*)/);
if (regexpResult && regexpResult[1]) {
return regexpResult[1];
}
return 'anonymous';
}
function getDocumentBase(doc) {
var bases = document.getElementsByTagName("base");
if (bases && bases.length && bases[0].href) {
return bases[0].href;
}
return "";
}
function getTagName(element) {
var tagName;
if (element && element.tagName && element.tagName.toLowerCase) {
tagName = element.tagName.toLowerCase();
}
return tagName;
}
function absolutify(url, baseUrl) {
/** returns a relative url in its absolute form, given by baseUrl.
*
* This function is a little odd, because it can take baseUrls that
* aren't necessarily directories. It uses the same rules as the HTML
* &lt;base&gt; tag; if the baseUrl doesn't end with "/", we'll assume
* that it points to a file, and strip the filename off to find its
* base directory.
*
* So absolutify("foo", "http://x/bar") will return "http://x/foo" (stripping off bar),
* whereas absolutify("foo", "http://x/bar/") will return "http://x/bar/foo" (preserving bar).
* Naturally absolutify("foo", "http://x") will return "http://x/foo", appropriately.
*
* @param url the url to make absolute; if this url is already absolute, we'll just return that, unchanged
* @param baseUrl the baseUrl from which we'll absolutify, following the rules above.
* @return 'url' if it was already absolute, or the absolutized version of url if it was not absolute.
*/
// DGF isn't there some library we could use for this?
if (/^\w+:/.test(url)) {
// it's already absolute
return url;
}
var loc;
try {
loc = parseUrl(baseUrl);
} catch (e) {
// is it an absolute windows file path? let's play the hero in that case
if (/^\w:\\/.test(baseUrl)) {
baseUrl = "file:///" + baseUrl.replace(/\\/g, "/");
loc = parseUrl(baseUrl);
} else {
throw new SeleniumError("baseUrl wasn't absolute: " + baseUrl);
}
}
loc.search = null;
loc.hash = null;
// if url begins with /, then that's the whole pathname
if (/^\//.test(url)) {
loc.pathname = url;
var result = reassembleLocation(loc);
return result;
}
// if pathname is null, then we'll just append "/" + the url
if (!loc.pathname) {
loc.pathname = "/" + url;
var result = reassembleLocation(loc);
return result;
}
// if pathname ends with /, just append url
if (/\/$/.test(loc.pathname)) {
loc.pathname += url;
var result = reassembleLocation(loc);
return result;
}
// if we're here, then the baseUrl has a pathname, but it doesn't end with /
// in that case, we replace everything after the final / with the relative url
loc.pathname = loc.pathname.replace(/[^\/\\]+$/, url);
var result = reassembleLocation(loc);
return result;
}
var URL_REGEX = /^((\w+):\/\/)(([^:]+):?([^@]+)?@)?([^\/\?:]*):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(.+)?/;
function parseUrl(url) {
var fields = ['url', null, 'protocol', null, 'username', 'password', 'host', 'port', 'pathname', 'search', 'hash'];
var result = URL_REGEX.exec(url);
if (!result) {
throw new SeleniumError("Invalid URL: " + url);
}
var loc = new Object();
for (var i = 0; i < fields.length; i++) {
var field = fields[i];
if (field == null) {
continue;
}
loc[field] = result[i];
}
return loc;
}
function reassembleLocation(loc) {
if (!loc.protocol) {
throw new Error("Not a valid location object: " + o2s(loc));
}
var protocol = loc.protocol;
protocol = protocol.replace(/:$/, "");
var url = protocol + "://";
if (loc.username) {
url += loc.username;
if (loc.password) {
url += ":" + loc.password;
}
url += "@";
}
if (loc.host) {
url += loc.host;
}
if (loc.port) {
url += ":" + loc.port;
}
if (loc.pathname) {
url += loc.pathname;
}
if (loc.search) {
url += "?" + loc.search;
}
if (loc.hash) {
var hash = loc.hash;
hash = loc.hash.replace(/^#/, "");
url += "#" + hash;
}
return url;
}
function canonicalize(url) {
var tempLink = window.document.createElement("link");
tempLink.href = url; // this will canonicalize the href
return tempLink.href;
}
function extractExceptionMessage(ex) {
if (ex == null) return "null exception";
if (ex.message != null) return ex.message;
if (ex.toString && ex.toString() != null) return ex.toString();
}
function describe(object, delimiter) {
var props = new Array();
for (var prop in object) {
try {
props.push(prop + " -> " + object[prop]);
} catch (e) {
props.push(prop + " -> [htmlutils: ack! couldn't read this property! (Permission Denied?)]");
}
}
return props.join(delimiter || '\n');
}
var PatternMatcher = function(pattern) {
this.selectStrategy(pattern);
};
PatternMatcher.prototype = {
selectStrategy: function(pattern) {
this.pattern = pattern;
var strategyName = 'glob';
// by default
if (/^([a-z-]+):(.*)/.test(pattern)) {
var possibleNewStrategyName = RegExp.$1;
var possibleNewPattern = RegExp.$2;
if (PatternMatcher.strategies[possibleNewStrategyName]) {
strategyName = possibleNewStrategyName;
pattern = possibleNewPattern;
}
}
var matchStrategy = PatternMatcher.strategies[strategyName];
if (!matchStrategy) {
throw new SeleniumError("cannot find PatternMatcher.strategies." + strategyName);
}
this.strategy = matchStrategy;
this.matcher = new matchStrategy(pattern);
},
matches: function(actual) {
return this.matcher.matches(actual + '');
// Note: appending an empty string avoids a Konqueror bug
}
};
/**
* A "static" convenience method for easy matching
*/
PatternMatcher.matches = function(pattern, actual) {
return new PatternMatcher(pattern).matches(actual);
};
PatternMatcher.strategies = {
/**
* Exact matching, e.g. "exact:***"
*/
exact: function(expected) {
this.expected = expected;
this.matches = function(actual) {
return actual == this.expected;
};
},
/**
* Match by regular expression, e.g. "regexp:^[0-9]+$"
*/
regexp: function(regexpString) {
this.regexp = new RegExp(regexpString);
this.matches = function(actual) {
return this.regexp.test(actual);
};
},
regex: function(regexpString) {
this.regexp = new RegExp(regexpString);
this.matches = function(actual) {
return this.regexp.test(actual);
};
},
/**
* "globContains" (aka "wildmat") patterns, e.g. "glob:one,two,*",
* but don't require a perfect match; instead succeed if actual
* contains something that matches globString.
* Making this distinction is motivated by a bug in IE6 which
* leads to the browser hanging if we implement *TextPresent tests
* by just matching against a regular expression beginning and
* ending with ".*". The globcontains strategy allows us to satisfy
* the functional needs of the *TextPresent ops more efficiently
* and so avoid running into this IE6 freeze.
*/
globContains: function(globString) {
this.regexp = new RegExp(PatternMatcher.regexpFromGlobContains(globString));
this.matches = function(actual) {
return this.regexp.test(actual);
};
},
/**
* "glob" (aka "wildmat") patterns, e.g. "glob:one,two,*"
*/
glob: function(globString) {
this.regexp = new RegExp(PatternMatcher.regexpFromGlob(globString));
this.matches = function(actual) {
return this.regexp.test(actual);
};
}
};
PatternMatcher.convertGlobMetaCharsToRegexpMetaChars = function(glob) {
var re = glob;
re = re.replace(/([.^$+(){}\[\]\\|])/g, "\\$1");
re = re.replace(/\?/g, "(.|[\r\n])");
re = re.replace(/\*/g, "(.|[\r\n])*");
return re;
};
PatternMatcher.regexpFromGlobContains = function(globContains) {
return PatternMatcher.convertGlobMetaCharsToRegexpMetaChars(globContains);
};
PatternMatcher.regexpFromGlob = function(glob) {
return "^" + PatternMatcher.convertGlobMetaCharsToRegexpMetaChars(glob) + "$";
};
var Assert = {
fail: function(message) {
throw new AssertionFailedError(message);
},
/*
* Assert.equals(comment?, expected, actual)
*/
equals: function() {
var args = new AssertionArguments(arguments);
if (args.expected === args.actual) {
return;
}
Assert.fail(args.comment +
"Expected '" + args.expected +
"' but was '" + args.actual + "'");
},
/*
* Assert.matches(comment?, pattern, actual)
*/
matches: function() {
var args = new AssertionArguments(arguments);
if (PatternMatcher.matches(args.expected, args.actual)) {
return;
}
Assert.fail(args.comment +
"Actual value '" + args.actual +
"' did not match '" + args.expected + "'");
},
/*
* Assert.notMtches(comment?, pattern, actual)
*/
notMatches: function() {
var args = new AssertionArguments(arguments);
if (!PatternMatcher.matches(args.expected, args.actual)) {
return;
}
Assert.fail(args.comment +
"Actual value '" + args.actual +
"' did match '" + args.expected + "'");
}
};
// Preprocess the arguments to allow for an optional comment.
function AssertionArguments(args) {
if (args.length == 2) {
this.comment = "";
this.expected = args[0];
this.actual = args[1];
} else {
this.comment = args[0] + "; ";
this.expected = args[1];
this.actual = args[2];
}
}
function AssertionFailedError(message) {
this.isAssertionFailedError = true;
this.isSeleniumError = true;
this.message = message;
this.failureMessage = message;
}
function SeleniumError(message) {
var error = new Error(message);
error.isSeleniumError = true;
return error;
}
function highlight(element) {
var highLightColor = "yellow";
if (element.originalColor == undefined) { // avoid picking up highlight
element.originalColor = elementGetStyle(element, "background-color");
}
elementSetStyle(element, {"backgroundColor" : highLightColor});
window.setTimeout(function() {
try {
//if element is orphan, probably page of it has already gone, so ignore
if (!element.parentNode) {
return;
}
elementSetStyle(element, {"backgroundColor" : element.originalColor});
} catch (e) {} // DGF unhighlighting is very dangerous and low priority
}, 200);
}
// for use from vs.2003 debugger
function o2s(obj) {
var s = "";
for (key in obj) {
var line = key + "->" + obj[key];
line.replace("\n", " ");
s += line + "\n";
}
return s;
}
var seenReadyStateWarning = false;
function openSeparateApplicationWindow(url, suppressMozillaWarning) {
// resize the Selenium window itself
window.resizeTo(1200, 500);
window.moveTo(window.screenX, 0);
var appWindow = window.open(url + '?start=true', 'main');
try {
var windowHeight = 500;
if (window.outerHeight) {
windowHeight = window.outerHeight;
} else if (document.documentElement && document.documentElement.offsetHeight) {
windowHeight = document.documentElement.offsetHeight;
}
if (window.screenLeft && !window.screenX) window.screenX = window.screenLeft;
if (window.screenTop && !window.screenY) window.screenY = window.screenTop;
appWindow.resizeTo(1200, screen.availHeight - windowHeight - 60);
appWindow.moveTo(window.screenX, window.screenY + windowHeight + 25);
} catch (e) {
LOG.error("Couldn't resize app window");
LOG.exception(e);
}
if (!suppressMozillaWarning && window.document.readyState == null && !seenReadyStateWarning) {
alert("Beware! Mozilla bug 300992 means that we can't always reliably detect when a new page has loaded. Install the Selenium IDE extension or the readyState extension available from selenium.openqa.org to make page load detection more reliable.");
seenReadyStateWarning = true;
}
return appWindow;
}
var URLConfiguration = classCreate();
objectExtend(URLConfiguration.prototype, {
initialize: function() {
},
_isQueryParameterTrue: function (name) {
var parameterValue = this._getQueryParameter(name);
if (parameterValue == null) return false;
if (parameterValue.toLowerCase() == "true") return true;
if (parameterValue.toLowerCase() == "on") return true;
return false;
},
_getQueryParameter: function(searchKey) {
var str = this.queryString
if (str == null) return null;
var clauses = str.split('&');
for (var i = 0; i < clauses.length; i++) {
var keyValuePair = clauses[i].split('=', 2);
var key = unescape(keyValuePair[0]);
if (key == searchKey) {
return unescape(keyValuePair[1]);
}
}
return null;
},
_extractArgs: function() {
var str = SeleniumHTARunner.commandLine;
if (str == null || str == "") return new Array();
var matches = str.match(/(?:\"([^\"]+)\"|(?!\"([^\"]+)\")(\S+))/g);
// We either want non quote stuff ([^"]+) surrounded by quotes
// or we want to look-ahead, see that the next character isn't
// a quoted argument, and then grab all the non-space stuff
// this will return for the line: "foo" bar
// the results "\"foo\"" and "bar"
// So, let's unquote the quoted arguments:
var args = new Array;
for (var i = 0; i < matches.length; i++) {
args[i] = matches[i];
args[i] = args[i].replace(/^"(.*)"$/, "$1");
}
return args;
},
isMultiWindowMode:function() {
return this._isQueryParameterTrue('multiWindow');
},
getBaseUrl:function() {
return this._getQueryParameter('baseUrl');
}
});
function safeScrollIntoView(element) {
if (element.scrollIntoView) {
element.scrollIntoView(false);
return;
}
// TODO: work out how to scroll browsers that don't support
// scrollIntoView (like Konqueror)
}

View file

@ -0,0 +1,79 @@
<script language="JavaScript">
if (window["selenium_has_been_loaded_into_this_window"]==null)
{
__SELENIUM_JS__
// Some background on the code below: broadly speaking, where we are relative to other windows
// when running in proxy injection mode depends on whether we are in a frame set file or not.
//
// In regular HTML files, the selenium JavaScript is injected into an iframe called "selenium"
// in order to reduce its impact on the JavaScript environment (through namespace pollution,
// etc.). So in regular HTML files, we need to look at the parent of the current window when we want
// a handle to, e.g., the application window.
//
// In frame set files, we can't use an iframe, so we put the JavaScript in the head element and share
// the window with the frame set. So in this case, we need to look at the current window, not the
// parent when looking for, e.g., the application window. (TODO: Perhaps I should have just
// assigned a regular frame for selenium?)
//
BrowserBot.prototype.getContentWindow = function() {
if (window["seleniumInSameWindow"] != null) return window;
return window.parent;
};
BrowserBot.prototype.getTargetWindow = function(windowName) {
if (window["seleniumInSameWindow"] != null) return window;
return window.parent;
};
BrowserBot.prototype.getCurrentWindow = function() {
if (window["seleniumInSameWindow"] != null) return window;
return window.parent;
};
LOG.openLogWindow = function(message, className) {
// disable for now
};
BrowserBot.prototype.relayToRC = function(name) {
var object = eval(name);
var s = 'state:' + serializeObject(name, object) + "\n";
sendToRC(s,"state=true");
}
BrowserBot.prototype.relayBotToRC = function(s) {
this.relayToRC("selenium." + s);
}
function selenium_frameRunTest(oldOnLoadRoutine) {
if (oldOnLoadRoutine) {
eval(oldOnLoadRoutine);
}
runSeleniumTest();
}
function seleniumOnLoad() {
injectedSessionId = @SESSION_ID@;
window["selenium_has_been_loaded_into_this_window"] = true;
runSeleniumTest();
}
function seleniumOnUnload() {
sendToRC("OK"); // just in case some poor PI server thread is waiting for a response
}
if (window.addEventListener) {
window.addEventListener("load", seleniumOnLoad, false); // firefox
window.addEventListener("unload", seleniumOnUnload, false); // firefox
} else if (window.attachEvent){
window.attachEvent("onload", seleniumOnLoad); // IE
window.attachEvent("onunload", seleniumOnUnload); // IE
}
else {
throw "causing a JavaScript error to tell the world that I did not arrange to be run on load";
}
injectedSessionId = @SESSION_ID@;
}
</script>

View file

@ -0,0 +1,7 @@
<script language="JavaScript">
// Ideally I would avoid polluting the namespace by enclosing this snippet with
// curly braces, but I want to make it easy to look at what URL I used for anyone
// who is interested in looking into http://jira.openqa.org/browse/SRC-101:
var _sel_url_ = "http://" + location.host + "/selenium-server/core/scripts/injection.html";
document.write('<iframe name="selenium" width=0 height=0 id="selenium" src="' + _sel_url_ + '"></iframe>');
</script>

View file

@ -0,0 +1,70 @@
/*
This is an experiment in using the Narcissus JavaScript engine
to allow Selenium scripts to be written in plain JavaScript.
The 'jsparse' function will compile each high level block into a Selenium table script.
TODO:
1) Test! (More browsers, more sample scripts)
2) Stepping and walking lower levels of the parse tree
3) Calling Selenium commands directly from JavaScript
4) Do we want comments to appear in the TestRunner?
5) Fix context so variables don't have to be global
For now, variables defined with "var" won't be found
if used later on in a script.
6) Fix formatting
*/
function jsparse() {
var script = document.getElementById('sejs')
var fname = 'javascript script';
parse_result = parse(script.text, fname, 0);
var x2 = new ExecutionContext(GLOBAL_CODE);
ExecutionContext.current = x2;
var new_test_source = '';
var new_line = '';
for (i=0;i<parse_result.$length;i++){
var the_start = parse_result[i].start;
var the_end;
if ( i == (parse_result.$length-1)) {
the_end = parse_result.tokenizer.source.length;
} else {
the_end = parse_result[i+1].start;
}
var script_fragment = parse_result.tokenizer.source.slice(the_start,the_end)
new_line = '<tr><td style="display:none;" class="js">getEval</td>' +
'<td style="display:none;">currentTest.doNextCommand()</td>' +
'<td style="white-space: pre;">' + script_fragment + '</td>' +
'<td></td></tr>\n';
new_test_source += new_line;
//eval(script_fragment);
};
execute(parse_result,x2)
// Create HTML Table
body = document.body
body.innerHTML += "<table class='selenium' id='se-js-table'>"+
"<tbody>" +
"<tr><td>// " + document.title + "</td></tr>" +
new_test_source +
"</tbody" +
"</table>";
//body.innerHTML = "<pre>" + parse_result + "</pre>"
}

View file

@ -0,0 +1,175 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Narcissus JavaScript engine.
*
* The Initial Developer of the Original Code is
* Brendan Eich <brendan@mozilla.org>.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Narcissus - JS implemented in JS.
*
* Well-known constants and lookup tables. Many consts are generated from the
* tokens table via eval to minimize redundancy, so consumers must be compiled
* separately to take advantage of the simple switch-case constant propagation
* done by SpiderMonkey.
*/
// jrh
//module('JS.Defs');
GLOBAL = this;
var tokens = [
// End of source.
"END",
// Operators and punctuators. Some pair-wise order matters, e.g. (+, -)
// and (UNARY_PLUS, UNARY_MINUS).
"\n", ";",
",",
"=",
"?", ":", "CONDITIONAL",
"||",
"&&",
"|",
"^",
"&",
"==", "!=", "===", "!==",
"<", "<=", ">=", ">",
"<<", ">>", ">>>",
"+", "-",
"*", "/", "%",
"!", "~", "UNARY_PLUS", "UNARY_MINUS",
"++", "--",
".",
"[", "]",
"{", "}",
"(", ")",
// Nonterminal tree node type codes.
"SCRIPT", "BLOCK", "LABEL", "FOR_IN", "CALL", "NEW_WITH_ARGS", "INDEX",
"ARRAY_INIT", "OBJECT_INIT", "PROPERTY_INIT", "GETTER", "SETTER",
"GROUP", "LIST",
// Terminals.
"IDENTIFIER", "NUMBER", "STRING", "REGEXP",
// Keywords.
"break",
"case", "catch", "const", "continue",
"debugger", "default", "delete", "do",
"else", "enum",
"false", "finally", "for", "function",
"if", "in", "instanceof",
"new", "null",
"return",
"switch",
"this", "throw", "true", "try", "typeof",
"var", "void",
"while", "with",
// Extensions
"require", "bless", "mixin", "import"
];
// Operator and punctuator mapping from token to tree node type name.
// NB: superstring tokens (e.g., ++) must come before their substring token
// counterparts (+ in the example), so that the opRegExp regular expression
// synthesized from this list makes the longest possible match.
var opTypeNames = {
'\n': "NEWLINE",
';': "SEMICOLON",
',': "COMMA",
'?': "HOOK",
':': "COLON",
'||': "OR",
'&&': "AND",
'|': "BITWISE_OR",
'^': "BITWISE_XOR",
'&': "BITWISE_AND",
'===': "STRICT_EQ",
'==': "EQ",
'=': "ASSIGN",
'!==': "STRICT_NE",
'!=': "NE",
'<<': "LSH",
'<=': "LE",
'<': "LT",
'>>>': "URSH",
'>>': "RSH",
'>=': "GE",
'>': "GT",
'++': "INCREMENT",
'--': "DECREMENT",
'+': "PLUS",
'-': "MINUS",
'*': "MUL",
'/': "DIV",
'%': "MOD",
'!': "NOT",
'~': "BITWISE_NOT",
'.': "DOT",
'[': "LEFT_BRACKET",
']': "RIGHT_BRACKET",
'{': "LEFT_CURLY",
'}': "RIGHT_CURLY",
'(': "LEFT_PAREN",
')': "RIGHT_PAREN"
};
// Hash of keyword identifier to tokens index. NB: we must null __proto__ to
// avoid toString, etc. namespace pollution.
var keywords = {__proto__: null};
// Define const END, etc., based on the token names. Also map name to index.
var consts = " ";
for (var i = 0, j = tokens.length; i < j; i++) {
if (i > 0)
consts += "; ";
var t = tokens[i];
if (/^[a-z]/.test(t)) {
consts += t.toUpperCase();
keywords[t] = i;
} else {
consts += (/^\W/.test(t) ? opTypeNames[t] : t);
}
consts += " = " + i;
tokens[t] = i;
}
eval(consts + ";");
// Map assignment operators to their indexes in the tokens array.
var assignOps = ['|', '^', '&', '<<', '>>', '>>>', '+', '-', '*', '/', '%'];
for (i = 0, j = assignOps.length; i < j; i++) {
t = assignOps[i];
assignOps[t] = tokens[t];
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,63 @@
/*
This is an experiment in creating a "selenese" parser that drastically
cuts down on the line noise associated with writing tests in HTML.
The 'parse' function will accept the follow sample commands.
test-cases:
//comment
command "param"
command "param" // comment
command "param" "param2"
command "param" "param2" // this is a comment
TODO:
1) Deal with multiline parameters
2) Escape quotes properly
3) Determine whether this should/will become the "preferred" syntax
for delivered Selenium self-test scripts
*/
function separse(doc) {
// Get object
script = doc.getElementById('testcase')
// Split into lines
lines = script.text.split('\n');
var command_pattern = / *(\w+) *"([^"]*)" *(?:"([^"]*)"){0,1}(?: *(\/\/ *.+))*/i;
var comment_pattern = /^ *(\/\/ *.+)/
// Regex each line into selenium command and convert into table row.
// eg. "<command> <quote> <quote> <comment>"
var new_test_source = '';
var new_line = '';
for (var x=0; x < lines.length; x++) {
result = lines[x].match(command_pattern);
if (result != null) {
new_line = "<tr><td>" + (result[1] || '&nbsp;') + "</td>" +
"<td>" + (result[2] || '&nbsp;') + "</td>" +
"<td>" + (result[3] || '&nbsp;') + "</td>" +
"<td>" + (result[4] || '&nbsp;') + "</td></tr>\n";
new_test_source += new_line;
}
result = lines[x].match(comment_pattern);
if (result != null) {
new_line = '<tr><td rowspan="1" colspan="4">' +
(result[1] || '&nbsp;') +
'</td></tr>';
new_test_source += new_line;
}
}
// Create HTML Table
body = doc.body
body.innerHTML += "<table class='selenium' id='testtable'>"+
new_test_source +
"</table>";
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,142 @@
/*
* Copyright 2004 ThoughtWorks, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
// Although it's generally better web development practice not to use
// browser-detection (feature detection is better), the subtle browser
// differences that Selenium has to work around seem to make it
// necessary. Maybe as we learn more about what we need, we can do this in
// a more "feature-centric" rather than "browser-centric" way.
var BrowserVersion = function() {
this.name = navigator.appName;
if (window.opera != null) {
this.browser = BrowserVersion.OPERA;
this.isOpera = true;
return;
}
var _getQueryParameter = function(searchKey) {
var str = location.search.substr(1);
if (str == null) return null;
var clauses = str.split('&');
for (var i = 0; i < clauses.length; i++) {
var keyValuePair = clauses[i].split('=', 2);
var key = unescape(keyValuePair[0]);
if (key == searchKey) {
return unescape(keyValuePair[1]);
}
}
return null;
};
var self = this;
var checkChrome = function() {
var loc = window.document.location.href;
try {
loc = window.top.document.location.href;
if (/^chrome:\/\//.test(loc)) {
self.isChrome = true;
} else {
self.isChrome = false;
}
} catch (e) {
// can't see the top (that means we might be chrome, but it's impossible to be sure)
self.isChromeDetectable = "no, top location couldn't be read in this window";
if (_getQueryParameter('thisIsChrome')) {
self.isChrome = true;
} else {
self.isChrome = false;
}
}
}
if (this.name == "Microsoft Internet Explorer") {
this.browser = BrowserVersion.IE;
this.isIE = true;
try {
if (window.top.SeleniumHTARunner && window.top.document.location.pathname.match(/.hta$/i)) {
this.isHTA = true;
}
} catch (e) {
this.isHTADetectable = "no, top location couldn't be read in this window";
if (_getQueryParameter('thisIsHTA')) {
self.isHTA = true;
} else {
self.isHTA = false;
}
}
if ("0" == navigator.appMinorVersion) {
this.preSV1 = true;
if (navigator.appVersion.match(/MSIE 6.0/)) {
this.appearsToBeBrokenInitialIE6 = true;
}
}
return;
}
if (navigator.userAgent.indexOf('Safari') != -1) {
this.browser = BrowserVersion.SAFARI;
this.isSafari = true;
this.khtml = true;
return;
}
if (navigator.userAgent.indexOf('Konqueror') != -1) {
this.browser = BrowserVersion.KONQUEROR;
this.isKonqueror = true;
this.khtml = true;
return;
}
if (navigator.userAgent.indexOf('Firefox') != -1) {
this.browser = BrowserVersion.FIREFOX;
this.isFirefox = true;
this.isGecko = true;
var result = /.*Firefox\/([\d\.]+).*/.exec(navigator.userAgent);
if (result) {
this.firefoxVersion = result[1];
}
checkChrome();
return;
}
if (navigator.userAgent.indexOf('Gecko') != -1) {
this.browser = BrowserVersion.MOZILLA;
this.isMozilla = true;
this.isGecko = true;
checkChrome();
return;
}
this.browser = BrowserVersion.UNKNOWN;
}
BrowserVersion.OPERA = "Opera";
BrowserVersion.IE = "IE";
BrowserVersion.KONQUEROR = "Konqueror";
BrowserVersion.SAFARI = "Safari";
BrowserVersion.FIREFOX = "Firefox";
BrowserVersion.MOZILLA = "Mozilla";
BrowserVersion.UNKNOWN = "Unknown";
var browserVersion = new BrowserVersion();

View file

@ -0,0 +1,375 @@
/*
* Copyright 2004 ThoughtWorks, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// A naming convention used in this file:
//
//
// - a "seleniumApi" is an instance of the Selenium object, defined in selenium-api.js.
//
// - a "Method" is an unbound function whose target must be supplied when it's called, ie.
// it should be invoked using Function.call() or Function.apply()
//
// - a "Block" is a function that has been bound to a target object, so can be called invoked directly
// (or with a null target)
//
// - "CommandHandler" is effectively an abstract base for
// various handlers including ActionHandler, AccessorHandler and AssertHandler.
// Subclasses need to implement an execute(seleniumApi, command) function,
// where seleniumApi is the Selenium object, and command a SeleniumCommand object.
//
// - Handlers will return a "result" object (ActionResult, AccessorResult, AssertResult).
// ActionResults may contain a .terminationCondition function which is run by
// -executionloop.js after the command is run; we'll run it over and over again
// until it returns true or the .terminationCondition throws an exception.
// AccessorResults will contain the results of running getter (e.g. getTitle returns
// the title as a string).
var CommandHandlerFactory = classCreate();
objectExtend(CommandHandlerFactory.prototype, {
initialize: function() {
this.handlers = {};
},
registerAction: function(name, actionBlock, wait, dontCheckAlertsAndConfirms) {
this.handlers[name] = new ActionHandler(actionBlock, wait, dontCheckAlertsAndConfirms);
},
registerAccessor: function(name, accessBlock) {
this.handlers[name] = new AccessorHandler(accessBlock);
},
registerAssert: function(name, assertBlock, haltOnFailure) {
this.handlers[name] = new AssertHandler(assertBlock, haltOnFailure);
},
getCommandHandler: function(name) {
return this.handlers[name];
},
_registerAllAccessors: function(seleniumApi) {
// Methods of the form getFoo(target) result in commands:
// getFoo, assertFoo, verifyFoo, assertNotFoo, verifyNotFoo
// storeFoo, waitForFoo, and waitForNotFoo.
for (var functionName in seleniumApi) {
var match = /^(get|is)([A-Z].+)$/.exec(functionName);
if (match) {
var accessMethod = seleniumApi[functionName];
var accessBlock = fnBind(accessMethod, seleniumApi);
var baseName = match[2];
var isBoolean = (match[1] == "is");
var requiresTarget = (accessMethod.length == 1);
this.registerAccessor(functionName, accessBlock);
this._registerStoreCommandForAccessor(baseName, accessBlock, requiresTarget);
var predicateBlock = this._predicateForAccessor(accessBlock, requiresTarget, isBoolean);
this._registerAssertionsForPredicate(baseName, predicateBlock);
this._registerWaitForCommandsForPredicate(seleniumApi, baseName, predicateBlock);
}
}
},
_registerAllActions: function(seleniumApi) {
for (var functionName in seleniumApi) {
var match = /^do([A-Z].+)$/.exec(functionName);
if (match) {
var actionName = match[1].lcfirst();
var actionMethod = seleniumApi[functionName];
var dontCheckPopups = actionMethod.dontCheckAlertsAndConfirms;
var actionBlock = fnBind(actionMethod, seleniumApi);
this.registerAction(actionName, actionBlock, false, dontCheckPopups);
this.registerAction(actionName + "AndWait", actionBlock, true, dontCheckPopups);
}
}
},
_registerAllAsserts: function(seleniumApi) {
for (var functionName in seleniumApi) {
var match = /^assert([A-Z].+)$/.exec(functionName);
if (match) {
var assertBlock = fnBind(seleniumApi[functionName], seleniumApi);
// Register the assert with the "assert" prefix, and halt on failure.
var assertName = functionName;
this.registerAssert(assertName, assertBlock, true);
// Register the assert with the "verify" prefix, and do not halt on failure.
var verifyName = "verify" + match[1];
this.registerAssert(verifyName, assertBlock, false);
}
}
},
registerAll: function(seleniumApi) {
this._registerAllAccessors(seleniumApi);
this._registerAllActions(seleniumApi);
this._registerAllAsserts(seleniumApi);
},
_predicateForAccessor: function(accessBlock, requiresTarget, isBoolean) {
if (isBoolean) {
return this._predicateForBooleanAccessor(accessBlock);
}
if (requiresTarget) {
return this._predicateForSingleArgAccessor(accessBlock);
}
return this._predicateForNoArgAccessor(accessBlock);
},
_predicateForSingleArgAccessor: function(accessBlock) {
// Given an accessor function getBlah(target),
// return a "predicate" equivalient to isBlah(target, value) that
// is true when the value returned by the accessor matches the specified value.
return function(target, value) {
var accessorResult = accessBlock(target);
if (PatternMatcher.matches(value, accessorResult)) {
return new PredicateResult(true, "Actual value '" + accessorResult + "' did match '" + value + "'");
} else {
return new PredicateResult(false, "Actual value '" + accessorResult + "' did not match '" + value + "'");
}
};
},
_predicateForNoArgAccessor: function(accessBlock) {
// Given a (no-arg) accessor function getBlah(),
// return a "predicate" equivalient to isBlah(value) that
// is true when the value returned by the accessor matches the specified value.
return function(value) {
var accessorResult = accessBlock();
if (PatternMatcher.matches(value, accessorResult)) {
return new PredicateResult(true, "Actual value '" + accessorResult + "' did match '" + value + "'");
} else {
return new PredicateResult(false, "Actual value '" + accessorResult + "' did not match '" + value + "'");
}
};
},
_predicateForBooleanAccessor: function(accessBlock) {
// Given a boolean accessor function isBlah(),
// return a "predicate" equivalient to isBlah() that
// returns an appropriate PredicateResult value.
return function() {
var accessorResult;
if (arguments.length > 2) throw new SeleniumError("Too many arguments! " + arguments.length);
if (arguments.length == 2) {
accessorResult = accessBlock(arguments[0], arguments[1]);
} else if (arguments.length == 1) {
accessorResult = accessBlock(arguments[0]);
} else {
accessorResult = accessBlock();
}
if (accessorResult) {
return new PredicateResult(true, "true");
} else {
return new PredicateResult(false, "false");
}
};
},
_invertPredicate: function(predicateBlock) {
// Given a predicate, return the negation of that predicate.
// Leaves the message unchanged.
// Used to create assertNot, verifyNot, and waitForNot commands.
return function(target, value) {
var result = predicateBlock(target, value);
result.isTrue = !result.isTrue;
return result;
};
},
createAssertionFromPredicate: function(predicateBlock) {
// Convert an isBlahBlah(target, value) function into an assertBlahBlah(target, value) function.
return function(target, value) {
var result = predicateBlock(target, value);
if (!result.isTrue) {
Assert.fail(result.message);
}
};
},
_invertPredicateName: function(baseName) {
var matchResult = /^(.*)Present$/.exec(baseName);
if (matchResult != null) {
return matchResult[1] + "NotPresent";
}
return "Not" + baseName;
},
_registerAssertionsForPredicate: function(baseName, predicateBlock) {
// Register an assertion, a verification, a negative assertion,
// and a negative verification based on the specified accessor.
var assertBlock = this.createAssertionFromPredicate(predicateBlock);
this.registerAssert("assert" + baseName, assertBlock, true);
this.registerAssert("verify" + baseName, assertBlock, false);
var invertedPredicateBlock = this._invertPredicate(predicateBlock);
var negativeassertBlock = this.createAssertionFromPredicate(invertedPredicateBlock);
this.registerAssert("assert" + this._invertPredicateName(baseName), negativeassertBlock, true);
this.registerAssert("verify" + this._invertPredicateName(baseName), negativeassertBlock, false);
},
_waitForActionForPredicate: function(predicateBlock) {
// Convert an isBlahBlah(target, value) function into a waitForBlahBlah(target, value) function.
return function(target, value) {
var terminationCondition = function () {
try {
return predicateBlock(target, value).isTrue;
} catch (e) {
// Treat exceptions as meaning the condition is not yet met.
// Useful, for example, for waitForValue when the element has
// not even been created yet.
// TODO: possibly should rethrow some types of exception.
return false;
}
};
return Selenium.decorateFunctionWithTimeout(terminationCondition, this.defaultTimeout);
};
},
_registerWaitForCommandsForPredicate: function(seleniumApi, baseName, predicateBlock) {
// Register a waitForBlahBlah and waitForNotBlahBlah based on the specified accessor.
var waitForActionMethod = this._waitForActionForPredicate(predicateBlock);
var waitForActionBlock = fnBind(waitForActionMethod, seleniumApi);
var invertedPredicateBlock = this._invertPredicate(predicateBlock);
var waitForNotActionMethod = this._waitForActionForPredicate(invertedPredicateBlock);
var waitForNotActionBlock = fnBind(waitForNotActionMethod, seleniumApi);
this.registerAction("waitFor" + baseName, waitForActionBlock, false, true);
this.registerAction("waitFor" + this._invertPredicateName(baseName), waitForNotActionBlock, false, true);
//TODO decide remove "waitForNot.*Present" action name or not
//for the back compatiblity issues we still make waitForNot.*Present availble
this.registerAction("waitForNot" + baseName, waitForNotActionBlock, false, true);
},
_registerStoreCommandForAccessor: function(baseName, accessBlock, requiresTarget) {
var action;
if (requiresTarget) {
action = function(target, varName) {
storedVars[varName] = accessBlock(target);
};
} else {
action = function(varName) {
storedVars[varName] = accessBlock();
};
}
this.registerAction("store" + baseName, action, false, true);
}
});
function PredicateResult(isTrue, message) {
this.isTrue = isTrue;
this.message = message;
}
// NOTE: The CommandHandler is effectively an abstract base for
// various handlers including ActionHandler, AccessorHandler and AssertHandler.
// Subclasses need to implement an execute(seleniumApi, command) function,
// where seleniumApi is the Selenium object, and command a SeleniumCommand object.
function CommandHandler(type, haltOnFailure) {
this.type = type;
this.haltOnFailure = haltOnFailure;
}
// An ActionHandler is a command handler that executes the sepcified action,
// possibly checking for alerts and confirmations (if checkAlerts is set), and
// possibly waiting for a page load if wait is set.
function ActionHandler(actionBlock, wait, dontCheckAlerts) {
this.actionBlock = actionBlock;
CommandHandler.call(this, "action", true);
if (wait) {
this.wait = true;
}
// note that dontCheckAlerts could be undefined!!!
this.checkAlerts = (dontCheckAlerts) ? false : true;
}
ActionHandler.prototype = new CommandHandler;
ActionHandler.prototype.execute = function(seleniumApi, command) {
if (this.checkAlerts && (null == /(Alert|Confirmation)(Not)?Present/.exec(command.command))) {
// todo: this conditional logic is ugly
seleniumApi.ensureNoUnhandledPopups();
}
var terminationCondition = this.actionBlock(command.target, command.value);
// If the handler didn't return a wait flag, check to see if the
// handler was registered with the wait flag.
if (terminationCondition == undefined && this.wait) {
terminationCondition = seleniumApi.makePageLoadCondition();
}
return new ActionResult(terminationCondition);
};
function ActionResult(terminationCondition) {
this.terminationCondition = terminationCondition;
}
function AccessorHandler(accessBlock) {
this.accessBlock = accessBlock;
CommandHandler.call(this, "accessor", true);
}
AccessorHandler.prototype = new CommandHandler;
AccessorHandler.prototype.execute = function(seleniumApi, command) {
var returnValue = this.accessBlock(command.target, command.value);
return new AccessorResult(returnValue);
};
function AccessorResult(result) {
this.result = result;
}
/**
* Handler for assertions and verifications.
*/
function AssertHandler(assertBlock, haltOnFailure) {
this.assertBlock = assertBlock;
CommandHandler.call(this, "assert", haltOnFailure || false);
}
AssertHandler.prototype = new CommandHandler;
AssertHandler.prototype.execute = function(seleniumApi, command) {
var result = new AssertResult();
try {
this.assertBlock(command.target, command.value);
} catch (e) {
// If this is not a AssertionFailedError, or we should haltOnFailure, rethrow.
if (!e.isAssertionFailedError) {
throw e;
}
if (this.haltOnFailure) {
var error = new SeleniumError(e.failureMessage);
throw error;
}
result.setFailed(e.failureMessage);
}
return result;
};
function AssertResult() {
this.passed = true;
}
AssertResult.prototype.setFailed = function(message) {
this.passed = null;
this.failed = true;
this.failureMessage = message;
}
function SeleniumCommand(command, target, value, isBreakpoint) {
this.command = command;
this.target = target;
this.value = value;
this.isBreakpoint = isBreakpoint;
}

View file

@ -0,0 +1,177 @@
/*
* Copyright 2004 ThoughtWorks, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function TestLoop(commandFactory) {
this.commandFactory = commandFactory;
}
TestLoop.prototype = {
start : function() {
selenium.reset();
LOG.debug("currentTest.start()");
this.continueTest();
},
continueTest : function() {
/**
* Select the next command and continue the test.
*/
LOG.debug("currentTest.continueTest() - acquire the next command");
if (! this.aborted) {
this.currentCommand = this.nextCommand();
}
if (! this.requiresCallBack) {
this.continueTestAtCurrentCommand();
} // otherwise, just finish and let the callback invoke continueTestAtCurrentCommand()
},
continueTestAtCurrentCommand : function() {
LOG.debug("currentTest.continueTestAtCurrentCommand()");
if (this.currentCommand) {
// TODO: rename commandStarted to commandSelected, OR roll it into nextCommand
this.commandStarted(this.currentCommand);
this._resumeAfterDelay();
} else {
this._testComplete();
}
},
_resumeAfterDelay : function() {
/**
* Pause, then execute the current command.
*/
// Get the command delay. If a pauseInterval is set, use it once
// and reset it. Otherwise, use the defined command-interval.
var delay = this.pauseInterval || this.getCommandInterval();
this.pauseInterval = undefined;
if (this.currentCommand.isBreakpoint || delay < 0) {
// Pause: enable the "next/continue" button
this.pause();
} else {
window.setTimeout(fnBind(this.resume, this), delay);
}
},
resume: function() {
/**
* Select the next command and continue the test.
*/
LOG.debug("currentTest.resume() - actually execute");
try {
selenium.browserbot.runScheduledPollers();
this._executeCurrentCommand();
this.continueTestWhenConditionIsTrue();
} catch (e) {
if (!this._handleCommandError(e)) {
this._testComplete();
} else {
this.continueTest();
}
}
},
_testComplete : function() {
selenium.ensureNoUnhandledPopups();
this.testComplete();
},
_executeCurrentCommand : function() {
/**
* Execute the current command.
*
* @return a function which will be used to determine when
* execution can continue, or null if we can continue immediately
*/
var command = this.currentCommand;
LOG.info("Executing: |" + command.command + " | " + command.target + " | " + command.value + " |");
var handler = this.commandFactory.getCommandHandler(command.command);
if (handler == null) {
throw new SeleniumError("Unknown command: '" + command.command + "'");
}
command.target = selenium.preprocessParameter(command.target);
command.value = selenium.preprocessParameter(command.value);
LOG.debug("Command found, going to execute " + command.command);
this.result = handler.execute(selenium, command);
this.waitForCondition = this.result.terminationCondition;
},
_handleCommandError : function(e) {
if (!e.isSeleniumError) {
LOG.exception(e);
var msg = "Selenium failure. Please report to selenium-dev@openqa.org, with error details from the log window.";
if (e.message) {
msg += " The error message is: " + e.message;
}
return this.commandError(msg);
} else {
LOG.error(e.message);
return this.commandError(e.message);
}
},
continueTestWhenConditionIsTrue: function () {
/**
* Busy wait for waitForCondition() to become true, and then carry
* on with test. Fail the current test if there's a timeout or an
* exception.
*/
//LOG.debug("currentTest.continueTestWhenConditionIsTrue()");
selenium.browserbot.runScheduledPollers();
try {
if (this.waitForCondition == null) {
LOG.debug("null condition; let's continueTest()");
LOG.debug("Command complete");
this.commandComplete(this.result);
this.continueTest();
} else if (this.waitForCondition()) {
LOG.debug("condition satisfied; let's continueTest()");
this.waitForCondition = null;
LOG.debug("Command complete");
this.commandComplete(this.result);
this.continueTest();
} else {
//LOG.debug("waitForCondition was false; keep waiting!");
window.setTimeout(fnBind(this.continueTestWhenConditionIsTrue, this), 10);
}
} catch (e) {
this.result = {};
this.result.failed = true;
this.result.failureMessage = extractExceptionMessage(e);
this.commandComplete(this.result);
this.continueTest();
}
},
pause : function() {},
nextCommand : function() {},
commandStarted : function() {},
commandComplete : function() {},
commandError : function() {},
testComplete : function() {},
getCommandInterval : function() {
return 0;
}
}

View file

@ -0,0 +1,139 @@
/*
* Copyright 2004 ThoughtWorks, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var Logger = function() {
this.logWindow = null;
}
Logger.prototype = {
pendingMessages: new Array(),
setLogLevelThreshold: function(logLevel) {
this.pendingLogLevelThreshold = logLevel;
this.show();
// NOTE: log messages will be discarded until the log window is
// fully loaded.
},
getLogWindow: function() {
if (this.logWindow && this.logWindow.closed) {
this.logWindow = null;
}
if (this.logWindow && this.pendingLogLevelThreshold && this.logWindow.setThresholdLevel) {
this.logWindow.setThresholdLevel(this.pendingLogLevelThreshold);
// can't just directly log because that action would loop back
// to this code infinitely
var pendingMessage = new LogMessage("info", "Log level programmatically set to " + this.pendingLogLevelThreshold + " (presumably by driven-mode test code)");
this.pendingMessages.push(pendingMessage);
this.pendingLogLevelThreshold = null; // let's only go this way one time
}
return this.logWindow;
},
openLogWindow: function() {
this.logWindow = window.open(
getDocumentBase(document) + "SeleniumLog.html", "SeleniumLog",
"width=600,height=1000,bottom=0,right=0,status,scrollbars,resizable"
);
this.logWindow.moveTo(window.screenX + 1210, window.screenY + window.outerHeight - 1400);
if (browserVersion.appearsToBeBrokenInitialIE6) {
// I would really prefer for the message to immediately appear in the log window, the instant the user requests that the log window be
// visible. But when I initially coded it this way, thou message simply didn't appear unless I stepped through the code with a debugger.
// So obviously there is some timing issue here which I don't have the patience to figure out.
var pendingMessage = new LogMessage("warn", "You appear to be running an unpatched IE 6, which is not stable and can crash due to memory problems. We recommend you run Windows update to install a more stable version of IE.");
this.pendingMessages.push(pendingMessage);
}
return this.logWindow;
},
show: function() {
if (! this.getLogWindow()) {
this.openLogWindow();
}
setTimeout(function(){LOG.info("Log window displayed");}, 500);
},
logHook: function(className, message) {
},
log: function(className, message) {
var logWindow = this.getLogWindow();
this.logHook(className, message);
if (logWindow) {
if (logWindow.append) {
if (this.pendingMessages.length > 0) {
logWindow.append("info: Appending missed logging messages", "info");
while (this.pendingMessages.length > 0) {
var msg = this.pendingMessages.shift();
logWindow.append(msg.type + ": " + msg.msg, msg.type);
}
logWindow.append("info: Done appending missed logging messages", "info");
}
logWindow.append(className + ": " + message, className);
}
} else {
// uncomment this to turn on background logging
/* these logging messages are never flushed, which creates
an enormous array of strings that never stops growing. Only
turn this on if you need it for debugging! */
//this.pendingMessages.push(new LogMessage(className, message));
}
},
close: function(message) {
if (this.logWindow != null) {
try {
this.logWindow.close();
} catch (e) {
// swallow exception
// the window is probably closed if we get an exception here
}
this.logWindow = null;
}
},
debug: function(message) {
this.log("debug", message);
},
info: function(message) {
this.log("info", message);
},
warn: function(message) {
this.log("warn", message);
},
error: function(message) {
this.log("error", message);
},
exception: function(exception) {
this.error("Unexpected Exception: " + extractExceptionMessage(exception));
this.error("Exception details: " + describe(exception, ', '));
}
};
var LOG = new Logger();
var LogMessage = function(type, msg) {
this.type = type;
this.msg = msg;
}

View file

@ -0,0 +1,466 @@
/*
* Copyright 2005 ThoughtWorks, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
passColor = "#cfffcf";
failColor = "#ffcfcf";
errorColor = "#ffffff";
workingColor = "#DEE7EC";
doneColor = "#FFFFCC";
var injectedSessionId;
var cmd1 = document.createElement("div");
var cmd2 = document.createElement("div");
var cmd3 = document.createElement("div");
var cmd4 = document.createElement("div");
var postResult = "START";
var debugMode = false;
var relayToRC = null;
var proxyInjectionMode = false;
var uniqueId = 'sel_' + Math.round(100000 * Math.random());
var RemoteRunnerOptions = classCreate();
objectExtend(RemoteRunnerOptions.prototype, URLConfiguration.prototype);
objectExtend(RemoteRunnerOptions.prototype, {
initialize: function() {
this._acquireQueryString();
},
isDebugMode: function() {
return this._isQueryParameterTrue("debugMode");
},
getContinue: function() {
return this._getQueryParameter("continue");
},
getDriverUrl: function() {
return this._getQueryParameter("driverUrl");
},
getSessionId: function() {
return this._getQueryParameter("sessionId");
},
_acquireQueryString: function () {
if (this.queryString) return;
if (browserVersion.isHTA) {
var args = this._extractArgs();
if (args.length < 2) return null;
this.queryString = args[1];
} else if (proxyInjectionMode) {
this.queryString = selenium.browserbot.getCurrentWindow().location.search.substr(1);
} else {
this.queryString = top.location.search.substr(1);
}
}
});
var runOptions;
function runSeleniumTest() {
runOptions = new RemoteRunnerOptions();
var testAppWindow;
if (runOptions.isMultiWindowMode()) {
testAppWindow = openSeparateApplicationWindow('Blank.html', true);
} else if ($('myiframe') != null) {
var myiframe = $('myiframe');
if (myiframe) {
testAppWindow = myiframe.contentWindow;
}
}
else {
proxyInjectionMode = true;
testAppWindow = window;
}
selenium = Selenium.createForWindow(testAppWindow, proxyInjectionMode);
if (runOptions.getBaseUrl()) {
selenium.browserbot.baseUrl = runOptions.getBaseUrl();
}
if (!debugMode) {
debugMode = runOptions.isDebugMode();
}
if (proxyInjectionMode) {
LOG.log = logToRc;
selenium.browserbot._modifyWindow(testAppWindow);
}
else if (debugMode) {
LOG.logHook = logToRc;
}
window.selenium = selenium;
commandFactory = new CommandHandlerFactory();
commandFactory.registerAll(selenium);
currentTest = new RemoteRunner(commandFactory);
if (document.getElementById("commandList") != null) {
document.getElementById("commandList").appendChild(cmd4);
document.getElementById("commandList").appendChild(cmd3);
document.getElementById("commandList").appendChild(cmd2);
document.getElementById("commandList").appendChild(cmd1);
}
var doContinue = runOptions.getContinue();
if (doContinue != null) postResult = "OK";
currentTest.start();
}
function buildDriverUrl() {
var driverUrl = runOptions.getDriverUrl();
if (driverUrl != null) {
return driverUrl;
}
var s = window.location.href
var slashPairOffset = s.indexOf("//") + "//".length
var pathSlashOffset = s.substring(slashPairOffset).indexOf("/")
return s.substring(0, slashPairOffset + pathSlashOffset) + "/selenium-server/driver/";
}
function logToRc(logLevel, message) {
if (logLevel == null) {
logLevel = "debug";
}
if (debugMode) {
sendToRC("logLevel=" + logLevel + ":" + message.replace(/[\n\r\015]/g, " ") + "\n", "logging=true");
}
}
function isArray(x) {
return ((typeof x) == "object") && (x["length"] != null);
}
function serializeString(name, s) {
return name + "=unescape(\"" + escape(s) + "\");";
}
function serializeObject(name, x)
{
var s = '';
if (isArray(x))
{
s = name + "=new Array(); ";
var len = x["length"];
for (var j = 0; j < len; j++)
{
s += serializeString(name + "[" + j + "]", x[j]);
}
}
else if (typeof x == "string")
{
s = serializeString(name, x);
}
else
{
throw "unrecognized object not encoded: " + name + "(" + x + ")";
}
return s;
}
function relayBotToRC(s) {
}
// seems like no one uses this, but in fact it is called using eval from server-side PI mode code; however,
// because multiple names can map to the same popup, assigning a single name confuses matters sometimes;
// thus, I'm disabling this for now. -Nelson 10/21/06
function setSeleniumWindowName(seleniumWindowName) {
//selenium.browserbot.getCurrentWindow()['seleniumWindowName'] = seleniumWindowName;
}
RemoteRunner = classCreate();
objectExtend(RemoteRunner.prototype, new TestLoop());
objectExtend(RemoteRunner.prototype, {
initialize : function(commandFactory) {
this.commandFactory = commandFactory;
this.requiresCallBack = true;
this.commandNode = null;
this.xmlHttpForCommandsAndResults = null;
},
nextCommand : function() {
var urlParms = "";
if (postResult == "START") {
urlParms += "seleniumStart=true";
}
this.xmlHttpForCommandsAndResults = XmlHttp.create();
sendToRC(postResult, urlParms, fnBind(this._HandleHttpResponse, this), this.xmlHttpForCommandsAndResults);
},
commandStarted : function(command) {
this.commandNode = document.createElement("div");
var innerHTML = command.command + '(';
if (command.target != null && command.target != "") {
innerHTML += command.target;
if (command.value != null && command.value != "") {
innerHTML += ', ' + command.value;
}
}
innerHTML += ")";
if (innerHTML.length >40) {
innerHTML = innerHTML.substring(0,40);
innerHTML += "...";
}
this.commandNode.innerHTML = innerHTML;
this.commandNode.style.backgroundColor = workingColor;
if (document.getElementById("commandList") != null) {
document.getElementById("commandList").removeChild(cmd1);
document.getElementById("commandList").removeChild(cmd2);
document.getElementById("commandList").removeChild(cmd3);
document.getElementById("commandList").removeChild(cmd4);
cmd4 = cmd3;
cmd3 = cmd2;
cmd2 = cmd1;
cmd1 = this.commandNode;
document.getElementById("commandList").appendChild(cmd4);
document.getElementById("commandList").appendChild(cmd3);
document.getElementById("commandList").appendChild(cmd2);
document.getElementById("commandList").appendChild(cmd1);
}
},
commandComplete : function(result) {
if (result.failed) {
if (postResult == "CONTINUATION") {
currentTest.aborted = true;
}
postResult = result.failureMessage;
this.commandNode.title = result.failureMessage;
this.commandNode.style.backgroundColor = failColor;
} else if (result.passed) {
postResult = "OK";
this.commandNode.style.backgroundColor = passColor;
} else {
if (result.result == null) {
postResult = "OK";
} else {
postResult = "OK," + result.result;
}
this.commandNode.style.backgroundColor = doneColor;
}
},
commandError : function(message) {
postResult = "ERROR: " + message;
this.commandNode.style.backgroundColor = errorColor;
this.commandNode.title = message;
},
testComplete : function() {
window.status = "Selenium Tests Complete, for this Test"
// Continue checking for new results
this.continueTest();
postResult = "START";
},
_HandleHttpResponse : function() {
if (this.xmlHttpForCommandsAndResults.readyState == 4) {
if (this.xmlHttpForCommandsAndResults.status == 200) {
if (this.xmlHttpForCommandsAndResults.responseText=="") {
LOG.error("saw blank string xmlHttpForCommandsAndResults.responseText");
return;
}
var command = this._extractCommand(this.xmlHttpForCommandsAndResults);
this.currentCommand = command;
this.continueTestAtCurrentCommand();
} else {
var s = 'xmlHttp returned: ' + this.xmlHttpForCommandsAndResults.status + ": " + this.xmlHttpForCommandsAndResults.statusText;
LOG.error(s);
this.currentCommand = null;
setTimeout(fnBind(this.continueTestAtCurrentCommand, this), 2000);
}
}
},
_extractCommand : function(xmlHttp) {
var command;
try {
var re = new RegExp("^(.*?)\n((.|[\r\n])*)");
if (re.exec(xmlHttp.responseText)) {
command = RegExp.$1;
var rest = RegExp.$2;
rest = rest.trim();
if (rest) {
eval(rest);
}
}
else {
command = xmlHttp.responseText;
}
} catch (e) {
alert('could not get responseText: ' + e.message);
}
if (command.substr(0, '|testComplete'.length) == '|testComplete') {
return null;
}
return this._createCommandFromRequest(command);
},
_delay : function(millis) {
var startMillis = new Date();
while (true) {
milli = new Date();
if (milli - startMillis > millis) {
break;
}
}
},
// Parses a URI query string into a SeleniumCommand object
_createCommandFromRequest : function(commandRequest) {
//decodeURIComponent doesn't strip plus signs
var processed = commandRequest.replace(/\+/g, "%20");
// strip trailing spaces
var processed = processed.replace(/\s+$/, "");
var vars = processed.split("&");
var cmdArgs = new Object();
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
cmdArgs[pair[0]] = pair[1];
}
var cmd = cmdArgs['cmd'];
var arg1 = cmdArgs['1'];
if (null == arg1) arg1 = "";
arg1 = decodeURIComponent(arg1);
var arg2 = cmdArgs['2'];
if (null == arg2) arg2 = "";
arg2 = decodeURIComponent(arg2);
if (cmd == null) {
throw new Error("Bad command request: " + commandRequest);
}
return new SeleniumCommand(cmd, arg1, arg2);
}
})
function sendToRC(dataToBePosted, urlParms, callback, xmlHttpObject, async) {
if (async == null) {
async = true;
}
if (xmlHttpObject == null) {
xmlHttpObject = XmlHttp.create();
}
var url = buildDriverUrl() + "?"
if (urlParms) {
url += urlParms;
}
url += "&localFrameAddress=" + (proxyInjectionMode ? makeAddressToAUTFrame() : "top");
url += getSeleniumWindowNameURLparameters();
url += "&uniqueId=" + uniqueId;
if (callback == null) {
callback = function() {
};
}
url += buildDriverParams() + preventBrowserCaching();
xmlHttpObject.open("POST", url, async);
xmlHttpObject.onreadystatechange = callback;
xmlHttpObject.send(dataToBePosted);
return null;
}
function buildDriverParams() {
var params = "";
var sessionId = runOptions.getSessionId();
if (sessionId == undefined) {
sessionId = injectedSessionId;
}
if (sessionId != undefined) {
params = params + "&sessionId=" + sessionId;
}
return params;
}
function preventBrowserCaching() {
var t = (new Date()).getTime();
return "&counterToMakeURsUniqueAndSoStopPageCachingInTheBrowser=" + t;
}
//
// Return URL parameters pertaining to the name(s?) of the current window
//
// In selenium, the main (i.e., first) window's name is a blank string.
//
// Additional pop-ups are associated with either 1.) the name given by the 2nd parameter to window.open, or 2.) the name of a
// property on the opening window which points at the window.
//
// An example of #2: if window X contains JavaScript as follows:
//
// var windowABC = window.open(...)
//
// Note that the example JavaScript above is equivalent to
//
// window["windowABC"] = window.open(...)
//
function getSeleniumWindowNameURLparameters() {
var w = (proxyInjectionMode ? selenium.browserbot.getCurrentWindow() : window).top;
var s = "&seleniumWindowName=";
if (w.opener == null) {
return s;
}
if (w["seleniumWindowName"] == null) {
s += 'generatedSeleniumWindowName_' + Math.round(100000 * Math.random());
}
else {
s += w["seleniumWindowName"];
}
var windowOpener = w.opener;
for (key in windowOpener) {
var val = null;
try {
val = windowOpener[key];
}
catch(e) {
}
if (val==w) {
s += "&jsWindowNameVar=" + key; // found a js variable in the opener referring to this window
}
}
return s;
}
// construct a JavaScript expression which leads to my frame (i.e., the frame containing the window
// in which this code is operating)
function makeAddressToAUTFrame(w, frameNavigationalJSexpression)
{
if (w == null)
{
w = top;
frameNavigationalJSexpression = "top";
}
if (w == selenium.browserbot.getCurrentWindow())
{
return frameNavigationalJSexpression;
}
for (var j = 0; j < w.frames.length; j++)
{
var t = makeAddressToAUTFrame(w.frames[j], frameNavigationalJSexpression + ".frames[" + j + "]");
if (t != null)
{
return t;
}
}
return null;
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,5 @@
Selenium.version = "0.8.2";
Selenium.revision = "1727";
window.top.document.title += " v" + Selenium.version + " [" + Selenium.revision + "]";

View file

@ -0,0 +1,75 @@
/*
* By default, Selenium looks for a file called "user-extensions.js", and loads and javascript
* code found in that file. This file is a sample of what that file could look like.
*
* user-extensions.js provides a convenient location for adding extensions to Selenium, like
* new actions, checks and locator-strategies.
* By default, this file does not exist. Users can create this file and place their extension code
* in this common location, removing the need to modify the Selenium sources, and hopefully assisting
* with the upgrade process.
*
* You can find contributed extensions at http://wiki.openqa.org/display/SEL/Contributed%20User-Extensions
*/
// The following examples try to give an indication of how Selenium can be extended with javascript.
// All do* methods on the Selenium prototype are added as actions.
// Eg add a typeRepeated action to Selenium, which types the text twice into a text box.
// The typeTwiceAndWait command will be available automatically
Selenium.prototype.doTypeRepeated = function(locator, text) {
// All locator-strategies are automatically handled by "findElement"
var element = this.page().findElement(locator);
// Create the text to type
var valueToType = text + text;
// Replace the element text with the new text
this.page().replaceText(element, valueToType);
};
// All assert* methods on the Selenium prototype are added as checks.
// Eg add a assertValueRepeated check, that makes sure that the element value
// consists of the supplied text repeated.
// The verify version will be available automatically.
Selenium.prototype.assertValueRepeated = function(locator, text) {
// All locator-strategies are automatically handled by "findElement"
var element = this.page().findElement(locator);
// Create the text to verify
var expectedValue = text + text;
// Get the actual element value
var actualValue = element.value;
// Make sure the actual value matches the expected
Assert.matches(expectedValue, actualValue);
};
// All get* methods on the Selenium prototype result in
// store, assert, assertNot, verify, verifyNot, waitFor, and waitForNot commands.
// E.g. add a getTextLength method that returns the length of the text
// of a specified element.
// Will result in support for storeTextLength, assertTextLength, etc.
Selenium.prototype.getTextLength = function(locator) {
return this.getText(locator).length;
};
// All locateElementBy* methods are added as locator-strategies.
// Eg add a "valuerepeated=" locator, that finds the first element with the supplied value, repeated.
// The "inDocument" is a the document you are searching.
PageBot.prototype.locateElementByValueRepeated = function(text, inDocument) {
// Create the text to search for
var expectedValue = text + text;
// Loop through all elements, looking for ones that have a value === our expected value
var allElements = inDocument.getElementsByTagName("*");
for (var i = 0; i < allElements.length; i++) {
var testElement = allElements[i];
if (testElement.value && testElement.value === expectedValue) {
return testElement;
}
}
return null;
};

View file

@ -0,0 +1,153 @@
// This is a third party JavaScript library from
// http://webfx.eae.net/dhtml/xmlextras/xmlextras.html
// i.e. This has not been written by ThoughtWorks.
//<script>
//////////////////
// Helper Stuff //
//////////////////
// used to find the Automation server name
function getDomDocumentPrefix() {
if (getDomDocumentPrefix.prefix)
return getDomDocumentPrefix.prefix;
var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
var o;
for (var i = 0; i < prefixes.length; i++) {
try {
// try to create the objects
o = new ActiveXObject(prefixes[i] + ".DomDocument");
return getDomDocumentPrefix.prefix = prefixes[i];
}
catch (ex) {};
}
throw new Error("Could not find an installed XML parser");
}
function getXmlHttpPrefix() {
if (getXmlHttpPrefix.prefix)
return getXmlHttpPrefix.prefix;
var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
var o;
for (var i = 0; i < prefixes.length; i++) {
try {
// try to create the objects
o = new ActiveXObject(prefixes[i] + ".XmlHttp");
return getXmlHttpPrefix.prefix = prefixes[i];
}
catch (ex) {};
}
throw new Error("Could not find an installed XML parser");
}
//////////////////////////
// Start the Real stuff //
//////////////////////////
// XmlHttp factory
function XmlHttp() {}
XmlHttp.create = function () {
try {
if (window.XMLHttpRequest) {
var req = new XMLHttpRequest();
// some versions of Moz do not support the readyState property
// and the onreadystate event so we patch it!
if (req.readyState == null) {
req.readyState = 1;
req.addEventListener("load", function () {
req.readyState = 4;
if (typeof req.onreadystatechange == "function")
req.onreadystatechange();
}, false);
}
return req;
}
if (window.ActiveXObject) {
return new ActiveXObject(getXmlHttpPrefix() + ".XmlHttp");
}
}
catch (ex) {}
// fell through
throw new Error("Your browser does not support XmlHttp objects");
};
// XmlDocument factory
function XmlDocument() {}
XmlDocument.create = function () {
try {
// DOM2
if (document.implementation && document.implementation.createDocument) {
var doc = document.implementation.createDocument("", "", null);
// some versions of Moz do not support the readyState property
// and the onreadystate event so we patch it!
if (doc.readyState == null) {
doc.readyState = 1;
doc.addEventListener("load", function () {
doc.readyState = 4;
if (typeof doc.onreadystatechange == "function")
doc.onreadystatechange();
}, false);
}
return doc;
}
if (window.ActiveXObject)
return new ActiveXObject(getDomDocumentPrefix() + ".DomDocument");
}
catch (ex) {}
throw new Error("Your browser does not support XmlDocument objects");
};
// Create the loadXML method and xml getter for Mozilla
if (window.DOMParser &&
window.XMLSerializer &&
window.Node && Node.prototype && Node.prototype.__defineGetter__) {
// XMLDocument did not extend the Document interface in some versions
// of Mozilla. Extend both!
//XMLDocument.prototype.loadXML =
Document.prototype.loadXML = function (s) {
// parse the string to a new doc
var doc2 = (new DOMParser()).parseFromString(s, "text/xml");
// remove all initial children
while (this.hasChildNodes())
this.removeChild(this.lastChild);
// insert and import nodes
for (var i = 0; i < doc2.childNodes.length; i++) {
this.appendChild(this.importNode(doc2.childNodes[i], true));
}
};
/*
* xml getter
*
* This serializes the DOM tree to an XML String
*
* Usage: var sXml = oNode.xml
*
*/
// XMLDocument did not extend the Document interface in some versions
// of Mozilla. Extend both!
/*
XMLDocument.prototype.__defineGetter__("xml", function () {
return (new XMLSerializer()).serializeToString(this);
});
*/
Document.prototype.__defineGetter__("xml", function () {
return (new XMLSerializer()).serializeToString(this);
});
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View file

@ -0,0 +1,43 @@
body, table {
font-family: Verdana, Arial, sans-serif;
font-size: 12;
}
table {
border-collapse: collapse;
border: 1px solid #ccc;
}
th, td {
padding-left: 0.3em;
padding-right: 0.3em;
}
a {
text-decoration: none;
}
.title {
font-style: italic;
}
.selected {
background-color: #ffffcc;
}
.status_done {
background-color: #eeffee;
}
.status_passed {
background-color: #ccffcc;
}
.status_failed {
background-color: #ffcccc;
}
.breakpoint {
background-color: #cccccc;
border: 1px solid black;
}

View file

@ -0,0 +1,299 @@
/*
* Copyright 2005 ThoughtWorks, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*---( Layout )---*/
* {
margin: 0px;
padding: 0px;
}
body {
overflow: auto;
}
td {
position: static;
}
tr {
vertical-align: top;
}
.layout {
width: 100%;
height: 100%;
border-collapse: collapse;
}
.layout td {
border: 0;
}
iframe {
border: 0px;
width: 100%;
height: 100%;
background: white;
overflow: auto;
}
/*---( Style )---*/
body, html {
font-family: Verdana, Arial, sans-serif;
}
.selenium th, .selenium td {
border: 1px solid #999;
}
.header {
background: #ccc;
padding: 0;
font-size: 90%;
}
#controlPanel {
padding: 0.5ex;
background: #eee;
overflow: auto;
font-size: 75%;
text-align: center;
}
#controlPanel fieldset {
margin: 0.3ex;
padding: 0.3ex;
}
#controlPanel fieldset legend {
color: black;
}
#controlPanel button {
margin: 0.5ex;
}
#imageButtonPanel button {
width: 24px;
height: 20px;
background-color:white;
background-repeat: no-repeat;
background-position: center;
border-style: solid;
border-color: black;
border-width: 1px;
}
#controlPanel #runSuite {
width: 32px;
background-image: url("icons/all.png");
}
#controlPanel #runSeleniumTest {
width: 32px;
background-image: url("icons/selected.png");
}
.cssPauseTest {
background-image: url("icons/pause.png");
}
.cssPauseTest[disabled] {
background-image: url("icons/pause_disabled.png");
}
.cssContinueTest {
background-image: url("icons/continue.png");
}
.cssContinueTest[disabled] {
background-image: url("icons/continue_disabled.png");
}
#controlPanel #stepTest {
background-image: url("icons/step.png");
}
#controlPanel #stepTest[disabled] {
background-image: url("icons/step_disabled.png");
}
#controlPanel table {
font-size: 100%;
}
#controlPanel th, #controlPanel td {
border: 0;
}
h1 {
margin: 0.2ex;
font-size: 130%;
font-weight: bold;
}
h2 {
margin: 0.2ex;
font-size: 80%;
font-weight: normal;
}
.selenium a {
color: black;
text-decoration: none;
}
.selenium a:hover {
text-decoration: underline;
}
button, label {
cursor: pointer;
}
#stats {
margin: 0.5em auto 0.5em auto;
}
#stats th, #stats td {
text-align: left;
padding-left: 2px;
}
#stats th {
text-decoration: underline;
}
#stats td.count {
font-weight: bold;
text-align: right;
}
#testRuns {
color: green;
}
#testFailures {
color: red;
}
#commandPasses {
color: green;
}
#commandFailures {
color: red;
}
#commandErrors {
color: #f90;
}
/*---( Logging Console )---*/
#logging-console {
background: #fff;
font-size: 75%;
}
#logging-console #banner {
display: block;
width: 100%;
position: fixed;
top: 0;
background: #ddd;
border-bottom: 1px solid #666;
}
#logging-console #logLevelChooser {
float: right;
margin: 3px;
}
#logging-console ul {
list-style-type: none;
margin: 0px;
margin-top: 3em;
padding-left: 5px;
}
#logging-console li {
margin: 2px;
border-top: 1px solid #ccc;
}
#logging-console li.error {
font-weight: bold;
color: red;
}
#logging-console li.warn {
color: red;
}
#logging-console li.debug {
color: green;
}
div.executionOptions {
padding-left: 5em;
}
div.executionOptions label, div.executionOptions input {
display: block;
float: left;
}
div.executionOptions br {
clear: left;
}
#speedSlider {
text-align: left;
margin: 0px auto;
width: 260px;
line-height: 0px;
font-size: 0px;
padding: 0px;
}
#speedSlider #speedTrack {
background-color: #333;
width: 260px;
height: 2px;
line-height: 2px;
z-index: 1;
border: 1px solid;
border-color: #999 #ddd #ddd #999;
cursor: pointer;
}
#speedSlider #speedHandle {
width: 12px;
top: -8px;
background-color: #666;
position: relative;
margin: 0px;
height: 8px;
line-height: 8px;
z-index: 1;
border: 1px solid;
border-color: #999 #333 #333 #999;
cursor: pointer;
}

View file

@ -0,0 +1,428 @@
// Copyright 2005 Google Inc.
// All Rights Reserved
//
// An XML parse and a minimal DOM implementation that just supportes
// the subset of the W3C DOM that is used in the XSLT implementation.
//
// References:
//
// [DOM] W3C DOM Level 3 Core Specification
// <http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/>.
//
//
// Author: Steffen Meschkat <mesch@google.com>
// NOTE: The split() method in IE omits empty result strings. This is
// utterly annoying. So we don't use it here.
// Resolve entities in XML text fragments. According to the DOM
// specification, the DOM is supposed to resolve entity references at
// the API level. I.e. no entity references are passed through the
// API. See "Entities and the DOM core", p.12, DOM 2 Core
// Spec. However, different browsers actually pass very different
// values at the API.
//
function xmlResolveEntities(s) {
var parts = stringSplit(s, '&');
var ret = parts[0];
for (var i = 1; i < parts.length; ++i) {
var rp = stringSplit(parts[i], ';');
if (rp.length == 1) {
// no entity reference: just a & but no ;
ret += parts[i];
continue;
}
var ch;
switch (rp[0]) {
case 'lt':
ch = '<';
break;
case 'gt':
ch = '>';
break;
case 'amp':
ch = '&';
break;
case 'quot':
ch = '"';
break;
case 'apos':
ch = '\'';
break;
case 'nbsp':
ch = String.fromCharCode(160);
break;
default:
// Cool trick: let the DOM do the entity decoding. We assign
// the entity text through non-W3C DOM properties and read it
// through the W3C DOM. W3C DOM access is specified to resolve
// entities.
var span = window.document.createElement('span');
span.innerHTML = '&' + rp[0] + '; ';
ch = span.childNodes[0].nodeValue.charAt(0);
}
ret += ch + rp[1];
}
return ret;
}
// Parses the given XML string with our custom, JavaScript XML parser. Written
// by Steffen Meschkat (mesch@google.com).
function xmlParse(xml) {
Timer.start('xmlparse');
var regex_empty = /\/$/;
// See also <http://www.w3.org/TR/REC-xml/#sec-common-syn> for
// allowed chars in a tag and attribute name. TODO(mesch): the
// following is still not completely correct.
var regex_tagname = /^([\w:-]*)/;
var regex_attribute = /([\w:-]+)\s?=\s?('([^\']*)'|"([^\"]*)")/g;
var xmldoc = new XDocument();
var root = xmldoc;
// For the record: in Safari, we would create native DOM nodes, but
// in Opera that is not possible, because the DOM only allows HTML
// element nodes to be created, so we have to do our own DOM nodes.
// xmldoc = document.implementation.createDocument('','',null);
// root = xmldoc; // .createDocumentFragment();
// NOTE(mesch): using the DocumentFragment instead of the Document
// crashes my Safari 1.2.4 (v125.12).
var stack = [];
var parent = root;
stack.push(parent);
var x = stringSplit(xml, '<');
for (var i = 1; i < x.length; ++i) {
var xx = stringSplit(x[i], '>');
var tag = xx[0];
var text = xmlResolveEntities(xx[1] || '');
if (tag.charAt(0) == '/') {
stack.pop();
parent = stack[stack.length-1];
} else if (tag.charAt(0) == '?') {
// Ignore XML declaration and processing instructions
} else if (tag.charAt(0) == '!') {
// Ignore notation and comments
} else {
var empty = tag.match(regex_empty);
var tagname = regex_tagname.exec(tag)[1];
var node = xmldoc.createElement(tagname);
var att;
while (att = regex_attribute.exec(tag)) {
var val = xmlResolveEntities(att[3] || att[4] || '');
node.setAttribute(att[1], val);
}
if (empty) {
parent.appendChild(node);
} else {
parent.appendChild(node);
parent = node;
stack.push(node);
}
}
if (text && parent != root) {
parent.appendChild(xmldoc.createTextNode(text));
}
}
Timer.end('xmlparse');
return root;
}
// Our W3C DOM Node implementation. Note we call it XNode because we
// can't define the identifier Node. We do this mostly for Opera,
// where we can't reuse the HTML DOM for parsing our own XML, and for
// Safari, where it is too expensive to have the template processor
// operate on native DOM nodes.
function XNode(type, name, value, owner) {
this.attributes = [];
this.childNodes = [];
XNode.init.call(this, type, name, value, owner);
}
// Don't call as method, use apply() or call().
XNode.init = function(type, name, value, owner) {
this.nodeType = type - 0;
this.nodeName = '' + name;
this.nodeValue = '' + value;
this.ownerDocument = owner;
this.firstChild = null;
this.lastChild = null;
this.nextSibling = null;
this.previousSibling = null;
this.parentNode = null;
}
XNode.unused_ = [];
XNode.recycle = function(node) {
if (!node) {
return;
}
if (node.constructor == XDocument) {
XNode.recycle(node.documentElement);
return;
}
if (node.constructor != this) {
return;
}
XNode.unused_.push(node);
for (var a = 0; a < node.attributes.length; ++a) {
XNode.recycle(node.attributes[a]);
}
for (var c = 0; c < node.childNodes.length; ++c) {
XNode.recycle(node.childNodes[c]);
}
node.attributes.length = 0;
node.childNodes.length = 0;
XNode.init.call(node, 0, '', '', null);
}
XNode.create = function(type, name, value, owner) {
if (XNode.unused_.length > 0) {
var node = XNode.unused_.pop();
XNode.init.call(node, type, name, value, owner);
return node;
} else {
return new XNode(type, name, value, owner);
}
}
XNode.prototype.appendChild = function(node) {
// firstChild
if (this.childNodes.length == 0) {
this.firstChild = node;
}
// previousSibling
node.previousSibling = this.lastChild;
// nextSibling
node.nextSibling = null;
if (this.lastChild) {
this.lastChild.nextSibling = node;
}
// parentNode
node.parentNode = this;
// lastChild
this.lastChild = node;
// childNodes
this.childNodes.push(node);
}
XNode.prototype.replaceChild = function(newNode, oldNode) {
if (oldNode == newNode) {
return;
}
for (var i = 0; i < this.childNodes.length; ++i) {
if (this.childNodes[i] == oldNode) {
this.childNodes[i] = newNode;
var p = oldNode.parentNode;
oldNode.parentNode = null;
newNode.parentNode = p;
p = oldNode.previousSibling;
oldNode.previousSibling = null;
newNode.previousSibling = p;
if (newNode.previousSibling) {
newNode.previousSibling.nextSibling = newNode;
}
p = oldNode.nextSibling;
oldNode.nextSibling = null;
newNode.nextSibling = p;
if (newNode.nextSibling) {
newNode.nextSibling.previousSibling = newNode;
}
if (this.firstChild == oldNode) {
this.firstChild = newNode;
}
if (this.lastChild == oldNode) {
this.lastChild = newNode;
}
break;
}
}
}
XNode.prototype.insertBefore = function(newNode, oldNode) {
if (oldNode == newNode) {
return;
}
if (oldNode.parentNode != this) {
return;
}
if (newNode.parentNode) {
newNode.parentNode.removeChild(newNode);
}
var newChildren = [];
for (var i = 0; i < this.childNodes.length; ++i) {
var c = this.childNodes[i];
if (c == oldNode) {
newChildren.push(newNode);
newNode.parentNode = this;
newNode.previousSibling = oldNode.previousSibling;
oldNode.previousSibling = newNode;
if (newNode.previousSibling) {
newNode.previousSibling.nextSibling = newNode;
}
newNode.nextSibling = oldNode;
if (this.firstChild == oldNode) {
this.firstChild = newNode;
}
}
newChildren.push(c);
}
this.childNodes = newChildren;
}
XNode.prototype.removeChild = function(node) {
var newChildren = [];
for (var i = 0; i < this.childNodes.length; ++i) {
var c = this.childNodes[i];
if (c != node) {
newChildren.push(c);
} else {
if (c.previousSibling) {
c.previousSibling.nextSibling = c.nextSibling;
}
if (c.nextSibling) {
c.nextSibling.previousSibling = c.previousSibling;
}
if (this.firstChild == c) {
this.firstChild = c.nextSibling;
}
if (this.lastChild == c) {
this.lastChild = c.previousSibling;
}
}
}
this.childNodes = newChildren;
}
XNode.prototype.hasAttributes = function() {
return this.attributes.length > 0;
}
XNode.prototype.setAttribute = function(name, value) {
for (var i = 0; i < this.attributes.length; ++i) {
if (this.attributes[i].nodeName == name) {
this.attributes[i].nodeValue = '' + value;
return;
}
}
this.attributes.push(new XNode(DOM_ATTRIBUTE_NODE, name, value));
}
XNode.prototype.getAttribute = function(name) {
for (var i = 0; i < this.attributes.length; ++i) {
if (this.attributes[i].nodeName == name) {
return this.attributes[i].nodeValue;
}
}
return null;
}
XNode.prototype.removeAttribute = function(name) {
var a = [];
for (var i = 0; i < this.attributes.length; ++i) {
if (this.attributes[i].nodeName != name) {
a.push(this.attributes[i]);
}
}
this.attributes = a;
}
function XDocument() {
XNode.call(this, DOM_DOCUMENT_NODE, '#document', null, this);
this.documentElement = null;
}
XDocument.prototype = new XNode(DOM_DOCUMENT_NODE, '#document');
XDocument.prototype.clear = function() {
XNode.recycle(this.documentElement);
this.documentElement = null;
}
XDocument.prototype.appendChild = function(node) {
XNode.prototype.appendChild.call(this, node);
this.documentElement = this.childNodes[0];
}
XDocument.prototype.createElement = function(name) {
return XNode.create(DOM_ELEMENT_NODE, name, null, this);
}
XDocument.prototype.createDocumentFragment = function() {
return XNode.create(DOM_DOCUMENT_FRAGMENT_NODE, '#document-fragment',
null, this);
}
XDocument.prototype.createTextNode = function(value) {
return XNode.create(DOM_TEXT_NODE, '#text', value, this);
}
XDocument.prototype.createAttribute = function(name) {
return XNode.create(DOM_ATTRIBUTE_NODE, name, null, this);
}
XDocument.prototype.createComment = function(data) {
return XNode.create(DOM_COMMENT_NODE, '#comment', data, this);
}
XNode.prototype.getElementsByTagName = function(name, list) {
if (!list) {
list = [];
}
if (this.nodeName == name) {
list.push(this);
}
for (var i = 0; i < this.childNodes.length; ++i) {
this.childNodes[i].getElementsByTagName(name, list);
}
return list;
}

View file

@ -0,0 +1,255 @@
// Copyright 2005 Google Inc.
// All Rights Reserved
//
// Miscellania that support the ajaxslt implementation.
//
// Author: Steffen Meschkat <mesch@google.com>
//
function el(i) {
return document.getElementById(i);
}
function px(x) {
return x + 'px';
}
// Split a string s at all occurrences of character c. This is like
// the split() method of the string object, but IE omits empty
// strings, which violates the invariant (s.split(x).join(x) == s).
function stringSplit(s, c) {
var a = s.indexOf(c);
if (a == -1) {
return [ s ];
}
var parts = [];
parts.push(s.substr(0,a));
while (a != -1) {
var a1 = s.indexOf(c, a + 1);
if (a1 != -1) {
parts.push(s.substr(a + 1, a1 - a - 1));
} else {
parts.push(s.substr(a + 1));
}
a = a1;
}
return parts;
}
// Returns the text value if a node; for nodes without children this
// is the nodeValue, for nodes with children this is the concatenation
// of the value of all children.
function xmlValue(node) {
if (!node) {
return '';
}
var ret = '';
if (node.nodeType == DOM_TEXT_NODE ||
node.nodeType == DOM_CDATA_SECTION_NODE ||
node.nodeType == DOM_ATTRIBUTE_NODE) {
ret += node.nodeValue;
} else if (node.nodeType == DOM_ELEMENT_NODE ||
node.nodeType == DOM_DOCUMENT_NODE ||
node.nodeType == DOM_DOCUMENT_FRAGMENT_NODE) {
for (var i = 0; i < node.childNodes.length; ++i) {
ret += arguments.callee(node.childNodes[i]);
}
}
return ret;
}
// Returns the representation of a node as XML text.
function xmlText(node) {
var ret = '';
if (node.nodeType == DOM_TEXT_NODE) {
ret += xmlEscapeText(node.nodeValue);
} else if (node.nodeType == DOM_ELEMENT_NODE) {
ret += '<' + node.nodeName;
for (var i = 0; i < node.attributes.length; ++i) {
var a = node.attributes[i];
if (a && a.nodeName && a.nodeValue) {
ret += ' ' + a.nodeName;
ret += '="' + xmlEscapeAttr(a.nodeValue) + '"';
}
}
if (node.childNodes.length == 0) {
ret += '/>';
} else {
ret += '>';
for (var i = 0; i < node.childNodes.length; ++i) {
ret += arguments.callee(node.childNodes[i]);
}
ret += '</' + node.nodeName + '>';
}
} else if (node.nodeType == DOM_DOCUMENT_NODE ||
node.nodeType == DOM_DOCUMENT_FRAGMENT_NODE) {
for (var i = 0; i < node.childNodes.length; ++i) {
ret += arguments.callee(node.childNodes[i]);
}
}
return ret;
}
// Applies the given function to each element of the array.
function mapExec(array, func) {
for (var i = 0; i < array.length; ++i) {
func(array[i]);
}
}
// Returns an array that contains the return value of the given
// function applied to every element of the input array.
function mapExpr(array, func) {
var ret = [];
for (var i = 0; i < array.length; ++i) {
ret.push(func(array[i]));
}
return ret;
};
// Reverses the given array in place.
function reverseInplace(array) {
for (var i = 0; i < array.length / 2; ++i) {
var h = array[i];
var ii = array.length - i - 1;
array[i] = array[ii];
array[ii] = h;
}
}
// Shallow-copies an array.
function copyArray(dst, src) {
for (var i = 0; i < src.length; ++i) {
dst.push(src[i]);
}
}
function assert(b) {
if (!b) {
throw 'assertion failed';
}
}
// Based on
// <http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247>
var DOM_ELEMENT_NODE = 1;
var DOM_ATTRIBUTE_NODE = 2;
var DOM_TEXT_NODE = 3;
var DOM_CDATA_SECTION_NODE = 4;
var DOM_ENTITY_REFERENCE_NODE = 5;
var DOM_ENTITY_NODE = 6;
var DOM_PROCESSING_INSTRUCTION_NODE = 7;
var DOM_COMMENT_NODE = 8;
var DOM_DOCUMENT_NODE = 9;
var DOM_DOCUMENT_TYPE_NODE = 10;
var DOM_DOCUMENT_FRAGMENT_NODE = 11;
var DOM_NOTATION_NODE = 12;
var xpathdebug = false; // trace xpath parsing
var xsltdebug = false; // trace xslt processing
// Escape XML special markup chracters: tag delimiter < > and entity
// reference start delimiter &. The escaped string can be used in XML
// text portions (i.e. between tags).
function xmlEscapeText(s) {
return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
// Escape XML special markup characters: tag delimiter < > entity
// reference start delimiter & and quotes ". The escaped string can be
// used in double quoted XML attribute value portions (i.e. in
// attributes within start tags).
function xmlEscapeAttr(s) {
return xmlEscapeText(s).replace(/\"/g, '&quot;');
}
// Escape markup in XML text, but don't touch entity references. The
// escaped string can be used as XML text (i.e. between tags).
function xmlEscapeTags(s) {
return s.replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
// An implementation of the debug log.
var logging__ = false;
function Log() {};
Log.lines = [];
Log.write = function(s) {
if (logging__) {
this.lines.push(xmlEscapeText(s));
this.show();
}
};
// Writes the given XML with every tag on a new line.
Log.writeXML = function(xml) {
if (logging__) {
var s0 = xml.replace(/</g, '\n<');
var s1 = xmlEscapeText(s0);
var s2 = s1.replace(/\s*\n(\s|\n)*/g, '<br/>');
this.lines.push(s2);
this.show();
}
}
// Writes without any escaping
Log.writeRaw = function(s) {
if (logging__) {
this.lines.push(s);
this.show();
}
}
Log.clear = function() {
if (logging__) {
var l = this.div();
l.innerHTML = '';
this.lines = [];
}
}
Log.show = function() {
var l = this.div();
l.innerHTML += this.lines.join('<br/>') + '<br/>';
this.lines = [];
l.scrollTop = l.scrollHeight;
}
Log.div = function() {
var l = document.getElementById('log');
if (!l) {
l = document.createElement('div');
l.id = 'log';
l.style.position = 'absolute';
l.style.right = '5px';
l.style.top = '5px';
l.style.width = '250px';
l.style.height = '150px';
l.style.overflow = 'auto';
l.style.backgroundColor = '#f0f0f0';
l.style.border = '1px solid gray';
l.style.fontSize = '10px';
l.style.padding = '5px';
document.body.appendChild(l);
}
return l;
}
function Timer() {}
Timer.start = function() {}
Timer.end = function() {}

File diff suppressed because it is too large Load diff