Skip to content

AlexBaitov/AppendScript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

AppendScript

Description (EN)

  • Appends script in a <head>
  • Checks the presence of the script by src and do not append twice
  • Execute callback-function on success or error

Input object properties:

src : '',                                       // script src
success: function(fileExistence, script){},     // callback on success
error: function(fileExistence){}                // callback on error

The success-callback function receives two parameters:

fileExistence {integer} 2 - if the script was already in DOM
1 - if the script has just appended
script {DOM element} appended or already presented script

The error-callback function receives one parameter:

fileExistence {integer} 0 - if the script is still absent in DOM

Requires: jQuery 1.7+
N.B. This function could be written without jQuery, but it would not be as short as it is.

Описание (RU)

Прикпрепляет скрипт в <head>
Проверят на наличие по src и второй раз не прикрепляет
@param options {object} В callback-функции первым параметром возвращает:
2 - если скрипт уже есть на странице,
1 - если присоединил,
0 - если скрипта всё ещё нет на странице
Вторым параметром в success находится DOM элемент прикрепленного скрипта

Usage

AppendScript({
    src:'/js/some.js',
	success: function(fileExistence,script){
	    SomeFunctionInSomeJS();
	}
});

Authors

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published