1 Star 0 Fork 38

apple006 / EasyWebApp

forked from 南漂一卒 / EasyWebApp 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
EasyWebApp.js 30.92 KB
一键复制 编辑 原始数据 按行查看 历史
南漂一卒 提交于 2016-09-23 15:50 . 【同步】更新开源基础库
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
(function () {
if ((typeof this.define != 'function') || (! this.define.amd))
arguments[0]();
else
this.define('EasyWebApp', ['iQuery+'], arguments[0]);
})(function () {
var ViewDataIO = (function (BOM, DOM, $) {
function ArrayRender(iArray, ValueRender) {
$.ListView(this, function () {
ValueRender.call(arguments[0], arguments[1]);
}).clear().render( iArray );
}
function ObjectRender(iData) {
var _Self_ = arguments.callee;
if ($.likeArray( iData ))
return ArrayRender.call(this[0], iData, _Self_);
var iView = $.CommonView.instanceOf(this, false);
if (iView) return iView.render(iData);
this.value('name', function (iName) {
if ($.likeArray( iData[iName] ))
ArrayRender.call(this, iData[iName], _Self_);
else if ($.isPlainObject( iData[iName] ))
_Self_.call($(this), iData[iName]);
else
return iData[iName];
});
}
$.fn.extend({
dataRender: function (iData) {
if ($.likeArray( iData ))
ArrayRender.call(
$.ListView.findView(this, true)[0], iData, ObjectRender
);
else
ObjectRender.call(this, iData);
return this;
},
dataReader: function () {
var $_Key = $('[name]', this[0]).not( $('[name] [name]', this[0]) ),
iData = { };
if (! $_Key[0]) return this.value();
for (var i = 0, iName, iLV; i < $_Key.length; i++) {
iName = $_Key[i].getAttribute('name');
iLV = $.ListView.instanceOf($_Key[i], false);
if (! iLV)
iData[iName] = arguments.callee.call( $( $_Key[i] ) );
else {
iData[iName] = [ ];
for (var j = 0; j < iLV.length; j++)
iData[iName][j] = $.extend(
iLV.valueOf(j), arguments.callee.call( iLV[j] )
);
}
}
return iData;
}
});
})(self, self.document, self.jQuery);
var PageLink = (function (BOM, DOM, $) {
/* ---------- [object PageLink] ---------- */
function PageLink(This_App, Link_DOM, iArgument, iData) {
this.ownApp = This_App;
this.$_DOM = $.isPlainObject(Link_DOM) ?
this.createDOM(Link_DOM, iArgument, iData) :
$(Link_DOM);
var _Self_ = arguments.callee, iLink = this.$_DOM.data('EWA_PageLink');
if (iLink instanceof _Self_) return iLink;
this.$_DOM.data('EWA_PageLink', this).css('cursor', 'pointer');
$.extend(this, _Self_.getAttr(this.$_DOM));
switch (this.target) {
case '_top': this.type = 'Outer'; break;
case '_blank': this.type = 'Data'; break;
case '_self': ;
default: if (this.href) this.type = 'Inner';
}
this.method = (this.method || 'Get').toLowerCase();
this.data = { };
this.href = this.href || this.ownApp.history.last().HTML;
this.href = this.getURL('href');
var iFileName = $.fileName( this.href ).split('.');
$.extend(this.data, {
_File_Path_: $.filePath( this.href ),
_File_Name_: iFileName[0],
_Ext_Name_: iFileName[1]
});
if (this.src)
$.extend(this.data, {
_Data_Path_: $.filePath(this.src),
_Data_Name_: $.fileName(this.src)
});
if ((this.href || '').indexOf('?') > -1)
this.data = $.extend($.paramJSON(this.href), this.data);
}
$.extend(PageLink, {
getAttr: function () {
return arguments[0].attr([
'target', 'title', 'alt', 'href', 'method', 'src', 'action'
]);
},
prefetchRel: $.browser.modern ? 'prefetch' : 'next',
prefetchClear: function () {
$('head link[rel="' + this.prefetchRel + '"]').remove();
}
});
$.extend(PageLink.prototype, {
createDOM: function (iAttribute, iArgument, iData) {
var _Argument_ = { };
if ( $.isPlainObject(iArgument) )
for (var iName in iArgument)
_Argument_['data-' + iName] = iArgument[iName];
var $_Link = $('<button />', $.extend({
rel: 'nofollow',
css: {display: 'none'}
}, iAttribute, _Argument_)).appendTo(DOM.body);
if ($.likeArray(iData) || $.isPlainObject(iData))
$_Link.data('EWA_Model', iData);
return $_Link;
},
getData: function () {
var iData = this.$_DOM.data('EWA_Model');
if (! iData) {
var $_Item = this.$_DOM.hasClass('ListView_Item') ?
this.$_DOM : this.$_DOM.parents('.ListView_Item');
if ( $_Item[0] )
iData = $.ListView.instanceOf( $_Item ).valueOf( $_Item );
}
return this.data = $.extend(iData || { }, this.data);
},
getArgs: function () {
var iData = $.extend(this.ownApp.history.getData(), this.getData());
return $.map(this.$_DOM[0].dataset, function (iName) {
if (
((Number(iName) % 1) !== 0) &&
(iData[iName] !== undefined)
)
return iData[iName];
return iName;
});
},
getURL: function (iKey) {
if (! this[iKey]) return '';
if ((iKey != 'href') || (this[iKey][0] != '#')) {
this[iKey] = this.ownApp.makeURL(
this[iKey] || '',
this.getData(),
((iKey == 'href') ? (! this.src) : (
this.method.toUpperCase() == 'GET'
)) && this.getArgs()
);
if ((iKey == 'href') && (this[iKey].slice(-1) == '?'))
this[iKey] = this[iKey].slice(0, -1);
}
return this[iKey];
},
valueOf: function () {
var iValue = { };
for (var iKey in this)
if (! (typeof this[iKey]).match(/object|function/))
iValue[iKey] = this[iKey];
return iValue;
}
});
return PageLink;
})(self, self.document, self.jQuery);
var InnerPage = (function (BOM, DOM, $, PageLink) {
/* ---------- [object InnerPage] ---------- */
function InnerPage(App_Instance, iLink) {
$.extend(this, {
ownerApp: App_Instance,
sourceLink: iLink,
title: iLink.title || DOM.title,
URL: iLink.alt || BOM.location.href,
HTML: iLink.href || DOM.URL,
method: iLink.method,
JSON: iLink.src || iLink.action,
time: $.now(),
innerLink: [ ]
});
}
$.extend(InnerPage.prototype, {
show: function ($_Page) {
$_Page = $_Page ? $($_Page) : this.$_Page;
var iHistory = this.ownerApp.history;
var iForward = iHistory.isForward(this);
if (! $_Page) {
if (this.sourceLink.type != 'Inner')
BOM.setTimeout(function () {
BOM.history[iForward ? 'forward' : 'back']();
});
else {
this.sourceLink = new PageLink(
this.ownerApp, this.sourceLink.valueOf()
);
this.sourceLink.$_DOM[0].click();
}
return this;
}
var $_Target = this.sourceLink.getTarget();
if (iHistory.length || iForward) iHistory.move( $_Target );
this.$_Page = $_Page.appendTo( $_Target ).fadeIn();
if (! arguments.length) {
var Link_DOM = iHistory.last(true).sourceLink.$_DOM[0];
var iListView = $.ListView.instanceOf( Link_DOM );
if (iListView)
iListView.focus(Link_DOM);
else
Link_DOM.scrollIntoView();
}
return this;
},
valueOf: PageLink.prototype.valueOf
});
return InnerPage;
})(self, self.document, self.jQuery, PageLink);
var InnerHistory = (function (BOM, DOM, $, InnerPage) {
/* ---------- [object InnerHistory] ---------- */
function InnerHistory() {
var _This_ = $.extend(this, {
length: 0,
ownerApp: arguments[0],
root: arguments[1],
lastIndex: -1
});
$(BOM).on('popstate', function () {
var iState = arguments[0].state;
var _Index_ = (iState || { }).DOM_Index;
var iHistory = _This_[_Index_];
if (! iHistory)
return BOM.history.go(_This_[_Index_ - 1] ? -1 : 1);
_This_.move(iState);
iHistory.show().onReady();
_This_.prevIndex = _This_.lastIndex;
_This_.lastIndex = iState.DOM_Index;
});
}
$.extend(InnerHistory.prototype, {
splice: Array.prototype.splice,
push: Array.prototype.push,
slice: Array.prototype.slice,
indexOf: Array.prototype.indexOf,
move: function () {
if ($.isPlainObject( arguments[0] ))
var iState = arguments[0];
else {
var $_Target = arguments[0];
$.ListView.findView(this.root, true);
}
var $_Page = ($_Target || this.root).children().detach();
if ((! iState) || ((iState.DOM_Index + 2) == this.length))
this[this.length - 1].$_Page =
this[this.length - 1].$_Page || $_Page;
return $_Page;
},
write: function () {
this.prevIndex = this.lastIndex++ ;
this.splice(this.lastIndex, this.length);
var iNew = new InnerPage(this.ownerApp, arguments[0] || { });
this.push(iNew);
iNew.$_Page = (this.cache() || { }).$_Page;
BOM.history.pushState(
{DOM_Index: this.lastIndex},
iNew.title,
iNew.URL
);
return iNew;
},
cache: function () {
var iNew = this[this.lastIndex];
for (var i = 0; i < this.lastIndex; i++)
if ((iNew.time - this[i].time) > (this.ownerApp.cache * 1000)) {
if (! this[i].sourceLink.action) this[i].$_Page = null;
} else if (
(! iNew.JSON) &&
$.isEqual(iNew.sourceLink, this[i].sourceLink)
)
return this[i];
},
last: function () {
var iPage = this[this.lastIndex] || { };
return arguments[0] ? iPage : iPage.valueOf();
},
prev: function () {
var iPage = this[this.prevIndex] || { };
return arguments[0] ? iPage : iPage.valueOf();
},
isForward: function () {
return (
this.indexOf( arguments[0] ) > this.indexOf( this.last(true) )
);
},
mergeData: function (iSource, Index) {
var iPage = this.slice(Index, (Index + 1) || undefined)[0];
iPage.data = $.extend(
iPage.data || { },
(iSource instanceof $) ?
$.paramJSON('?' + iSource.serialize()) : iSource
);
return iSource;
}
});
return InnerHistory;
})(self, self.document, self.jQuery, InnerPage);
var WebApp = (function (BOM, DOM, $, PageLink, InnerPage, InnerHistory) {
function Data_Merge(iOld, iNew) {
var iArgs = $.makeArray(arguments);
iArgs.unshift(true);
if ($.likeArray( iArgs.slice(-1)[0] )) iArgs.splice(1, 0, [ ]);
return $.extend.apply($, iArgs);
}
InnerHistory.prototype.getData = function () {
var iData = $.map(this, function (iPage) {
var _Data_ = iPage.data || iPage.sourceLink.data;
return _Data_ && [_Data_];
});
return (iData.length < 2) ?
(iData[0] || { }) : Data_Merge.apply(null, iData);
};
/* ---------->> WebApp Constructor <<---------- */
function WebApp($_Root, API_Root, Cache_Second, URL_Change) {
$.Observer.apply(this);
$.extend(this, {
domRoot: $($_Root),
apiRoot: API_Root || '',
cache:
(Cache_Second || (Cache_Second == 0)) ?
Cache_Second : Infinity,
urlChange: URL_Change,
history: new InnerHistory(this, $_Root),
loading: false,
innerTemplate: { }
});
}
WebApp.prototype = new $.Observer();
WebApp.prototype.constructor = WebApp;
var RE_Str_Var = /\{(.+?)\}/g;
$.extend(WebApp.prototype, {
makeURL: function (iURL, iData, iArgs) {
iURL = $.split(iURL, '?', 2);
iData = $.extend(this.history.getData(), iData || { });
var iJSONP = ('&' + iURL[1]).match(/&([^=]+)=\?/);
iJSONP = iJSONP && iJSONP[1];
var URL_Param = $.param(
$.extend(
$.paramJSON('?' + iURL[1].replace(iJSONP + '=?', '')),
iArgs || { }
)
);
iURL = [
BOM.decodeURIComponent(iURL[0]).replace(RE_Str_Var, function () {
return iData[arguments[1]];
}),
(! iJSONP) ? URL_Param : [
URL_Param, URL_Param ? '&' : '', iJSONP, '=?'
].join('')
].join('?');
if (! (
iURL.match(/^(\w+:)?\/\/[\w\d]+/) ||
$.fileName(iURL).match(/\.(htm|html|md|markdown)$/)
))
iURL = this.apiRoot + iURL;
return iURL;
},
getTemplate: function (DOM_ID) {
if (DOM_ID)
return this.innerTemplate[DOM_ID].children().clone(true);
var $_Link = $('body *[target="_self"][href^="#"]');
for (var i = 0; $_Link[i]; i++) {
DOM_ID = $_Link[i].getAttribute('href').slice(1);
if (this.innerTemplate[DOM_ID]) continue;
this.innerTemplate[DOM_ID] =
$(DOM.getElementById(DOM_ID)).detach();
$.ListView.findView(this.innerTemplate[DOM_ID], false);
}
return this;
}
});
function Trig_Event() {
var This_Page = this.history.last();
return this.trigger(
arguments[0], This_Page.HTML, This_Page.JSON, arguments[1]
).slice(-1)[0];
}
/* ---------- Auto Navigation ---------- */
$.extend(PageLink.prototype, {
getTarget: function () {
return this.target.match(/^_(self|blank)$/) ?
this.ownApp.domRoot : $('[name="' + this.target + '"]');
},
prefetch: function () {
var iHTML = (this.href || '').split('?');
if (
(this.target == '_self') &&
((iHTML[1] || '').indexOf('=') == -1)
) {
var $_Prefetch = $('<link />', {
rel: this.constructor.prefetchRel,
href: this.href
});
if (
this.method.match(/Get/i) &&
(this.src && (! this.src.match(RE_Str_Var))) &&
$.isEmptyObject( this.$_DOM[0].dataset )
)
$_Prefetch.add(
$('<link />', {
rel: this.constructor.prefetchRel,
href: this.getURL('src')
})
);
$_Prefetch.appendTo(DOM.head);
}
return this;
},
loadData: function (Data_Ready) {
var $_Form = $(this.$_DOM).parents('form').eq(0);
if ($_Form.length)
this.ownApp.history.mergeData($_Form, -1);
var iLink = this, This_App = this.ownApp,
API_URL = this.getURL('src');
function AJAX_Ready(iData) {
iData = Trig_Event.call(This_App, 'apiCall', [
{
method: iLink.method,
URL: API_URL || iLink.getURL('action'),
data: iData
},
This_App.history.last().HTML,
This_App
]) || iData;
if (typeof Data_Ready == 'function')
Data_Ready.call(iLink, iData);
else
This_App.history.mergeData(iData, -1);
}
if (! API_URL) return AJAX_Ready.call(this, this.getData());
switch (this.method) {
case 'get': $[this.method](API_URL, AJAX_Ready); break;
case 'post': ;
case 'put': ;
case 'delete':
$[this.method](API_URL, this.getArgs(), AJAX_Ready);
}
}
});
$.extend(InnerPage.prototype, {
boot: function (iRender) {
var This_Page = this,
$_Page = $('head link[target][href]'),
$_API = $('head link[src]');
this.ownerApp.getTemplate();
if ( $_Page.length )
this.ownerApp.one('pageReady', function () {
return arguments[2].loadLink(
$_Page.remove().attr(['target', 'href']),
null,
This_Page.sourceLink.getData()
);
});
if (! $_API.length) return iRender.call(this);
var iData = { }, Data_Ready = $_API.length;
function API_Load(_Data_) {
iData = Data_Merge(iData, _Data_);
if (--Data_Ready > 0) return;
iRender.call(This_Page, iData);
$_API.remove();
}
for (var i = 0; i < $_API.length; i++)
(new PageLink(this.ownerApp, $_API[i])).loadData(API_Load);
},
load: function (iLink, Page_Load) {
var MarkDown_File = /\.(md|markdown)\??/i,
This_Page = this, This_App = this.ownerApp;
if (iLink.href[0] == '#')
return Page_Load.call(
this.show(This_App.getTemplate( iLink.href.slice(1) )).ownerApp
);
$.get(iLink.getURL('href'), (! iLink.href.match(MarkDown_File)) ?
function (iHTML) {
iHTML = (arguments[2] || '').responseText || iHTML;
if (! (
iHTML.match(/<\s*(html|head|body)(\s|>)/i) ||
iHTML.match(/<\s*(link|script)(\s|>)/i)
))
return This_Page.show(iHTML).boot(Page_Load);
var $_Content = $(iHTML.children || iHTML), $_Page = [ ];
for (var i = 0, j = 0; $_Content[i]; i++)
switch ( $_Content[i].tagName.toLowerCase() ) {
case 'link': {
if ($_Content[i].rel == 'stylesheet')
$('<link rel="stylesheet" />')
.attr('href', $_Content[i].href)
.appendTo( DOM.head );
else if ($_Content[i].getAttribute('target'))
DOM.head.appendChild( $_Content[i] );
break;
}
case 'script': {
if ( $_Content[i].text.trim() )
$.globalEval( $_Content[i].text );
break;
}
default: $_Page[j++] = $_Content[i];
}
This_Page.show($_Page).boot(Page_Load);
} :
function (iMarkDown) {
iMarkDown = (arguments[2] || '').responseText || iMarkDown;
if (typeof BOM.marked == 'function')
This_Page.show( BOM.marked(iMarkDown) ).$_Page
.find('a[href]').attr('target', function () {
if (! (
this.href.indexOf('#!') ||
this.matches('a[rel*="nofollow"]')
)) {
this.setAttribute('rel', 'nofollow');
return arguments[1];
}
return this.href.match(MarkDown_File) ?
'_self' : '_top';
});
else
This_App.domRoot.text(iMarkDown);
Page_Load.call(This_App);
}
);
}
});
$.extend(PageLink.prototype, {
loadTemplate: function () {
var iReturn = Trig_Event.call(this.ownApp, 'pageLoad', [
this.ownApp.history.last(),
this.ownApp.history.prev()
]);
if (iReturn === false) return;
this.ownApp.loading = true;
/* ----- Load DOM from Cache ----- */
var This_Page = this.ownApp.history.write(this);
if (this.ownApp.cache && This_Page.$_Page)
return This_Page.show().onReady();
/* ----- Load DOM from Network ----- */
var iData, Need_HTML = (this.type == 'Inner');
var Load_Stage = Need_HTML ? 2 : 1, This_Link = this;
function Page_Load() {
if (arguments[0]) iData = arguments[0];
if (--Load_Stage != 0) return;
This_Page.render(This_Link, iData).onReady();
}
this.loadData(Page_Load);
if (Need_HTML) This_Page.load(this, Page_Load);
},
loadPage: function () {
var iReturn = Trig_Event.call(this.ownApp, 'appExit', [
this.ownApp.history.last().HTML,
this.href,
this.getData()
]);
if (iReturn === false) return;
this.ownApp.history.move();
BOM.sessionStorage.EWA_Model = BOM.JSON.stringify(
$.isPlainObject(iReturn) ? iReturn : this.getData()
);
BOM.location.href = this.href + '?' + $.param( this.getArgs() );
}
});
$.extend(InnerPage.prototype,{
render: function (Source_Link, iData) {
var This_App = this.ownerApp;
iData = Data_Merge(Source_Link && Source_Link.getData(), iData);
var iReturn = Trig_Event.call(This_App, 'pageRender', [
This_App.history.last(),
This_App.history.prev(),
iData
]);
this.data = iData = iReturn || iData;
if (iReturn !== false) {
var $_Render = This_App.domRoot;
if (! $.likeArray(iData))
$_Render = $(DOM.body);
else if (Source_Link && (Source_Link.target != '_self'))
$_Render = Source_Link.getTarget().parent();
$_Render.dataRender(iData);
}
return this;
},
findLink: function (iPrefetch) {
var $_Root = this.ownerApp.history.lastIndex ?
this.ownerApp.domRoot : $(DOM.body);
var $_Link = $_Root.find('*[target]').not(
$.ListView.findView($_Root).find('*[target]')
);
for (var i = 0, iLink; i < $_Link.length; i++) {
iLink = new PageLink(this.ownerApp, $_Link[i]);
this.innerLink.push(iLink);
if (iPrefetch) iLink.prefetch();
}
return $_Link;
},
onReady: function () {
$('button[target]:hidden', DOM.body).remove();
var This_App = this.ownerApp;
PageLink.prefetchClear();
This_App.loading = false;
Trig_Event.call(This_App, 'pageReady', [
This_App.history.last(),
This_App.history.prev(),
This_App
]);
this.findLink(true);
This_App.domRoot.focus();
$(DOM.body).trigger({
type: 'loading',
detail: 1
});
return this;
}
});
/* ---------- Manual Navigation ---------- */
WebApp.prototype.loadLink = function (iAttribute, iArgument, iData) {
if (typeof iAttribute == 'string') {
iAttribute = {
target: '_self',
href: iAttribute,
src: iArgument,
};
iArgument = iData;
iData = arguments[3];
}
this.loading = false;
(
(iAttribute instanceof PageLink) ? iAttribute : (
new PageLink(this, iAttribute, iArgument, iData)
)
).$_DOM.click();
return this;
};
function Hash_Path_Load() {
var iHash = $.split(BOM.location.hash, '!', 2);
if ((iHash[0] != '#') || (! iHash[1])) return;
this.findLink();
var $_Link = $('*[target="_self"][href="' + iHash[1] + '"]');
if ($_Link[0])
$_Link[0][
($_Link[0].tagName.toLowerCase() != 'form') ?
'click' : 'submit'
]();
else
this.ownerApp.loadLink(iHash[1]);
return iHash[1];
}
WebApp.prototype.boot = function () {
if (this.history.length) throw 'This WebApp has been booted !';
this.loading = true;
var This_Link = new PageLink(this, {target: ''}, null, arguments[0]);
var This_Page = this.history.write(This_Link, This_Link.getTarget()),
This_App = this;
$(DOM.body).on('submit', 'form:visible', function () {
if (This_App.loading) return false;
var iLink = $(this).data('EWA_PageLink') ||
(new PageLink(This_App, this));
This_App.history.mergeData(iLink.$_DOM, -1).attr(
'action', iLink.getURL('action')
);
}).ajaxSubmit(function (iData) {
var iReturn = Trig_Event.call(This_App, 'formSubmit', [
This_App.history.last().HTML,
arguments[2].url,
iData,
$(this).attr('href')
]);
if ((iReturn !== false) && this.target)
This_App.loadLink(
$.extend(PageLink.getAttr( $(this) ), {
action: arguments[2].url
}),
null,
iReturn || iData
);
});
if (! Hash_Path_Load.call(This_Page))
This_Page.boot(function () {
this.render(null, arguments[0]).onReady();
});
$(BOM).on('hashchange', $.proxy(Hash_Path_Load, This_Page));
return this;
};
return WebApp;
})(self, self.document, self.jQuery, PageLink, InnerPage, InnerHistory);
//
// >>> EasyWebApp.js <<<
//
//
// [Version] v2.6 (2016-09-20) Beta
//
// [Require] iQuery || jQuery with jQuery+,
//
// iQuery+,
//
// [ marked.js ] (for MarkDown rendering)
//
// [Usage] A Light-weight WebApp Framework
// jQuery Compatible API.
//
//
// (C)2015-2016 shiy2008@gmail.com
//
var EasyWebApp = (function (BOM, DOM, $, WebApp, PageLink) {
/* ---------->> jQuery Wrapper <<---------- */
$.fn.WebApp = function () {
if (! this[0]) return;
var iWebApp = $(this[0]).data('_EWAI_');
if (iWebApp instanceof WebApp) return iWebApp;
var iArgs = $.makeArray(arguments);
var Init_Data = $.extend(
$.parseJSON(BOM.sessionStorage.EWA_Model || '{ }'),
$.paramJSON(),
$.isPlainObject(iArgs[0]) && iArgs.shift()
);
var API_Root = (typeof iArgs[0] == 'string') && iArgs.shift();
var Cache_Second = (typeof iArgs[0] == 'number') && iArgs.shift();
var URL_Change = (typeof iArgs[0] == 'boolean') && iArgs[0];
iWebApp = (new WebApp(
this, API_Root, Cache_Second, URL_Change
)).boot(Init_Data);
$(this[0]).data('_EWAI_', iWebApp).addClass('EWA_Container');
return iWebApp;
};
/* ---------- User Event Switcher ---------- */
var No_Hook = $.makeSet('form', 'input', 'textarea', 'select');
function Event_Filter() {
var iTagName = this.tagName.toLowerCase(),
iEvent = arguments.callee.caller.arguments[0];
switch (iEvent.type) {
case 'click': ;
case 'tap': {
if (iTagName == 'a') {
if (this.matches('a[rel*="nofollow"]')) return true;
iEvent.preventDefault();
}
return (iTagName in No_Hook);
}
case 'change': return (this !== iEvent.target);
}
}
$(DOM).on(
($.browser.mobile ? 'tap' : 'click') + ' change',
'*[target]',
function () {
if ( Event_Filter.call(this) ) return;
var iLink = new PageLink($('.EWA_Container').WebApp(), this);
switch (iLink.target) {
case '_self': {
if (iLink.href) iLink.loadTemplate();
break;
}
case '_blank': {
if (iLink.src) iLink.loadData();
break;
}
case '_top': {
if (iLink.href) iLink.loadPage();
break;
}
default: iLink.loadTemplate();
}
}
);
})(self, self.document, self.jQuery, WebApp, PageLink);
});
JavaScript
1
https://gitee.com/tang006/EasyWebApp.git
git@gitee.com:tang006/EasyWebApp.git
tang006
EasyWebApp
EasyWebApp
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891