Using Javascript from SpiderBasic
skinkairewalker
 
Posts: 86
Joined: Tue Jun 14, 2016 7:17 pm

What am I doing wrong when importing a JS script?

by skinkairewalker Fri Feb 19, 2021 2:25 pm

Hello everyone !
there are some Javascript scripts that I try to import into my project, but most of them always get the error> Uncaught ReferenceError, what am I doing wrong when importing these scripts? below an example of the functional html code :

Code: Select all
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="https://cdn.metroui.org.ua/v4/css/metro-all.min.css">
  </head>
  <body>
    <h1 class="text-center">Metro 4</h1>
    <h3 class="text-center">The Components Library</h3>
    <div data-role="cube"></div>

    <script src="https://cdn.metroui.org.ua/v4/js/metro.min.js"></script>
  </body>
</html>


But when I try to import the script.js into the SB the error occurs: metro.js: 5450 Uncaught ReferenceError: Metro is not defined
at metro.js: 5450


screenshot : https://prnt.sc/100xl1l

below the SB code that I'm using :


Code: Select all
ExamineDesktops()
Global deskwidth.i = DesktopWidth(0)
Global deskheight.i = DesktopHeight(0)

Declare ButtonClick(index)

Procedure AppendHead(content.s)
  Debug "head"
  !$("head").append(v_content);
EndProcedure

Procedure AppendBody(content.s)
  !$("body").append(v_content);
EndProcedure

Procedure AppendContent(component.i,content.s, Position = #PB_Ignore)
  GID = GadgetID(component)
  If Position <> #PB_Ignore
    ! $(".card:eq(" + v_position + ")").prepend(v_content);
  Else
    ! $(v_gid.div).append(v_content);
  EndIf
EndProcedure

Procedure OnResize()
 
  ExamineDesktops()
  deskwidth = DesktopWidth(0)
  deskheight = DesktopHeight(0)
 
  Debug "Resized W : " + Str(deskwidth)
  Debug "Resized H : " + Str(deskheight)
 
  ResizeWindow(0,#PB_Ignore,#PB_Ignore,deskwidth,deskheight)
  ResizeGadget(0,#PB_Ignore,#PB_Ignore,deskwidth,deskheight)
 
EndProcedure


Procedure Main(URL$, Success)
 
  Debug "Script URL: " + URL$
  Debug "Loading status: " + Success
 
  OpenWindow(0, 0, 0, 600, 600, "",#PB_Window_Background)
 
  ScrollAreaGadget(0, 0, 0, deskwidth, deskheight,600,600) : CloseGadgetList()
 
  AppendContent(0," <h1 class='text-center'>Metro 4</h1>"+
   " <h3 class='text-center'>The Components Library</h3>"+
   " <div Data-role='cube'></div> ")
 

 
 EndProcedure
   
  Procedure ButtonClick(indice)
    Debug "ButtonClick(" + indice + ")"
  EndProcedure

Procedure init(URL$, Success)
    Debug "Script URL: " + URL$
    Debug "Loading status: " + Success
   
   ; ! $("<link rel='stylesheet' type='text/css'>").attr("href", "https://cdn.metroui.org.ua/v4/css/metro-all.min.css").appendTo("head");

;     ! require(["https://cdn.metroui.org.ua/v4/js/metro.min.js"], function() {
;     Main()
;     ! });   
   
    LoadScript("https://cdn.metroui.org.ua/v4/js/metro.min.js",@Main(),#PB_Script_JavaScript)
   
EndProcedure

BindEvent(#PB_Event_SizeDesktop,@OnResize())

AppendHead("<meta http-equiv='cache-control' content='max-age=0' />' />"+
           "<meta http-equiv='pragma' content='no-cache' />"+
           "<meta http-equiv='cache-control' content='no-store' />"+
           "<meta http-equiv='expires' content='Tue, 01 Jan 1980 1:00:00 GMT' />' />"+
           "<meta http-equiv='expires' content='-1' />")

AppendHead("<meta http-equiv='Content-Security-Policy' content='upgrade-insecure-requests'>")

AppendHead("<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'>")

;! $("<link rel='stylesheet' href='https://cdn.metroui.org.ua/v4/css/metro-all.min.css' />").appendTo("head");

LoadScript("https://cdn.metroui.org.ua/v4/css/metro-all.min.css", @init(), #PB_Script_CSS)


Can anyone give me a light ? :)
User avatar
Peter
 
Posts: 867
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080

Re: What am I doing wrong when importing a JS script?

by Peter Sat Feb 20, 2021 11:21 am

It seems to be a bigger problem to include the metro-library. In an earlier version I managed to do this with the HttpPreProcessor. In the current version, this no longer seems to work.
Return to Javascript

Who is online

Users browsing this forum: No registered users and 1 guest