Skip to content

npabisz/wait-for

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Wait for it!

Simple function to allow using libs which are loaded at last in footer.

<!DOCTYPE html>
<html>
   <head>
      <script>
         function waitFor(objectName, callback)
         {
            //function body from this repository
         }
      </script>
   </head>
   <body>
      <div class="widget">
         <!-- Sometimes we need to call some js from inside widget which is loaded before js libraries -->
         <script>
            waitFor('SomeClassLoadedInFooter', function () {
               //Our library is loaded, we can call whatever we want

               SomeClassLoadedInFooter.myWidgetJustLoaded();
            });
			
            waitFor(['jQuery', 'SomeClassLoadedInFooter'], function () {
               //Both libraries are loaded
			   
               jQuery.get(SomeClassLoadedInFooter.someUrl());
            });
			
            waitFor('jQuery.someExtraPlugin', function () {
               //jQuery's someExtraPlugin is loaded
			   
               jQuery('body').someExtraPlugin();
            });
         </script>
      </div>

      <!-- Load jQuery -->
      <script src="/jQuery.js"></script>
	  
      <!-- Loading our library with SomeClassLoadedInFooter prototype -->
      <script src="/some-class-loaded-in-footer.js"></script>
   </body>
</html>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published