Loading the script:
<script type="text/javascript" src="../js/myJS-1.2.js"></script>
<!-- or -->
<script type="text/javascript" src="../js/myJS-1.2.min.js"></script>
DOM FUNCTIONS ^
JS.gss(query, css)
let val = JS.gss("#id", "color"); // returns color value
Specify the selection and CSS property to retrieve
JS.css(QuerySelect [,css])
JS.css(".content", "background: black; visibility: visible;")
JS.css("textarea").background = "black";
JS.css("#id").visibility = "visible";
Specify the selection and optionally the css statements. Sets the style attribute value of an HTML tag.
JS.doq(qs)
let obj = JS.doq("#id");
Given a DOM query selector, return the elements object handle.
JS.addClass(qs, classname)
JS.addClass("input", "myclass");
Classname must exist in the classlist.
JS.delClass(qs, classname)
JS.delClass("input", "myclass");
Classname must exist in the classlist.
JS.htm(qs [,data])
let val = JS.htm("#id"); // get
JS.htm("#id", val); // set
JS.tod(qs, mode)
JS.tod("#id", "block");
JS.tod(".msg1", "inline");
Toggles an element's display property between block|inline and none.
JS.show(qs)
JS.show(".msgclass");
Set selected element to "visible".
make hidden
JS.hide(qs)
JS.hide(".msgclass");
Hide selected element.
JS.val(qs [,data])
let value = JS.val("#id"); // get value
JS.val("#id", value); // set value
Get or Set the form input value of the selection.
JS.attr(qs, aname [,avalue])
let value = JS.attr("#id", "size"); // get attr value
JS.attr("#id", "size", "35"); // set attr value
Get or set HTML tag attributes, like: size='35'
ASYNC FUNCTIONS ^
example:
JS.webpost("my.php", 1, `postvar1=${var1}&postvar2=${var2}`)
. . .
function webresponse(n, text) {
switch (n) {
case 1:
// do something with text ...
break;
case 2:
// ... and so on
break;
}
}
The function 'webresponse' is used by all of the async functions and you have to code it. All of the async functions execute a promise which will call webresponse function upon completion.
JS.webget(url, n)
JS.webget("myfile.txt", 1);
Send a request to return the contents of a text file residing on the app server. 'webresponse' is called with n=1 after the file is read. see example above.
JS.webgetjson(url, n)
JS.webgetjson("mydata.json", 1);
Send a request to return the contents of a JSON file residing on the app server. 'webresponse' returns a JSON object.
JS.webpost(url, n, qs)
JS.webpost("handler.php", 1, `postvar1=${var1}&postvar2=${var2}`)
Probably the most useful - for getting dynamic updates to your page.
JS.websend(url, qs)
JS.websend(url, `txt=${text2save}`);
NOTE: webresponse will not be called upon completion of this one-way message.
MISC FUNCTIONS ^
JS.sleep( m )
JS.sleep( 2000 ); // wait 2 seconds
processes milliseconds of time
JS.scrollBottom()
JS.scrollBottom();
forces current page to scroll to bottom.
JS.rand( low, high )
JS.rand( 1, 5 );
Returns a random number from low to high inclusive.
JS.getOptionText( qs )
let txt = JS.getOptionText("#mySelect");
Returns the currently selected text
from an HTML <select>
element.
JS.getOptionIndex( qs )
let num = JS.getOptionIndex( "#mySelect" );
Returns the currently selected index from
an HTML <select>
element.
JS.getQvar( var )
let val = JS.getQvar( "name" );
Returns the value in a querystring name/value pair.
JS.titleCase( string )
let msg = JS.titleCase( "hello GAL" ); // -> "Hello Gal"
Returns a string in title case.
JS.setCB( s )
JS.setCB( "put into clipbrd" );
Will request user's permissions according to current standards.
JS.getCB()
JS.getCB(); // uses callback
requires the following callback that you must code:
function getCBtext(text) {
// do something with text
}
JS.notify( string )
JS.notify( "Good Morning" );
Creates a system notification - Will request user's permissions according to current standards.
JS.numfix( f, [p] )
let f = 123.4567
let fd = JS.numfix( f ); // fd = 123.46
given a floating point 'f' convert
to 'p' places; default is 2
returns a float value
JS.dlgOpen( qs )
JS.dlgOpen("dialog");
JS.dlgClose( qs )
JS.dlgClose("dialog")
COOKIE FUNCTIONS ^
JS.setCookie( cname, cvalue [, exdays] )
JS.setCookie("mycook", "valu", 30)
JS.getCookie( cname )
let cval = JS.getCookie( "mycook" );
JS.deleteCookie( name )
JS.deleteCookie( "mycook" );
DATE FUNCTIONS ^
JS.todayDay([DateObj])
let daynbr = JS.todayDay();
Returns digit 0..6
where 0 is Sunday.
:Uses current date object
unless you provide one.
JS.todayMon([DateObj])
let mnbr = JS.todayMon();
Returns digit 1..12
JS.getDOM([DateObj])
let dnbr = JS.getDOM();
Returns digit 1..31
JS.todayYear([DateObj])
let yrYYYY = JS.todayYear();
Returns 4 digit year like 1996.
JS.getMDY([DateObj])
let mdy = JS.getMDY();
JS.getYMD([DateObj])
let ymd = JS.getYMD();
JS.getHM()
let hm = JS.getHM();
Returns time in HH:MM format
JS.getHM12()
let hm12 = JS.getHM12();
Returns time in 12 hour HH:MM am/pm format
JS.addDays(n)
let objDate = JS.addDays(15); // today + 15 days
Returns new date object.
JS.getShortMon(n)
let smonth = JS.getShortMon(11);
Returns 3 character month, like: "Nov"
n = the month number 1-12 or (JS.todayMon())
JS.getLongMon(n)
let month = JS.getLongMon(JS.todayMon());
Returns month spelled out, like: "November"
n = the month number 1-12 or (JS.todayMon())
JS.getShortDay(n)
let sday = JS.getShortDay(3); // Wed
Returns 3 character day of week.
n = the day number 0-6 or (JS.todayDay())
JS.getLongDay(n)
let day = JS.getLongDay(JS.todayDay()); // Wednesday
Returns day of week spelled out.
n = the day number 0-6.
//Examples of date output
JS.getMDY() // 03/20/2022
JS.getYMD() // 2022-03-20
JS.getHM() // 11:19
JS.getHM12() // 11:19 am
JS.todayDay() // 0
JS.getShortDay(JS.todayDay()) // Sun
JS.getLongDay(JS.todayDay()) // Sunday
JS.getShortMon(JS.todayMon()) // Mar
JS.getLongMon(JS.todayMon()) // March
JS.todayMon() // 3
JS.getDOM() // 20
JS.todayYear() // 2022
let mydate = JS.addDays(8); // + 8 days
JS.getYMD(mydate) // 2022-03-28
JS.getMDY(mydate) // 03/28/2022
JS.getShortMon(JS.todayMon(mydate)) // Mar
JS.getLongDay(JS.todayDay(mydate)) // Monday