Skip to content
This repository has been archived by the owner on Apr 16, 2019. It is now read-only.

added one method to get cross-domain script. #608

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 55 additions & 9 deletions appframework.js
Expand Up @@ -752,7 +752,7 @@ if (!window.af || typeof(af) !== "function") {
if (this.length === 0)
return (value === nundefined) ? undefined : this;
if (value === nundefined && !$.isObject(attr)) {
var val = (this[0].afmCacheId && _attrCache[this[0].afmCacheId][attr]) ? (this[0].afmCacheId && _attrCache[this[0].afmCacheId][attr]) : this[0].getAttribute(attr);
var val = (this[0].afmCacheId && _attrCache[this[0].afmCacheId] && _attrCache[this[0].afmCacheId][attr]) ? _attrCache[this[0].afmCacheId][attr] : this[0].getAttribute(attr);
return val;
}
for (var i = 0; i < this.length; i++) {
Expand Down Expand Up @@ -793,7 +793,7 @@ if (!window.af || typeof(af) !== "function") {
for (var i = 0; i < this.length; i++) {
attr.split(/\s+/g).forEach(function(param) {
that[i].removeAttribute(param);
if (that[i].afmCacheId && _attrCache[that[i].afmCacheId][attr])
if (that[i].afmCacheId && _attrCache[that[i].afmCacheId])
delete _attrCache[that[i].afmCacheId][attr];
});
}
Expand All @@ -819,7 +819,7 @@ if (!window.af || typeof(af) !== "function") {
return (value === nundefined) ? undefined : this;
if (value === nundefined && !$.isObject(prop)) {
var res;
var val = (this[0].afmCacheId && _propCache[this[0].afmCacheId][prop]) ? (this[0].afmCacheId && _propCache[this[0].afmCacheId][prop]) : !(res = this[0][prop]) && prop in this[0] ? this[0][prop] : res;
var val = (this[0].afmCacheId && _propCache[this[0].afmCacheId] && _propCache[this[0].afmCacheId][prop]) ? _propCache[this[0].afmCacheId][prop] : !(res = this[0][prop]) && prop in this[0] ? this[0][prop] : res;
return val;
}
for (var i = 0; i < this.length; i++) {
Expand Down Expand Up @@ -859,7 +859,7 @@ if (!window.af || typeof(af) !== "function") {
prop.split(/\s+/g).forEach(function(param) {
if (that[i][param])
that[i][param] = undefined;
if (that[i].afmCacheId && _propCache[that[i].afmCacheId][prop]) {
if (that[i].afmCacheId && _propCache[that[i].afmCacheId]) {
delete _propCache[that[i].afmCacheId][prop];
}
});
Expand Down Expand Up @@ -1451,16 +1451,18 @@ if (!window.af || typeof(af) !== "function") {
* @title $().data(key,[value]);
*/
data: function(key, value) {
var retData;
var retData, JSON_RE = /^{.*}$/;
// setter
if (value) {
if (value !== undefined && value !== null) {
return this.attr('data-' + key, value);
}
// getter
retData = this.attr('data-' + key);
try {
retData = $.parseJSON(retData);
} catch(ex) {}
if (JSON_RE.test(retData)) {
try {
retData = $.parseJSON(retData);
} catch(ex) {}
}
return retData;
},
/**
Expand Down Expand Up @@ -1716,6 +1718,7 @@ if (!window.af || typeof(af) !== "function") {
switch (settings.dataType) {
case "script":
settings.dataType = 'text/javascript, application/javascript';
return $.getScript(settings.url, settings.success);
break;
case "json":
settings.dataType = 'application/json';
Expand Down Expand Up @@ -1886,6 +1889,49 @@ if (!window.af || typeof(af) !== "function") {
});
};

/**
* get script.
* Note: code are borrowed from jQuery.
```
$.getScript("some.js",);
```

* @param {String} url to hit
* @param {Function} [success]
*/
$.getScript = function(url, success) {
var script,
head = document.head || af("head")[0] || document.documentElement;

script = document.createElement("script");

script.async = true;

script.src = url;

// Attach handlers for all browsers
script.onload = script.onreadystatechange = function( _, isAbort ) {

if ( isAbort || !script.readyState || /loaded|complete/.test( script.readyState ) ) {

// Remove the script
if ( script.parentNode ) {
script.parentNode.removeChild( script );
}

// Dereference the script
script = null;

// Callback if not abort
if ( !isAbort ) {
success && success( 200, "success" );
}
}
};

head.insertBefore( script, head.firstChild );
}

/**
* Converts an object into a key/value par with an optional prefix. Used for converting objects to a query string
```
Expand Down