JavaScript include_once
!No description available for include_once. @php.js developers: Please update the function summary text file.
1 2 3 4 56 7 8 9 1011 12 13 14 1516 17 18 19 2021 22 23 24 2526 27 28 29 3031 32 33 34 3536 37 38 39 4041 | function include_once (filename) { // !No description available for include_once. @php.js developers: Please update the function summary text file. // // version: 911.2217 // discuss at: http://phpjs.org/functions/include_once // + original by: Legaev Andrey // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + improved by: Michael White (http://getsprink.com) // + input by: Brett Zamir (http://brett-zamir.me) // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + bugfixed by: Brett Zamir (http://brett-zamir.me) // - depends on: include // % note 1: Uses global: php_js to keep track of included files (though private static variable in namespaced version) // * example 1: include_once('http://www.phpjs.org/js/phpjs/_supporters/pj_test_supportfile_2.js'); // * returns 1: true var cur_file = {}; cur_file[this.window.location.href] = 1; // BEGIN STATIC try { // We can't try to access on window, since it might not exist in some environments, and if we use "this.window" // we risk adding another copy if different window objects are associated with the namespaced object php_js_shared; // Will be private static variable in namespaced version or global in non-namespaced // version since we wish to share this across all instances } catch(e) { php_js_shared = {}; } // END STATIC if (!php_js_shared.includes) { php_js_shared.includes = cur_file; } if (!php_js_shared.includes[filename]) { if (this.include(filename)){ return true; } } else{ return true; } return false;} |
Examples
Running
1 | include_once('http://www.phpjs.org/js/phpjs/_supporters/pj_test_supportfile_2.js'); |
Should return
1 | true |
Dependencies
In order to use this function, you also need:
Open syntax issues
php.js uses JsLint to help us keep our code consistent and prevent some common bugs.
Eventually we want all code to pass or at least take into consideration most fixes suggested by JsLint, following this JsLint configuration we’ve decided on.
Authors
Thanks to the following developers, you get to have include_once goodness in JavaScript.
No comments yet. Be the first!
spread the word:
Use any PHP function in JavaScript
These kind folks have already donated: Anonymous and Shawn Houser.
<your name here>