Skip to content

Commit

Permalink
Update to version 0.9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
StefansArya committed Jan 24, 2019
1 parent 34da1f8 commit 099815d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 47 deletions.
94 changes: 49 additions & 45 deletions dist/scarletsframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,10 @@ sf.model = function(scope){
firstTime = false;
}

// Remove var because no variable are being passed
if(firstTime === true)
strDeclare = strDeclare.replace('var ', '');

// Disable function call for addional security eval protection
strDeclare = strDeclare.split('(').join('').split(')').join('');

Expand Down Expand Up @@ -608,12 +612,15 @@ sf.model = function(scope){
check = temp.split('@if ');
if(check.length != 1){
check = check[1].split(':');
var scopes = [check[0], _model_, _modelScope, _content_];

// If condition was meet
if(localEval.apply(self.root, [check[0], _model_, _modelScope, _content_])){
check.shift();
return check.join(':');
}
// If condition was not meet
if(localEval.apply(self.root, scopes) == false)
return '';

check.shift();
scopes.splice(0, 1, check.join(':').split('&VarPass&').join('{}'));
return localEval.apply(self.root, scopes);
}

// Get defined variables
Expand Down Expand Up @@ -931,6 +938,7 @@ sf.model = function(scope){
content = content.replace(/ +|\t+/g, '');

if(method.length === 2){
var temp = '';
for(var i in items){
var item = items[i];

Expand Down Expand Up @@ -1412,9 +1420,6 @@ sf.router = new function(){
self.init();
});

// Reinit lazy router
self.lazy();

// Run 'before' event for new page view
$('[sf-controller], [sf-page]', $(targetNode)[0]).each(function(){
if(this.attributes['sf-controller'])
Expand All @@ -1430,31 +1435,33 @@ sf.router = new function(){
currentRouterURL = window.location.pathname;
}

function popstateListener(event) {
// Don't continue if the last routing was error
if(routingError){
routingError = false;
return;
}

routingBack = true;
self.goto(window.location.pathname);
}

self.enable = function(status){
if(status === undefined) status = true;
if(self.enabled === status) return;
self.enabled = status;

if(status)
self.lazy();
if(status === true){
// Create listener for link click
$(document.body).on('click', 'a[href]', self.load);

// Create listener when navigate backward
window.addEventListener('popstate', popstateListener, false);
}
else{
$('a[href][onclick]').each(function(){
var current = $(this);
if(current.attr('onclick') === 'return sf.router.load(this)')
current.removeAttr('onclick');
});
$(document.body).off('click', 'a[href]', self.load);
window.removeEventListener('popstate', popstateListener, false);
}

window.addEventListener('popstate', function(event) {
// Don't continue if the last routing was error
if(routingError){
routingError = false;
return;
}

routingBack = true;
self.goto(window.location.pathname);
}, false);
}

var before = {};
Expand Down Expand Up @@ -1538,26 +1545,23 @@ sf.router = new function(){
}
}
*/
self.lazy = function(){
if(!self.enabled) return;

$('a[href]:not([onclick])').each(function(){
var url = this.href;
if(url.indexOf('#') !== -1)
return;
self.load = function(ev){
if(self.enabled !== true) return;

if(url.indexOf(window.location.origin) !== 0 && url.charAt(0) !== '/')
return; //Not current domain origin
var elem = ev.target;
if(!elem.href) return;

$(this).attr('onclick', 'return sf.router.load(this)');
});
}
if(!history.pushState || elem.hasAttribute('sf-router-ignore'))
return;

self.load = function(elem){
if(!history.pushState || $(elem).attr('sf-router') == 'ignore')
return true;
// Make sure it's from current origin
var path = elem.href.replace(window.location.origin, '');
if(path.indexOf('//') !== -1)
return;

return !self.goto(elem.href.replace(window.location.origin, ''));
ev.preventDefault()
return !self.goto(path);
}

var RouterLoading = false;
Expand All @@ -1567,6 +1571,8 @@ sf.router = new function(){
if(!method) method = 'GET';
else method = method.toUpperCase();

if(!data) data = {};

for (var i = 0; i < onEvent['loading'].length; i++) {
if(onEvent['loading'][i](path)) return;
}
Expand Down Expand Up @@ -1641,9 +1647,6 @@ sf.router = new function(){
}
}

// Reinit lazy router
self.lazy();

// Run 'before' event for new page view
if(!DOMReference) DOMReference = $(document.body);
if(self.pauseRenderOnTransition)
Expand Down Expand Up @@ -2228,8 +2231,9 @@ sf.internal.virtual_scroll = new function(){
refreshScrollBounding(index, virtual.bounding, list, parentNode);

temp = parentNode.children[prepareCount - reduce + 1];

if(temp !== undefined)
scroller.scrollTop = temp.offsetTop;
scroller.scrollTop = temp.offsetTop - scroller.offsetTop;
}

scrollingByScript = false;
Expand Down
Loading

0 comments on commit 099815d

Please sign in to comment.