|
楼主 |
发表于 2016-5-3 16:39:59
|
显示全部楼层
本帖最后由 我是猿 于 2016-5-3 16:46 编辑
我发不了文件,只能全部贴上去了。用模式2打包,web路径是http://n.andtedh.net:8090
/*!
* WeX5 v3 (http://www.justep.com)
* Copyright 2015 Justep, Inc.
* Licensed under Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/
define(function(require){
var $=require('jquery'),
Object = require("$UI/system/lib/base/object"),
Observable = require("$UI/system/lib/base/observable"),
URL = require('$UI/system/lib/base/url'),
Browser = require('$UI/system/lib/base/browser'),
_history = window.history,
HashbangParser = require('./hashbangParser'),
_lastChangeTimeStamp = new Date().getTime();
var HashbangToken = "#!",
StateSeriesSplitToken = "!",
LeftBarcketToken = "(",
RightBarcketToken = ")",
SegmentSplitToken = "/";
function ignoreVLS(url){
return URL._removeVLS(url);
};
function convertToOldUrl(){
var oldUrl = new URL(window.__justep.__ResourceEngine.url);
var path = oldUrl.getPathname();
var currentUrl = new URL(location.href);
var search = currentUrl.getSearch();
var hash = currentUrl.getHash();
return path + search + hash;
};
var isSimulator = false;
try{
isSimulator = window.parent && window.parent.getOSName;
}catch(err){
}
var Router = Object.extend({
mixin:Observable,
constructor: function(){
this.callParent();
Observable.prototype.constructor.call(this);
this.checkRedirectParam();
this.interceptLinkHash();
this.polyfillStateApi();
this.originUrl = location.href;
this.ignoreVls();
this.subscribeState();
}
});
Router.prototype.checkRedirectParam = function(){
var currentUrl = new URL(location.href);
if(currentUrl.getParam('_shareHash')){
var _shareHash = currentUrl.getParam('_shareHash');
currentUrl.setHash(_shareHash);
currentUrl.removeParam('_shareHash');
this.publishState({
isReplace:true,
hashbang:currentUrl.toString()
});
}
};
Router.prototype.polyfillStateApi = function(){
if(typeof _history.pushState != 'function'){
_history.pushState = function(){};
_history.replaceState = function(){};
}
};
Router.prototype.revertVls = function(){
if(!Browser.isWeChat && !isSimulator){
var url = convertToOldUrl();
this.publishState({
isIgnoreVersionPublish:true,
isReplace:true,
hashbang:url
});
}
};
Router.prototype.ignoreVls = function(){
if(!Browser.isWeChat && !isSimulator){
var ignoreVersionUrl = ignoreVLS(location.pathname + location.search) + location.hash;
this.publishState({
isIgnoreVersionPublish:true,
isReplace:true,
hashbang:ignoreVersionUrl
});
}
};
Router.prototype.interceptLinkHash = function(){
var self = this;
$(document).on('click.routeState','a',function(event){
var href = $(event.currentTarget).attr('href');
if(href && href.indexOf('#!') == 0){
event.preventDefault();
//debugger;
var bindingContext = justep.Bind.contextFor(event.target);
if(bindingContext){
var $model = bindingContext.$model;
if($model){
$model.fireEvent('onRouteStatePublish',{
hashbang: href,
isReplace:false
});
$model.postMessage({
type:"routeState",
newUrl:href
});
}
}
}else if(href && href == '#'){
event.preventDefault();
}
});
};
Router.prototype.subscribeState = function(){
$(window).on('hashchange',$.proxy(function(event){
_lastChangeTimeStamp = new Date().getTime();
var e = event.originalEvent;
var newUrl = e.newURL;
var oldUrl = e.oldURL;
if(newUrl == undefined){
newUrl = location.href;
}
this.dispatchChange(newUrl,oldUrl);
},this));
};
Router.prototype.dispatchChange = function(newUrl,oldUrl){
this.rootModel.postMessage({
type:"routeState",
oldUrlldUrl,
newUrl:newUrl
});
};
Router.prototype.publishState = function(event){
var currentTimeStamp = new Date().getTime();
var isReplace = event.isReplace;
if(currentTimeStamp - _lastChangeTimeStamp < 800){
isReplace = true;
}
var hashbang = event.hashbang;
if(hashbang == "" || hashbang === HashbangToken){
if(typeof justep.Portal.getPortal() !== "undefined"){
return;
}else{
hashbang = "";
}
}
if(isReplace){
this.publishState._lastState = hashbang;
try{_history.replaceState(null,null,hashbang);}catch(e){console.log(e);}
}else{
if(this.publishState._lastState !== hashbang){
this.publishState._lastState = hashbang;
_lastChangeTimeStamp = currentTimeStamp;
_history.pushState(null,null,hashbang);
}
}
};
Router.prototype.setRootModel = function(model){
var self = this;
if(typeof this.rootModel == 'undefined'){
this.rootModel = model;
this.rootModel.on('onRouteStatePublish',function(event){
this.publishState(event);
},this);
var originHref = location.href;
//第一次进来理解url
this.rootModel.on('onLoaded',function(event){
self.dispatchChange(originHref,'');
},this);
}
};
return new Router();
});
这个问题非常急,麻烦您帮忙解决一下了 |
|