Wait-Screen

Share your advanced knowledge/code with the community.
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Wait-Screen

Post by Peter »

Here is a little snippet for showing a Wait-Screen during long time operations (like HTTPRequest()).

The code is using the jquery.msg - Library.

Code: Select all

Procedure.i PageInclude(FileName.s, FileType.s="")
  ; by eddy (http://forums.spiderbasic.com/viewtopic.php?f=9&t=153)
  If FileType = "" : FileType = GetExtensionPart(FileName) : EndIf
  Select LCase(FileType)
    Case "less"
      !$('<link rel="stylesheet/less" type="text/css">').attr('href',v_filename).appendTo('head');
    Case "css"
      !$('<link rel="stylesheet" type="text/css">').attr('href',v_filename).appendTo('head');
    Case "js"
      !$('<script type="text/javascript"></script>').attr('src',v_filename).appendTo('head');
  EndSelect
EndProcedure

PageInclude("jquery.center.min.js")
PageInclude("jquery.msg.css")
PageInclude("jquery.msg.min.js")

Procedure Wait(Flag)
  
  ; http://dreamerslab.com/blog/en/jquery-blockui-alternative-with-jquery-msg-plugin/
  
  If Flag
    ! $.msg({ autoUnblock : false, clickUnblock : false, content : '<center><h1>Please wait...</h1><p>(this window will be closed in 5 Seconds)</p><img src="wait.gif" /></center>' });
  Else
    ! $.msg( 'unblock' );
  EndIf
  
EndProcedure

Enumeration
  #Desktop
  #TestWindow
  #TestButton
  #myTimer
EndEnumeration

Procedure CloseWait()
  
  Wait(#False)
  
  RemoveWindowTimer(#Desktop, #myTimer)
  
EndProcedure

Procedure OpenWait()
  
  Wait(#True)
  
  AddWindowTimer(#Desktop, #myTimer, 5000)
  BindEvent(#PB_Event_Timer, @CloseWait(), #Desktop)
  
EndProcedure

Procedure TestButtonEvent()
  OpenWait()
EndProcedure

OpenWindow(#Desktop, 0, 0, 0, 0, "msg-Demo", #PB_Window_Background)
OpenWindow(#TestWindow, 100, 100, 300, 300, "Test-Window")
ButtonGadget(#TestButton, 10, 10, 200, 30, "Show Wait-Screen")
BindGadgetEvent(#TestButton, @TestButtonEvent())
Here you can see a demo. (The server is a little bit slow)

Here is the complete package to download (~63 KB)

Greetings ... Peter
tj1010
Posts: 201
Joined: Wed May 27, 2015 1:36 pm
Contact:

Re: Wait-Screen

Post by tj1010 »

or you could just use asynchronous requests like are in 99% of JS snippets on the internet. I don't even think JQuery supports synchronous AJAX anymore.
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Wait-Screen

Post by Peter »

HTTPRequest() is asynchronous.

Greetings ... Peter
Post Reply