- function require(file, callback) {
- if (file)
- {
- if (!constant.isDefined("API_URL")) {
- constant.set('API_URL','http://funceme.br/produtos/js/');
- }
- var name = $include.formatNameFile(file);
- var filejs = constant.get('API_URL')+file;
- var isInclude = $include.isScript(filejs);
- if (isInclude) {
- var newjs = document.createElement('script');
- newjs.setAttribute('name', 'fapp');
- //IE
- newjs.onreadstatechange = function() {
- if (newjs.readyState==='loaded'|| newjs.readyState==='complete') {
- newjs.onreadystatechange = null;
- if (typeof callback === "function") {
- callback();
- }
- }
- }
- //outros
- newjs.onload = function() {
- if (typeof callback === "function") {
- callback();
- }
- }
- newjs.src = filejs;
- document.body.appendChild(newjs);
- }else if (typeof callback === "function") {
- callback();
- }
- }
- }
- var $include = {
- formatNameFile : function(nome) {
- var nameArray = nome.split('/');
- nome = nameArray[1];
- return nome;
- },
- isScript : function(nome) {
- $('script[name=fapp]').each(function() {
- if ($(this).attr('src')==nome) {
- return false;
- }
- });
- return true;
- }
- }
- var constant = (function() {
- var constants = {},
- ownProp = Object.prototype.hasOwnProperty,
- allowed = {
- string : 1,
- number : 1,
- bolean : 1
- },
- prefix = (Math.random()+"_").slice(2);
- return {
- set : function(name,value) {
- if (this.isDefined(name)) {
- return false;
- }
- if (!ownProp.call(allowed,typeof value)) {
- return false;
- }
- constants[prefix+name] = value;
- return true;
- },
- isDefined : function(name) {
- return ownProp.call(constants, prefix+name);
- },
- get : function(name) {
- if (this.isDefined(name)) {
- return constants[prefix+name];
- }
- return null;
- }
- }
- }());
Raw Paste