Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v0.1' into v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanNano committed Jun 2, 2015
2 parents d4bf58f + 31f2cea commit ec630e6
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 80 deletions.
107 changes: 60 additions & 47 deletions af.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,34 +192,36 @@ var items= {
}
},
'new' : function(settings){
var object = {};
if(settings.hasOwnProperty('constructor')){
object= new settings.constructor(engine);
}else if(settings.builder && settings.nameSpace){
engine[settings.nameSpace]= {};
object= function(){
return settings.builder(engine[settings.nameSpace], this.arguments);
};
}else if(settings.builder){
object= settings.builder;
}else{
object= settings.object;
}
engine.deviceReady.then(function(){
var object = {};
if(settings.hasOwnProperty('constructor')){
object= new settings.constructor(engine);
}else if(settings.builder && settings.nameSpace){
engine[settings.nameSpace]= {};
object= function(){
return settings.builder(engine[settings.nameSpace], this.arguments);
};
}else if(settings.builder){
object= settings.builder;
}else{
object= settings.object;
}

if(settings.name && !items[settings.name])
items[settings.name]= object;
else
$$.console.error("No or ilegall name!");
if(settings._init){
if(settings.nameSpace)
settings._init(engine[settings.nameSpace], settings.object);
else
settings._init(settings.object);
}
if(settings.nameSpace)
return engine[settings.nameSpace];
return null;
},
if(settings.name && !items[settings.name])
items[settings.name]= object;
else
$$.console.error("No or ilegall name!");
if(settings._init){
if(settings.nameSpace)
settings._init(engine[settings.nameSpace], settings.object);
else
settings._init(settings.object);
}
if(settings.nameSpace)
return engine[settings.nameSpace];
return null;
});
},
queue : {
push : function(object){
var push= function(){
Expand Down Expand Up @@ -353,13 +355,15 @@ var prepareScope= function(item){
'module' : {
value : function(name, dependencies, f){
var request= new $$.Promise(function(success, failure){
if(dependencies.length > 0){
scope.properties.modules.on('available', dependencies).then(function(){
f(scope.properties, success, failure);
});
}else{
f(scope.properties, success, failure);
}
engine.deviceReady.then(function(){
if(dependencies.length > 0){
scope.properties.modules.on('available', dependencies).then(function(){
f(scope.properties, success, failure);
});
}else{
f(scope.properties, success, failure);
}
});
});
scope.modules.push(request);
request.then(function(value){
Expand Down Expand Up @@ -573,20 +577,22 @@ var engine = {
push : function(scope){
if(!this.isRunning){
this.isRunning= true;
if(settings.renderMode == 'default'){
if(scope.modules.length > 0){
$$.Promise.all(scope.modules).then(function(){
engine.deviceReady.then(function(){
if(settings.renderMode == 'default'){
if(scope.modules.length > 0){
$$.Promise.all(scope.modules).then(function(){
scope.thread.apply(scope.properties, [scope]);
});
}else{
scope.thread.apply(scope.properties, [scope]);
});
}else{
scope.thread.apply(scope.properties, [scope]);
}
}
}

if(this.queue.length > 0){
var n= this.queue[0]; this.queue.shift();
this.push(n);
}
if(this.queue.length > 0){
var n= this.queue[0]; this.queue.shift();
this.push(n);
}
}.bind(this));
this.isRunning= false;
}else{
this.queue.push(scope);
Expand All @@ -597,6 +603,13 @@ var engine = {
lastAddonComId : 0,
pushListeners : [],
launchQueue : [],
deviceReady : new Promise(function(ready){
if($$.cordova){
$$.document.addEventListener('deviceready', ready, false);
}else{
ready();
}
}),
exit : function(){}
};

Expand All @@ -609,7 +622,7 @@ if ($$.navigator && !$$.importScripts){
// Mozilla
platform= (((platform.indexOf('Gecko/') > -1) && 'Gecko '+platform.substring(platform.indexOf('rv:')+3, platform.indexOf(')')) ) || false) ||
// Google / Apple / Opera
(((platform.indexOf('AppleWebKit') > -1) && platform.substring(platform.indexOf('AppleWebKit'), platform.lastIndexOf('(')-1).replace(/\//, ' ')) || false) ||
(((platform.indexOf('AppleWebKit') > -1) && (platform= platform.substring(platform.indexOf('AppleWebKit'))) && platform.substring(0, platform.indexOf('(')-1).replace(/\//, ' ')) || false) ||
// Microsoft
(((platform.indexOf('Trident/') > -1) && platform.substring(platform.indexOf('Trident/'), platform.indexOf(';', platform.indexOf('Trident/'))).replace(/\//, ' ')) || false) ||
// Unknown
Expand All @@ -623,7 +636,7 @@ if ($$.navigator && !$$.importScripts){
// Mozilla
platform= (((platform.indexOf('Gecko/') > -1) && 'Gecko '+platform.substring(platform.indexOf('rv:')+3, platform.indexOf(')')) ) || false) ||
// Google / Apple / Opera
(((platform.indexOf('AppleWebKit') > -1) && platform.substring(platform.indexOf('AppleWebKit'), platform.lastIndexOf('(')-1).replace(/\//, ' ')) || false) ||
(((platform.indexOf('AppleWebKit') > -1) && (platform= platform.substring(platform.indexOf('AppleWebKit'))) && platform.substring(0, platform.indexOf('(')-1).replace(/\//, ' ')) || false) ||
// Microsoft
(((platform.indexOf('Trident/') > -1) && platform.substring(platform.indexOf('Trident/'), platform.indexOf(';', platform.indexOf('Trident/'))).replace(/\//, ' ')) || false) ||
// Unknown
Expand Down
108 changes: 106 additions & 2 deletions modules/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@ $('new')({
this.busy= false;
this.step= 0;
this.status= 'notstarted';
}
},
URL : function(urlString){
this._h= '';
this._p= '';
this._pa= '';
this._u= '';
this._pat= '';
this._hr= urlString;

this.parse(urlString);
}
},
_init : function(me){
"use strict";
Expand Down Expand Up @@ -60,7 +70,7 @@ $('new')({
}
};
me.AsyncLoop.prototype= {
'while' : function(condition, $){
'while' : function(condition){
this.busy= true;
var loop= this;

Expand Down Expand Up @@ -141,5 +151,99 @@ $('new')({
next();
}
};

me.URL.prototype= {
parse : function(urlString){
// parse URL
if(urlString.indexOf('//')){
this._p= urlString.substring(0, urlString.indexOf('//'));
urlString.substr(urlString.indexOf('//')+2);
}

var hostPart= urlString.substring(0, urlString.indexOf('/'));
urlString= urlString.substr(urlString.indexOf('/'));
if(hostPart.indexOf('@')){
var userPart= hostPart.split('@')[0];
this._h= hostPart.split('@')[1];
this._u= userPart.split(':')[0];
this._pa= userPart.split(':')[1] || '';
}
this._h= hostPart;
this._pat= urlString;
},

asemble : function(){
var path= '';
if(this._p !== '')
path+= this._p+'//';

if(this._u !== ''){
path+= this._u;
path+= (this._pa !== '') ? ':'+this._pa+'@' : '@';
}

if(this._h)
path+= this._h;

if(this._pat)
path+= this._pat;

this._hr= path;
},

get protocol(){
return this._p;
},

set protocol(value){
this._p=value;
this.asemble();
},

get host(){
return this._h;
},

set host(value){
this._h= value;
this.asemble();
},

get username(){
return this._u;
},

set username(value){
this._u= value;
this.asemble();
},

get password(){
return this._pa;
},

set password(value){
this._pa= value;
this.asemble();
},

get path(){
return this._pat;
},

set path(value){
this._pat= value;
this.asemble();
},

get href(){
return this._hr;
},

set href(value){
this._hr= value;
this.parse(this._hr);
}
};
}
});
Loading

0 comments on commit ec630e6

Please sign in to comment.