Proyecto en colaboración con OPASO

main.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Authors : Carlos C. Corrada-Bravo
  2. David J. Ortiz-Rivera
  3. José A. Quiñones-Flores
  4. Organization : Centro de Desarrollo y Consultoria Computacional
  5. Project : OPASO Material Registry
  6. File : main.js
  7. Description : Compile mainly used functions */
  8. /* current() - highlight current page in navbar */
  9. function current(){
  10. var current = window.location.pathname;
  11. $(".link").each(function(){
  12. if($(this).attr("href") == current){
  13. $(this).addClass("current");
  14. }
  15. });
  16. }
  17. /* get_arg(arg: string) - fetches argument from url if set, else returns null */
  18. function get_arg(arg){
  19. /* Get arg by id */
  20. var url = new URL(window.location.href);
  21. arg = url.searchParams.get(arg);
  22. return arg;
  23. }
  24. /* loading_screen(flag: bool) - hide/show loading screen */
  25. function loading_screen(flag){
  26. if(flag){ /* show */
  27. $(".content").css("overflow","hidden");
  28. $(".loading-screen").show();
  29. }
  30. else{ /* hide */
  31. $(".loading-screen").hide();
  32. $(".content").css("overflow","auto");
  33. }
  34. }
  35. /* create_button(text: string,icon: object,cname: string,id: string,val: string) - generates button */
  36. function create_button(text,icon,cname,id,val){
  37. var button = document.createElement("button");
  38. /* set attributes */
  39. button.setAttribute("class",cname);
  40. button.setAttribute("id",id);
  41. if(is_defined(val)){
  42. button.setAttribute("val",val);
  43. }
  44. /* set content */
  45. button.textContent = text;
  46. button.append(create_element("i",icon));
  47. return button;
  48. }
  49. /* create_element(type: string,cname: string,content: string) - generates an html element */
  50. function create_element(type,cname,content){
  51. var element = document.createElement(type);
  52. /* set class */
  53. element.setAttribute("class",cname);
  54. /* set content */
  55. if(is_defined(content)){
  56. element.textContent = content;
  57. }
  58. return element;
  59. }
  60. /* display_error(error: string) - display error to user */
  61. function display_error(message){
  62. var error = create_element("div","error",message);
  63. $(".main").html(error);
  64. }
  65. /* is_defined(arg: any) - return true if an argument is defined */
  66. function is_defined(arg){
  67. return typeof arg != undefined;
  68. }