12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- /* Authors : Carlos C. Corrada-Bravo
- David J. Ortiz-Rivera
- José A. Quiñones-Flores
-
- Organization : Centro de Desarrollo y Consultoria Computacional
- Project : OPASO Material Registry
- File : main.js
- Description : Compile mainly used functions */
-
- /* current() - highlight current page in navbar */
- function current(){
- var current = window.location.pathname;
- $(".link").each(function(){
- if($(this).attr("href") == current){
- $(this).addClass("current");
- }
- });
- }
- /* get_arg(arg: string) - fetches argument from url if set, else returns null */
- function get_arg(arg){
- /* Get arg by id */
- var url = new URL(window.location.href);
- arg = url.searchParams.get(arg);
- return arg;
- }
- /* loading_screen(flag: bool) - hide/show loading screen */
- function loading_screen(flag){
- if(flag){ /* show */
- $(".content").css("overflow","hidden");
- $(".loading-screen").show();
- }
- else{ /* hide */
- $(".loading-screen").hide();
- $(".content").css("overflow","auto");
- }
- }
- /* create_button(text: string,icon: object,cname: string,id: string,val: string) - generates button */
- function create_button(text,icon,cname,id,val){
- var button = document.createElement("button");
- /* set attributes */
- button.setAttribute("class",cname);
- button.setAttribute("id",id);
- if(is_defined(val)){
- button.setAttribute("val",val);
- }
- /* set content */
- button.textContent = text;
- button.append(create_element("i",icon));
- return button;
- }
- /* create_element(type: string,cname: string,content: string) - generates an html element */
- function create_element(type,cname,content){
- var element = document.createElement(type);
- /* set class */
- element.setAttribute("class",cname);
- /* set content */
- if(is_defined(content)){
- element.textContent = content;
- }
- return element;
- }
- /* display_error(error: string) - display error to user */
- function display_error(message){
- var error = create_element("div","error",message);
- $(".main").html(error);
- }
- /* is_defined(arg: any) - return true if an argument is defined */
- function is_defined(arg){
- return typeof arg != undefined;
- }
|