Jash - JavaScript Shell Copyright: 2007, Billy Reisinger Documentation: http://www.billyreisinger.com/jash/ License: GNU General Public License - http://www.gnu.org/licenses/gpl.html This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
new Jash()
|
| • |
revision
|
| CVS Revision Number, do not modify | |
| • |
stopWatch
|
| Time execution in ms |
| ◊ |
addEvent(obj, eventName, func)
|
| Cross-browser DOM 2 event handler assignment - calls 'func' on 'eventName' in 'obj' |
| parameters | ||
| HTML Element |
obj
|
HTML Element on which to listen for eventName |
| string |
eventName
|
event name without "on", i.e., "click" |
| function |
func
|
function to assign as handler for eventName on obj |
| ◊ |
assignInputKeyEvent(keyCode)
|
| Map input keystrokes |
| parameters | ||
| int |
keyCode
|
number representing keycode of key pressed in event object |
| ◊ |
clear()
|
| Clear output console |
| ◊ |
close()
|
| show/hide Jash |
| ◊ |
create()
|
| Create HTML necessary for Debugger, assign events to buttons and window |
| ◊ |
dump(obj)
|
| Dump - show verbose output of all of an object's members |
| parameters | ||
| object |
obj
|
object whose members should be dumped |
| returns | |
| _null or other string, see above | |
| ◊ |
findElementPosition(obj)
|
| Find top, left pixel offset of HTML element relative to window |
| parameters | ||
| HTML Element |
obj
|
an HTML element to calculate offset of |
| returns | |
| array | [x,y] offset of html element 'obj' |
| ◊ |
getAccessKeyText()
|
| return access key text based on what browser we're using. Access keys are different for every browser, and even between the same browsers on different platforms. |
| ◊ |
getDimensions(el)
|
| Get the pixel dimensions of any given HTML object |
| parameters | ||
| HTML Element |
el
|
an HTML element |
| returns | |
| object | [x,y] representing object width, height |
| ◊ |
getMouseXY(e)
|
| Get mouse position in pixels |
| parameters | ||
| object |
e
|
event object |
| returns | |
| object | [x,y] representing mouse position on screen in px |
| ◊ |
getXBrowserYOffset()
|
| Get the Y scrolling offset of the current page for whatever browser |
| returns | |
| int | Y scrolling offset of current page |
| ◊ |
help()
|
| Print some useful information |
| ◊ |
identifyNode(el, showDots)
|
| Return a string containing information about HTML element 'el' - node name, id, class, etc. |
| parameters | ||
| HTML Element |
el
|
Element to inspect |
| bool |
showDots
|
precede returned text with dots |
| returns | |
| object |
{txt: string |
| ◊ |
kill()
|
| Remove node under cursor |
| ◊ |
main()
|
| Set environment, create HTML |
| ◊ |
print(text, clear, suppressLineNumbers, autoscroll)
|
| Print simple output to the console |
| parameters | ||
| string |
text
|
text to print |
| bool |
clear
|
clear console before printing, default is false |
| bool |
suppressLineNumbers
|
print line number before text, default is true |
| bool |
autoscroll
|
scroll output console to bottom when printing |
| ◊ |
returnBrowserType()
|
| return string representing browser type |
| ◊ |
returnOsType()
|
| return string representing os |
| ◊ |
setButtonVisualActiveState(button, state)
|
| set the visual state of a button |
| parameters | ||
| HTML Element |
button
|
element to change visual state of |
| string |
state
|
"on" | "off" |
| ◊ |
setCrossBrowserAccessKeyFunctionForAnchor(el)
|
| Cross-browser access key |
| parameters | ||
| HTML Element |
el
|
element to simulate access key event on |
| ◊ |
show(obj)
|
| Show terse output (name and type) of an object's members |
| parameters | ||
| object |
obj
|
an object whose members are to be shown |
| returns | |
| string | _null |
| ◊ |
showNodes(e)
|
| DOM inspection: Show parent node structure, and possibly innerHTML, of node under mouse cursor. |
| parameters | ||
| object |
e
|
Event object |
| ◊ |
showOutputHistory()
|
| Shows everything that has gone in the output console during this session |
| ◊ |
start()
|
| Start the timer |
| returns | |
| int | epoch time in ms |
| ◊ |
stop()
|
| Stop the timer |
| returns | |
| int | time between start and stop in ms |
new Jash.Evaluator()
|
| ◊ |
evalCss(input)
|
| evaluate 'input' string as css |
| parameters | ||
| string |
input
|
an input string to evaluate as css (selector(s) followed by rules) |
| returns | |
| sring | the input string unmodified |
| ◊ |
evalJs(input)
|
| Evaluate 'input' string as javascript |
| parameters | ||
| string |
input
|
input string to evaluate as javascript |
| returns | |
| string | result of evaluation (or undefined if this.returnInsteadOfPrint is true) |
| ◊ |
evaluate(input)
|
| Delegate evaluation of input string appropriately |
| parameters | ||
| string |
input
|
input string to evaluate |
| ◊ |
insertStyleRule(rule)
|
| Write style rule in stylesheet |
| parameters | ||
| string |
rule
|
a series of selectors and rules separated by the newline character '\n' |
| returns | |
| string | empty string |
new Jash.History()
|
| ◊ |
add(input)
|
| Add input string to history array |
| parameters | ||
| string |
input
|
input to add to history |
| ◊ |
getNextInput()
|
| Get the next input string in history relative to the current position |
| returns | |
| string | blank if no history value, or string |
| ◊ |
getPreviousInput()
|
| Find the previous input in history relative to current position |
| returns | |
| string | blank if no history value, or string |
Jash.Indenter.indent(document.getElementById("someDiv").innerHTML);
| ◊ |
static
Jash.Indenter.closeUnclosedNode(str)
|
| Find unclosed tags (a list of which is in this.nodesCommonlyUnclosed) in str and close them. |
| parameters | ||
| string |
str
|
string representing one node |
| returns | |
| str | string with tag(s) closed |
| ◊ |
static
Jash.Indenter.indent(source)
|
| indent string source and return indented result |
| parameters | ||
| string |
source
|
a string representing unformatted HTML |
| returns | |
| string | prettified HTML |
| ◊ |
static
Jash.Indenter.indentAndAdd(level, string, arr)
|
| Indent a text string level times and add it to arr |
| parameters | ||
| int |
level
|
number of times to indent string |
| string |
string
|
string to indent |
| Array |
arr
|
array of indented strings (i.e., result set) |
| returns | |
| Array | array "arr" with new entry |
| ◊ |
static
Jash.Indenter.stringRepeat(stringToRepeat, times)
|
| repeat stringToRepeat times times and return concatenated string with no separator |
| parameters | ||
| string |
stringToRepeat
|
a string that should be repeated times times |
| int |
times
|
number of times to repeat string |
| returns | |
| string | string repeated times times |
var profile = new Jash.Profiler(function() {
document.getElementById("something");
});
profile.multiPass(1000);
new Jash.Profiler(func, func)
|
| parameters | ||
| function |
func
|
Function to profile |
| function |
func
|
(optional) callback function to fire when profiler is done |
| • |
stopWatch
|
| Simple stop watch to time something in milliseconds |
| ◊ |
average(arr)
|
| Get the average of all of the numbers in arr |
| parameters | ||
| array |
arr
|
Array of integers to average |
| returns | |
| int | Average of numbers in arr |
| ◊ |
forLoop(reps)
|
| Do this.func reps times in a for loop |
| parameters | ||
| int |
reps
|
Amount of times to execute this.func |
| returns | |
| int | Time, in milliseconds, it took to perform loop |
| ◊ |
loop(kind, reps)
|
| Controller for loop types - run loop 'kind' with 'reps' iterations Store the results of each loop type in its own array, i.e. results.reverseWhile.100 or results.forLoop.100 or results.reverseWhile.200 |
| parameters | ||
| str |
kind
|
Kind of loop to perform. "reverseWhile" | "forLoop" |
| int |
reps
|
Number of iterations in the loop. |
| ◊ |
multiPass(passes, type, reps)
|
| run func() passes times in type manner (if type is a loop type, do reps iterations) |
| parameters | ||
| int |
passes
|
number of times to execute func |
| str |
type
|
"runOnce" or "forLoop" or "reverseWhile" (optional, defaults to runOnce) |
| int |
reps
|
number of times to loop if loop type is used (optional) |
| ◊ |
reportProfile(avgMs, type, reps)
|
| Create output for user to see results |
| parameters | ||
| int |
avgMs
|
Average milliseconds it took to do type reps times |
| str |
type
|
Type of function profile. If not "runOnce", then profile type is considered a loop. |
| int |
reps
|
(optional, only if type is loopy) Number of repetitions of loop |
| ◊ |
reverseWhile(reps)
|
| Do this.func 'reps' times in a reverse while loop |
| parameters | ||
| int |
reps
|
Amount of times to execute this.func |
| returns | |
| int | Time, in milliseconds, it took to perform loop |
| ◊ |
runOnce()
|
| Run this.func only one time, store resulting time in milliseconds in this.results.runOnce[] |
new Jash.TabComplete()
|
| ◊ |
doAllStringsInArrayHaveSameCharacterAtIndex(index, arr)
|
| Return true if all characters in an array of strings at a certain position are the same |
| parameters | ||
| int |
index
|
0 start int position of character to look at |
| array |
arr
|
array of strings to test |
| returns | |
| boolean | True if all characters match at position 'index', false if not |
| ◊ |
findBestStringMatch(str, arr)
|
| Try to find the longest possible match in an array of strings starting from the left |
| parameters | ||
| str |
str
|
String to look for |
| array |
arr
|
Array of strings to look through |
| returns | |
| str | Longest match, starting from left, of all strings in arr |
| ◊ |
findTextMatchesInArray(arrayToTest, findMe)
|
| Look through an array of strings, return strings that match 'findMe' |
| parameters | ||
| array |
arrayToTest
|
array of strings to match against |
| string |
findMe
|
string to look for in array |
| returns | |
| array | array of matches (if matches > 1) |
| str | string match (if matches == 1) |
| boolean | false (if matches == 0) |
| ◊ |
getMembers(context)
|
| Scan an object and return just the member names |
| parameters | ||
| string |
context
|
name of object to scan |
| ◊ |
searchInputForDomGetElFunctions(inputText)
|
| scan inputText to determine if a dom get el fct was typed in. If so, return match and type of match (class or id) |
| parameters | ||
| str |
inputText
|
Text to scan for getEl function |
| returns | |
| object | { match: "matching text", type: "class" | "id" } |
| ◊ |
tabCompleteIdOrClassInCss(inputText)
|
| Attempt to complete an element id or class name based on what is available in all elements in the current DOM; assume the input text is a css-style selector, i.e. ".someth" or "#someth" |
| parameters | ||
| string |
inputText
|
Text to try to complete |
| ◊ |
tabCompleteIdOrClassInJavascript(inputText, type)
|
| Attempt to complete an element id or class name based on what is available in all elements in the current DOM; assume the input text is a javascript function call containing (" before the string in question. |
| parameters | ||
| string |
inputText
|
Text to try to complete |
| string |
type
|
"id" | "class" : element id or class name completion |
| ◊ |
tabCompleteJavascript(e, inputText)
|
| Try to complete a javscript object or function name |
| parameters | ||
| object |
e
|
Event object |
| string |
inputText
|
Text to run completion on |
| returns | |
| boolean | false |