Skip to content

MLeidel/myJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

myJS function Reference

  1. DOM FUNCTIONS
  2. ASYNC FUNCTIONS
  3. MISC FUNCTIONS
  4. COOKIE FUNCTIONS
  5. DATE FUNCTIONS

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 ^

return CSS property value

JS.gss(query, css)

let val = JS.gss("#id", "color"); // returns color value

Specify the selection and CSS property to retrieve


change inline style

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.


return DOM object

JS.doq(qs)

let obj = JS.doq("#id");

Given a DOM query selector, return the elements object handle.


add a class to an HTML element

JS.addClass(qs, classname)

JS.addClass("input", "myclass");

Classname must exist in the classlist.


remove a class from an HTML element

JS.delClass(qs, classname)

JS.delClass("input", "myclass");

Classname must exist in the classlist.


Set or Get innerHTML

JS.htm(qs [,data])

let val = JS.htm("#id"); // get
JS.htm("#id", val); // set

toggle 'display' property value

JS.tod(qs, mode)

JS.tod("#id", "block");
JS.tod(".msg1", "inline");

Toggles an element's display property between block|inline and none.


make visible

JS.show(qs)

JS.show(".msgclass");

Set selected element to "visible".


make hidden

JS.hide(qs)

JS.hide(".msgclass");

Hide selected element.


get or set an input value

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.


get or set a tag attribute

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.

read a text file

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.


read a JSON file

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.


send request and recieve reponse

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.


send data to handler w/out response

JS.websend(url, qs)

JS.websend(url, `txt=${text2save}`);

NOTE: webresponse will not be called upon completion of this one-way message.


MISC FUNCTIONS ^

sleep

JS.sleep( m )

JS.sleep( 2000 ); // wait 2 seconds

processes milliseconds of time


jump to bottom of page

JS.scrollBottom()

JS.scrollBottom();

forces current page to scroll to bottom.


random number

JS.rand( low, high )

JS.rand( 1, 5 );

Returns a random number from low to high inclusive.


selected list item

JS.getOptionText( qs )

let txt = JS.getOptionText("#mySelect");

Returns the currently selected text from an HTML <select> element.


selected list index

JS.getOptionIndex( qs )

let num = JS.getOptionIndex( "#mySelect" );

Returns the currently selected index from an HTML <select> element.


value of querystring name-value pair

JS.getQvar( var )

let val = JS.getQvar( "name" );

Returns the value in a querystring name/value pair.


Title Case

JS.titleCase( string )

let msg = JS.titleCase( "hello GAL" ); // -> "Hello Gal"

Returns a string in title case.


copy string to system clipboard

JS.setCB( s )

JS.setCB( "put into clipbrd" );

Will request user's permissions according to current standards.


paste clipboard contents

JS.getCB()

JS.getCB(); // uses callback

requires the following callback that you must code:

function getCBtext(text) { 

  // do something with text
  
}

generate a notification

JS.notify( string )

JS.notify( "Good Morning" );

Creates a system notification - Will request user's permissions according to current standards.


format a decimal number

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


open html modal dialog

JS.dlgOpen( qs )

JS.dlgOpen("dialog");

close html modal dialog

JS.dlgClose( qs )

JS.dlgClose("dialog")

COOKIE FUNCTIONS ^

set a cookie

JS.setCookie( cname, cvalue [, exdays] )

JS.setCookie("mycook", "valu", 30)

get a cookie 8-)

JS.getCookie( cname )

let cval = JS.getCookie( "mycook" );

delete cookie 8-(

JS.deleteCookie( name )

JS.deleteCookie( "mycook" );

DATE FUNCTIONS ^

day of week

JS.todayDay([DateObj])

let daynbr = JS.todayDay();

Returns digit 0..6
where 0 is Sunday.

:Uses current date object
unless you provide one.


month number

JS.todayMon([DateObj])

let mnbr = JS.todayMon();

Returns digit 1..12


date (number) of month

JS.getDOM([DateObj])

let dnbr = JS.getDOM();

Returns digit 1..31


year

JS.todayYear([DateObj])

let yrYYYY = JS.todayYear();

Returns 4 digit year like 1996.


date mm/dd/yyyy

JS.getMDY([DateObj])

let mdy = JS.getMDY();

date yyyy/mm/dd

JS.getYMD([DateObj])

let ymd = JS.getYMD();

Hours:Minutes

JS.getHM()

let hm = JS.getHM();

Returns time in HH:MM format


Hours:Minutes am/pm

JS.getHM12()

let hm12 = JS.getHM12();

Returns time in 12 hour HH:MM am/pm format


add days to date

JS.addDays(n)

let objDate = JS.addDays(15); // today + 15 days

Returns new date object.


Month (short)

JS.getShortMon(n)

let smonth = JS.getShortMon(11);

Returns 3 character month, like: "Nov"
n = the month number 1-12 or (JS.todayMon())


Month (long)

JS.getLongMon(n)

let month = JS.getLongMon(JS.todayMon());

Returns month spelled out, like: "November"
n = the month number 1-12 or (JS.todayMon())


Day (short)

JS.getShortDay(n)

let sday = JS.getShortDay(3); // Wed

Returns 3 character day of week.
n = the day number 0-6 or (JS.todayDay())


Day (long)

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
Here endith the document

Releases

No releases published

Packages

No packages published