├── generators
└── app
│ └── templates
│ ├── js
│ ├── comp
│ │ ├── tpl
│ │ │ ├── loaded.tpl
│ │ │ ├── loading.tpl
│ │ │ ├── loading-retry.tpl
│ │ │ ├── alert.tpl
│ │ │ └── confirm.tpl
│ │ ├── channel
│ │ │ └── global.js
│ │ ├── common
│ │ │ ├── fastclick.js
│ │ │ ├── validator.js
│ │ │ ├── active.js
│ │ │ ├── tip.js
│ │ │ ├── confirm.js
│ │ │ └── alert.js
│ │ ├── ui
│ │ │ ├── reuseDialog.js
│ │ │ ├── loginLayer.js
│ │ │ ├── screenMask.js
│ │ │ ├── autoloadList.js
│ │ │ ├── switchGroup.js
│ │ │ ├── overlay.js
│ │ │ ├── tip.js
│ │ │ └── mask.js
│ │ └── model
│ │ │ └── paging.js
│ ├── entry
│ │ ├── global.js
│ │ └── static
│ │ │ └── zepto.js
│ ├── lib.js
│ ├── mods
│ │ ├── channel
│ │ │ └── app.js
│ │ ├── trans
│ │ │ ├── app.js
│ │ │ └── getTransmission.js
│ │ ├── view
│ │ │ ├── countDown.js
│ │ │ └── auctionState.js
│ │ ├── model
│ │ │ └── auctionInfo.js
│ │ └── layer
│ │ │ └── autoCloseTip.js
│ ├── lib
│ │ ├── kit
│ │ │ ├── util
│ │ │ │ ├── getUniqueKey.js
│ │ │ │ ├── scrollFix.js
│ │ │ │ ├── stockMonitor.js
│ │ │ │ ├── template.js
│ │ │ │ ├── makeReady.js
│ │ │ │ └── cookie.js
│ │ │ ├── dom
│ │ │ │ ├── isNode.js
│ │ │ │ ├── getValue.js
│ │ │ │ ├── placeholder.js
│ │ │ │ └── getHiddenBox.js
│ │ │ ├── env
│ │ │ │ ├── platform.js
│ │ │ │ ├── network.js
│ │ │ │ ├── device.js
│ │ │ │ ├── os.js
│ │ │ │ ├── browser.js
│ │ │ │ ├── touchable.js
│ │ │ │ └── ua.js
│ │ │ ├── evt
│ │ │ │ ├── occurInside.js
│ │ │ │ └── tapStop.js
│ │ │ ├── num
│ │ │ │ ├── comma.js
│ │ │ │ ├── fixTo.js
│ │ │ │ ├── limit.js
│ │ │ │ └── numerical.js
│ │ │ ├── arr
│ │ │ │ ├── contains.js
│ │ │ │ ├── erase.js
│ │ │ │ ├── include.js
│ │ │ │ ├── find.js
│ │ │ │ └── flatten.js
│ │ │ ├── str
│ │ │ │ ├── bLength.js
│ │ │ │ ├── hyphenate.js
│ │ │ │ ├── dbcToSbc.js
│ │ │ │ ├── ipToHex.js
│ │ │ │ ├── leftB.js
│ │ │ │ ├── decodeHTML.js
│ │ │ │ ├── encodeHTML.js
│ │ │ │ ├── substitute.js
│ │ │ │ └── parseURL.js
│ │ │ ├── obj
│ │ │ │ ├── type.js
│ │ │ │ ├── find.js
│ │ │ │ └── cover.js
│ │ │ ├── func
│ │ │ │ ├── once.js
│ │ │ │ ├── lock.js
│ │ │ │ ├── delay.js
│ │ │ │ ├── regular.js
│ │ │ │ └── queue.js
│ │ │ ├── io
│ │ │ │ └── loadScript.js
│ │ │ ├── fx
│ │ │ │ ├── flashAction.js
│ │ │ │ └── smoothScrollTo.js
│ │ │ ├── time
│ │ │ │ └── split.js
│ │ │ └── date
│ │ │ │ └── format.js
│ │ ├── core
│ │ │ ├── transmission.js
│ │ │ └── listener.js
│ │ └── mvc
│ │ │ └── delegate.js
│ ├── plugin
│ │ ├── extra.js
│ │ └── transform.js
│ └── vendor
│ │ └── zepto
│ │ ├── ie.js
│ │ └── form.js
│ ├── src
│ ├── js
│ │ ├── comp
│ │ │ ├── tpl
│ │ │ │ ├── loaded.tpl
│ │ │ │ ├── loading.tpl
│ │ │ │ ├── loading-retry.tpl
│ │ │ │ ├── alert.tpl
│ │ │ │ └── confirm.tpl
│ │ │ ├── common
│ │ │ │ ├── fastclick.js
│ │ │ │ ├── validator.js
│ │ │ │ ├── active.js
│ │ │ │ ├── tip.js
│ │ │ │ ├── confirm.js
│ │ │ │ └── alert.js
│ │ │ ├── channel
│ │ │ │ └── global.js
│ │ │ ├── ui
│ │ │ │ ├── reuseDialog.js
│ │ │ │ ├── loginLayer.js
│ │ │ │ ├── screenMask.js
│ │ │ │ ├── autoloadList.js
│ │ │ │ ├── switchGroup.js
│ │ │ │ ├── overlay.js
│ │ │ │ ├── tip.js
│ │ │ │ └── mask.js
│ │ │ └── model
│ │ │ │ └── paging.js
│ │ ├── entry
│ │ │ ├── page
│ │ │ │ └── home.js
│ │ │ ├── global.js
│ │ │ └── static
│ │ │ │ └── zepto.js
│ │ ├── mods
│ │ │ ├── tpl
│ │ │ │ └── goTop.tpl
│ │ │ ├── channel
│ │ │ │ └── app.js
│ │ │ ├── trans
│ │ │ │ ├── app.js
│ │ │ │ └── getTransmission.js
│ │ │ ├── pl
│ │ │ │ └── goTop.js
│ │ │ └── view
│ │ │ │ └── countDown.js
│ │ ├── lib.js
│ │ ├── lib
│ │ │ ├── kit
│ │ │ │ ├── util
│ │ │ │ │ ├── getUniqueKey.js
│ │ │ │ │ ├── scrollFix.js
│ │ │ │ │ ├── stockMonitor.js
│ │ │ │ │ ├── template.js
│ │ │ │ │ ├── makeReady.js
│ │ │ │ │ └── cookie.js
│ │ │ │ ├── dom
│ │ │ │ │ ├── isNode.js
│ │ │ │ │ ├── getValue.js
│ │ │ │ │ ├── placeholder.js
│ │ │ │ │ └── getHiddenBox.js
│ │ │ │ ├── env
│ │ │ │ │ ├── platform.js
│ │ │ │ │ ├── device.js
│ │ │ │ │ ├── os.js
│ │ │ │ │ ├── network.js
│ │ │ │ │ ├── browser.js
│ │ │ │ │ ├── touchable.js
│ │ │ │ │ └── ua.js
│ │ │ │ ├── evt
│ │ │ │ │ ├── occurInside.js
│ │ │ │ │ └── tapStop.js
│ │ │ │ ├── num
│ │ │ │ │ ├── comma.js
│ │ │ │ │ ├── fixTo.js
│ │ │ │ │ ├── limit.js
│ │ │ │ │ └── numerical.js
│ │ │ │ ├── arr
│ │ │ │ │ ├── contains.js
│ │ │ │ │ ├── erase.js
│ │ │ │ │ ├── include.js
│ │ │ │ │ ├── find.js
│ │ │ │ │ └── flatten.js
│ │ │ │ ├── str
│ │ │ │ │ ├── hyphenate.js
│ │ │ │ │ ├── bLength.js
│ │ │ │ │ ├── dbcToSbc.js
│ │ │ │ │ ├── ipToHex.js
│ │ │ │ │ ├── leftB.js
│ │ │ │ │ ├── decodeHTML.js
│ │ │ │ │ ├── encodeHTML.js
│ │ │ │ │ ├── substitute.js
│ │ │ │ │ └── parseURL.js
│ │ │ │ ├── obj
│ │ │ │ │ ├── type.js
│ │ │ │ │ ├── find.js
│ │ │ │ │ └── cover.js
│ │ │ │ ├── func
│ │ │ │ │ ├── once.js
│ │ │ │ │ ├── lock.js
│ │ │ │ │ ├── delay.js
│ │ │ │ │ ├── regular.js
│ │ │ │ │ └── queue.js
│ │ │ │ ├── io
│ │ │ │ │ └── loadScript.js
│ │ │ │ ├── fx
│ │ │ │ │ ├── flashAction.js
│ │ │ │ │ └── smoothScrollTo.js
│ │ │ │ ├── time
│ │ │ │ │ └── split.js
│ │ │ │ └── date
│ │ │ │ │ └── format.js
│ │ │ ├── core
│ │ │ │ ├── transmission.js
│ │ │ │ └── listener.js
│ │ │ └── mvc
│ │ │ │ └── delegate.js
│ │ ├── plugin
│ │ │ ├── extra.js
│ │ │ └── transform.js
│ │ └── vendor
│ │ │ └── zepto
│ │ │ ├── ie.js
│ │ │ └── form.js
│ ├── html
│ │ ├── common
│ │ │ ├── footer.html
│ │ │ ├── header.html
│ │ │ ├── script-foot.html
│ │ │ ├── link.html
│ │ │ ├── meta.html
│ │ │ └── script-head.html
│ │ ├── mods
│ │ │ └── pl-home-banner.html
│ │ └── pages
│ │ │ └── home.html
│ ├── images
│ │ ├── sprite.png
│ │ ├── weixin.png
│ │ ├── sprite-2x.png
│ │ ├── temp
│ │ │ └── house.png
│ │ └── sprite
│ │ │ ├── right.png
│ │ │ ├── to-top.png
│ │ │ └── warn.png
│ └── css
│ │ ├── common
│ │ ├── public.css
│ │ ├── reset.css
│ │ ├── sprite.css
│ │ └── common.css
│ │ ├── mods
│ │ ├── pl-home-banner.css
│ │ └── pl-gotop.css
│ │ └── pages
│ │ └── main.css
│ ├── html
│ ├── common
│ │ ├── footer.html
│ │ ├── script-foot.html
│ │ ├── link.html
│ │ ├── meta.html
│ │ ├── header.html
│ │ └── script-head.html
│ └── pages
│ │ └── home.html
│ ├── images
│ ├── sprite
│ │ ├── ahead.png
│ │ ├── ask.png
│ │ ├── clock.png
│ │ ├── close.png
│ │ ├── error.png
│ │ ├── kan.png
│ │ ├── minus.png
│ │ ├── out.png
│ │ ├── phone.png
│ │ ├── plus.png
│ │ ├── right.png
│ │ ├── shop.png
│ │ ├── warn.png
│ │ ├── yao.png
│ │ ├── yes.png
│ │ ├── account.png
│ │ ├── confirm.png
│ │ ├── loading.png
│ │ ├── remind.png
│ │ ├── to-top.png
│ │ ├── wechat.png
│ │ ├── wehouse.png
│ │ ├── weshop.png
│ │ ├── decrease.png
│ │ ├── homeLogo.png
│ │ └── increase.png
│ ├── temp
│ │ └── house.png
│ └── sprite-output
│ │ ├── sprite-..png
│ │ ├── sprite.png
│ │ ├── sprite@2x.png
│ │ └── sprite-.@2x.png
│ ├── docs
│ ├── test.md
│ ├── contact.md
│ ├── interface.md
│ ├── spec-code.md
│ ├── debug.md
│ └── dir.md
│ ├── css
│ ├── pages
│ │ └── main.css
│ └── common
│ │ ├── reset.css
│ │ ├── public.css
│ │ └── common.css
│ ├── README.md
│ ├── index.html
│ ├── package.json
│ ├── gruntfile.js
│ └── webpack.config.js
├── .gitignore
├── README.md
└── package.json
/generators/app/templates/js/comp/tpl/loaded.tpl:
--------------------------------------------------------------------------------
1 |
已显示全部
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/tpl/loaded.tpl:
--------------------------------------------------------------------------------
1 | 已显示全部
--------------------------------------------------------------------------------
/generators/app/templates/js/entry/global.js:
--------------------------------------------------------------------------------
1 | require('../comp/common/fastclick');
2 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/entry/page/home.js:
--------------------------------------------------------------------------------
1 | //首页
2 | require('../global');
3 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/tpl/loading.tpl:
--------------------------------------------------------------------------------
1 |
2 | 数据加载中...
3 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/tpl/loading.tpl:
--------------------------------------------------------------------------------
1 |
2 | 数据加载中...
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | generators/app/templates/dist/*
3 | generators/app/templates/online/*
4 |
--------------------------------------------------------------------------------
/generators/app/templates/html/common/footer.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/generators/app/templates/src/html/common/footer.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/generators/app/templates/src/html/common/header.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/mods/tpl/goTop.tpl:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/generators/app/templates/src/html/mods/pl-home-banner.html:
--------------------------------------------------------------------------------
1 |
2 | banner
3 |
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/ahead.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/ahead.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/ask.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/ask.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/clock.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/clock.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/close.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/error.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/kan.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/kan.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/minus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/minus.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/out.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/out.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/phone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/phone.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/plus.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/right.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/shop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/shop.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/warn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/warn.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/yao.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/yao.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/yes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/yes.png
--------------------------------------------------------------------------------
/generators/app/templates/images/temp/house.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/temp/house.png
--------------------------------------------------------------------------------
/generators/app/templates/src/images/sprite.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/src/images/sprite.png
--------------------------------------------------------------------------------
/generators/app/templates/src/images/weixin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/src/images/weixin.png
--------------------------------------------------------------------------------
/generators/app/templates/html/common/script-foot.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/account.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/account.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/confirm.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/confirm.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/loading.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/remind.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/remind.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/to-top.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/to-top.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/wechat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/wechat.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/wehouse.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/wehouse.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/weshop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/weshop.png
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/channel/global.js:
--------------------------------------------------------------------------------
1 | var $listener = require('../../lib/core/listener');
2 |
3 | module.exports = new $listener([
4 | ]);
5 |
--------------------------------------------------------------------------------
/generators/app/templates/src/html/common/script-foot.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/generators/app/templates/src/images/sprite-2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/src/images/sprite-2x.png
--------------------------------------------------------------------------------
/generators/app/templates/src/images/temp/house.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/src/images/temp/house.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/decrease.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/decrease.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/homeLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/homeLogo.png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite/increase.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite/increase.png
--------------------------------------------------------------------------------
/generators/app/templates/src/images/sprite/right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/src/images/sprite/right.png
--------------------------------------------------------------------------------
/generators/app/templates/src/images/sprite/to-top.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/src/images/sprite/to-top.png
--------------------------------------------------------------------------------
/generators/app/templates/src/images/sprite/warn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/src/images/sprite/warn.png
--------------------------------------------------------------------------------
/generators/app/templates/docs/test.md:
--------------------------------------------------------------------------------
1 | # 测试环境
2 |
3 | ### 环境类别名称
4 |
5 | hosts:
6 | - IP 域名
7 |
8 | 范例页面路径:
9 | - [页面名称](http://页面地址)
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib.js:
--------------------------------------------------------------------------------
1 | var Zepto = window.Zepto;
2 | if(Zepto && Zepto.noConflict){
3 | Zepto.noConflict();
4 | }
5 |
6 | module.exports = Zepto;
7 |
8 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/entry/global.js:
--------------------------------------------------------------------------------
1 | require('../comp/common/fastclick');
2 | require('../comp/model/user');
3 | require('../mods/pl/goTop');
4 |
5 |
6 |
--------------------------------------------------------------------------------
/generators/app/templates/html/common/link.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite-output/sprite-..png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite-output/sprite-..png
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite-output/sprite.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite-output/sprite.png
--------------------------------------------------------------------------------
/generators/app/templates/src/css/common/public.css:
--------------------------------------------------------------------------------
1 | body{
2 | font-size: 0.12rem;
3 | }
4 |
5 | .icon{
6 | display: block;
7 | overflow: hidden;
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/generators/app/templates/src/html/common/link.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib.js:
--------------------------------------------------------------------------------
1 | var Zepto = window.Zepto;
2 | if(Zepto && Zepto.noConflict){
3 | Zepto.noConflict();
4 | }
5 |
6 | module.exports = Zepto;
7 |
8 |
--------------------------------------------------------------------------------
/generators/app/templates/docs/contact.md:
--------------------------------------------------------------------------------
1 | # 项目联系人
2 |
3 | ### 姓名 - 职位
4 | - 邮箱
5 | - 手机
6 | - 010-62671188-分机
7 | - qq
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite-output/sprite@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite-output/sprite@2x.png
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/tpl/loading-retry.tpl:
--------------------------------------------------------------------------------
1 |
2 | 数据加载失败,请点击这里重试
3 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/tpl/loading-retry.tpl:
--------------------------------------------------------------------------------
1 |
2 | 数据加载失败,请点击这里重试
3 |
--------------------------------------------------------------------------------
/generators/app/templates/images/sprite-output/sprite-.@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icai/generator-tomg/master/generators/app/templates/images/sprite-output/sprite-.@2x.png
--------------------------------------------------------------------------------
/generators/app/templates/js/mods/channel/app.js:
--------------------------------------------------------------------------------
1 | //业务广播列表
2 |
3 | var $listener = require('../../lib/core/listener');
4 |
5 | module.exports = new $listener([
6 |
7 | ]);
8 |
--------------------------------------------------------------------------------
/generators/app/templates/src/css/mods/pl-home-banner.css:
--------------------------------------------------------------------------------
1 | .pl-home-banner{
2 | width: 3.2rem;
3 | height: 20rem;
4 | border: 1px solid #000;
5 | box-sizing:border-box;
6 | }
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Installation
2 |
3 | ```sh
4 | 安装yeoman
5 | $ npm install -g yo
6 | 安装前端脚手架
7 | $ npm install -g generator-tomg
8 | ```
9 |
10 | ## Quick Start
11 |
12 | yo tomg
13 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/mods/channel/app.js:
--------------------------------------------------------------------------------
1 | //业务广播列表
2 |
3 | var $listener = require('../../lib/core/listener');
4 |
5 | module.exports = new $listener([
6 |
7 | ]);
8 |
9 |
10 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/common/fastclick.js:
--------------------------------------------------------------------------------
1 | var $ = require('../../lib');
2 | var $FastClick = require('../../vendor/fastclick');
3 |
4 | $(function(){
5 | $FastClick.attach(document.body);
6 | });
7 |
8 |
--------------------------------------------------------------------------------
/generators/app/templates/js/mods/trans/app.js:
--------------------------------------------------------------------------------
1 | /**
2 | 接口管理器
3 | **/
4 |
5 | var $getTransmission = require('./getTransmission');
6 |
7 | var trans = $getTransmission();
8 |
9 | module.exports = trans;
10 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/common/fastclick.js:
--------------------------------------------------------------------------------
1 | var $ = require('../../lib');
2 | var $FastClick = require('../../vendor/fastclick');
3 |
4 | $(function(){
5 | $FastClick.attach(document.body);
6 | });
7 |
8 |
--------------------------------------------------------------------------------
/generators/app/templates/css/pages/main.css:
--------------------------------------------------------------------------------
1 | @charset "utf-8";
2 |
3 | @@include('../common/reset.css')
4 | @@include('../common/common.css')
5 | @@include('../common/public.css')
6 |
7 | /* modules */
8 | @@include('../mods/pl-home.css')
9 |
--------------------------------------------------------------------------------
/generators/app/templates/README.md:
--------------------------------------------------------------------------------
1 | # Quick Start
2 |
3 | - docs/debug.md 搭建本地开发调试环境
4 | - docs/dir.md 项目目录说明
5 | - docs/spec-code.md JS开发规范
6 | - docs/interface.md 接口说明
7 | - docs/contact.md 项目相关联系人
8 | - docs/test.md 项目联调时可能需要配置的测试环境
9 |
10 |
--------------------------------------------------------------------------------
/generators/app/templates/src/css/mods/pl-gotop.css:
--------------------------------------------------------------------------------
1 | /*返顶*/
2 | .pl-gotop{
3 | position: fixed;
4 | right: 0.1rem;
5 | bottom: 0.1rem;
6 | }
7 |
8 | .pl-gotop .icon{
9 | display: block;
10 | width: 0.26rem;
11 | height: 0.26rem;
12 | }
13 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/channel/global.js:
--------------------------------------------------------------------------------
1 | var $listener = require('../../lib/core/listener');
2 |
3 | module.exports = new $listener([
4 | //需要登录时触发
5 | 'need-login',
6 | //需要退出登录时触发
7 | 'need-logout',
8 | //用户登录信息变更时触发
9 | 'user-change'
10 | ]);
11 |
12 |
13 |
--------------------------------------------------------------------------------
/generators/app/templates/html/common/meta.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/generators/app/templates/src/html/common/meta.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/mods/trans/app.js:
--------------------------------------------------------------------------------
1 | /**
2 | 接口管理器
3 | **/
4 |
5 | var $getTransmission = require('./getTransmission');
6 |
7 | var trans = $getTransmission();
8 |
9 | // 接口说明
10 | // 参数名称 参数说明
11 | trans.register('接口名称', {
12 | url: '/接口地址'
13 | });
14 |
15 |
16 | module.exports = trans;
17 |
--------------------------------------------------------------------------------
/generators/app/templates/js/mods/trans/getTransmission.js:
--------------------------------------------------------------------------------
1 | /**
2 | 获取接口配置实例
3 | **/
4 |
5 | var $transmission = require('../../lib/core/transmission');
6 |
7 | module.exports = function(){
8 | return new $transmission({
9 | verify : function(rs, conf, options){
10 | return !!rs;
11 | }
12 | });
13 | };
14 |
15 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/tpl/alert.tpl:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/mods/trans/getTransmission.js:
--------------------------------------------------------------------------------
1 | /**
2 | 获取接口配置实例
3 | **/
4 |
5 | var $transmission = require('../../lib/core/transmission');
6 |
7 | module.exports = function(){
8 | return new $transmission({
9 | verify : function(rs, conf, options){
10 | return !!rs;
11 | }
12 | });
13 | };
14 |
15 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/tpl/alert.tpl:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/util/getUniqueKey.js:
--------------------------------------------------------------------------------
1 | /**
2 | 获取唯一ID
3 | @module lib/kit/util/getUniqueKey
4 | **/
5 |
6 | var time = + new Date(), index = 1;
7 |
8 | /**
9 | 生成一个不与之前重复的随机字符串
10 | @return {string} 随机字符串
11 | **/
12 | module.exports = function() {
13 | return ( time + (index++) ).toString(16);
14 | };
15 |
16 |
--------------------------------------------------------------------------------
/generators/app/templates/src/css/pages/main.css:
--------------------------------------------------------------------------------
1 | @charset "utf-8";
2 |
3 | @@include('../common/reset.css')
4 | @@include('../common/common.css')
5 | @@include('../common/public.css')
6 | @@include('../common/sprite.css')
7 |
8 | /* modules */
9 | @@include('../mods/pl-gotop.css')
10 | @@include('../mods/pl-home-banner.css')
11 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/dom/isNode.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/dom/isNode
3 | **/
4 |
5 | /**
6 | 判断对象是否为dom元素
7 | @param {element} node
8 | @return {boolean} true/false
9 | **/
10 | module.exports = function(node){
11 | return (node !== undefined && node !== null) &&
12 | Boolean(node.nodeName) && Boolean(node.nodeType);
13 | };
14 |
15 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/util/getUniqueKey.js:
--------------------------------------------------------------------------------
1 | /**
2 | 获取唯一ID
3 | @module lib/kit/util/getUniqueKey
4 | **/
5 |
6 | var time = + new Date(), index = 1;
7 |
8 | /**
9 | 生成一个不与之前重复的随机字符串
10 | @return {string} 随机字符串
11 | **/
12 | module.exports = function() {
13 | return ( time + (index++) ).toString(16);
14 | };
15 |
16 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/env/platform.js:
--------------------------------------------------------------------------------
1 | /**
2 | 检测用户使用的是什么平台的设备
3 |
4 | - 仅提供平台信息,浏览器等其他信息由其他组件提供。
5 | - 这个组件将结合UA检测和特性检测,力求获取更准确的匹配。
6 |
7 | @module lib/kit/env/platform
8 | **/
9 |
10 | var $ua = require('./ua');
11 |
12 | var platform = $ua.platform;
13 |
14 | /**
15 | 平台类型
16 | @type {string}
17 | **/
18 | module.exports = platform;
19 |
20 |
21 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/dom/isNode.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/dom/isNode
3 | **/
4 |
5 | /**
6 | 判断对象是否为dom元素
7 | @param {element} node
8 | @return {boolean} true/false
9 | **/
10 | module.exports = function(node){
11 | return (node !== undefined && node !== null) &&
12 | Boolean(node.nodeName) && Boolean(node.nodeType);
13 | };
14 |
15 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/env/platform.js:
--------------------------------------------------------------------------------
1 | /**
2 | 检测用户使用的是什么平台的设备
3 |
4 | - 仅提供平台信息,浏览器等其他信息由其他组件提供。
5 | - 这个组件将结合UA检测和特性检测,力求获取更准确的匹配。
6 |
7 | @module lib/kit/env/platform
8 | **/
9 |
10 | var $ua = require('./ua');
11 |
12 | var platform = $ua.platform;
13 |
14 | /**
15 | 平台类型
16 | @type {string}
17 | **/
18 | module.exports = platform;
19 |
20 |
21 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/env/network.js:
--------------------------------------------------------------------------------
1 | /**
2 | 网络环境检测
3 | @module lib/kit/env/network
4 | **/
5 |
6 | var supportOnlineCheck = 'onLine' in window.navigator;
7 |
8 | module.exports = {
9 | /**
10 | 判断是否联网
11 | @return {boolean} true/false
12 | **/
13 | onLine : function(){
14 | return supportOnlineCheck ? window.navigator.onLine : true;
15 | }
16 | };
17 |
18 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/evt/occurInside.js:
--------------------------------------------------------------------------------
1 | /**
2 | 判断事件是否发生在一个元素内
3 | **/
4 |
5 | var $ = require('../../../lib');
6 |
7 | var occurInside = function(node, event){
8 | node = $(node);
9 | if(node.length && event && event.target){
10 | return node[0] === event.target || node.has(event.target).length;
11 | }
12 | };
13 |
14 | module.exports = occurInside;
15 |
16 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/evt/occurInside.js:
--------------------------------------------------------------------------------
1 | /**
2 | 判断事件是否发生在一个元素内
3 | **/
4 |
5 | var $ = require('../../../lib');
6 |
7 | var occurInside = function(node, event){
8 | node = $(node);
9 | if(node.length && event && event.target){
10 | return node[0] === event.target || node.has(event.target).length;
11 | }
12 | };
13 |
14 | module.exports = occurInside;
15 |
16 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/dom/getValue.js:
--------------------------------------------------------------------------------
1 | /**
2 | placeholder兼容性相关函数
3 | 获取input的实际value
4 | **/
5 |
6 | var $ = require('../../../lib');
7 |
8 | module.exports = function(node){
9 | node = $(node);
10 | var text = node.attr('placeholder');
11 | var value = node.val();
12 | if(value === text){
13 | return '';
14 | }else{
15 | return $.trim(value);
16 | }
17 | };
18 |
19 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/env/device.js:
--------------------------------------------------------------------------------
1 | /**
2 | 检测用户使用的是什么设备
3 |
4 | - 仅提供设备信息,操作系统等其他信息由其他组件提供。
5 | - 这个组件将结合UA检测和特性检测,力求获取更准确的匹配。
6 |
7 | @module lib/kit/env/device
8 | **/
9 |
10 | var $ua = require('./ua');
11 |
12 | /**
13 | 设备类型
14 | @type {string}
15 | **/
16 | exports.type = '';
17 |
18 | /**
19 | 设备版本号
20 | @type {number}
21 | **/
22 | exports.version = 0;
23 |
24 |
25 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/env/os.js:
--------------------------------------------------------------------------------
1 | /**
2 | 检测用户使用的是什么操作系统
3 |
4 | - 仅提供操作系统信息,浏览器等其他信息由其他组件提供。
5 | - 这个组件将结合UA检测和特性检测,力求获取更准确的匹配。
6 |
7 | @module lib/kit/env/os
8 | **/
9 |
10 | var $ua = require('./ua');
11 |
12 |
13 | /**
14 | 操作系统类型
15 | @type {string}
16 | **/
17 | exports.type = '';
18 |
19 | /**
20 | 操作系统版本号
21 | @type {number}
22 | **/
23 | exports.version = 0;
24 |
25 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/dom/getValue.js:
--------------------------------------------------------------------------------
1 | /**
2 | placeholder兼容性相关函数
3 | 获取input的实际value
4 | **/
5 |
6 | var $ = require('../../../lib');
7 |
8 | module.exports = function(node){
9 | node = $(node);
10 | var text = node.attr('placeholder');
11 | var value = node.val();
12 | if(value === text){
13 | return '';
14 | }else{
15 | return $.trim(value);
16 | }
17 | };
18 |
19 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/env/device.js:
--------------------------------------------------------------------------------
1 | /**
2 | 检测用户使用的是什么设备
3 |
4 | - 仅提供设备信息,操作系统等其他信息由其他组件提供。
5 | - 这个组件将结合UA检测和特性检测,力求获取更准确的匹配。
6 |
7 | @module lib/kit/env/device
8 | **/
9 |
10 | var $ua = require('./ua');
11 |
12 | /**
13 | 设备类型
14 | @type {string}
15 | **/
16 | exports.type = '';
17 |
18 | /**
19 | 设备版本号
20 | @type {number}
21 | **/
22 | exports.version = 0;
23 |
24 |
25 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/env/os.js:
--------------------------------------------------------------------------------
1 | /**
2 | 检测用户使用的是什么操作系统
3 |
4 | - 仅提供操作系统信息,浏览器等其他信息由其他组件提供。
5 | - 这个组件将结合UA检测和特性检测,力求获取更准确的匹配。
6 |
7 | @module lib/kit/env/os
8 | **/
9 |
10 | var $ua = require('./ua');
11 |
12 |
13 | /**
14 | 操作系统类型
15 | @type {string}
16 | **/
17 | exports.type = '';
18 |
19 | /**
20 | 操作系统版本号
21 | @type {number}
22 | **/
23 | exports.version = 0;
24 |
25 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/env/network.js:
--------------------------------------------------------------------------------
1 | /**
2 | 网络环境检测
3 | @module lib/kit/env/network
4 | **/
5 |
6 | var supportOnlineCheck = 'onLine' in window.navigator;
7 |
8 | module.exports = {
9 | /**
10 | 判断是否联网
11 | @return {boolean} true/false
12 | **/
13 | onLine : function(){
14 | return supportOnlineCheck ? window.navigator.onLine : true;
15 | }
16 | };
17 |
18 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/env/browser.js:
--------------------------------------------------------------------------------
1 | /**
2 | 检测用户使用的是什么浏览器
3 |
4 | - 仅提供浏览器信息,操作系统等其他信息由其他组件提供。
5 | - 这个组件将结合UA检测和特性检测,力求获取更准确的匹配。
6 |
7 | @module lib/kit/env/browser
8 | **/
9 |
10 | var $ua = require('./ua');
11 |
12 | /**
13 | 浏览器类型
14 | @type {string}
15 | **/
16 | exports.type = '';
17 |
18 | /**
19 | 浏览器版本号
20 | @type {number}
21 | **/
22 | exports.version = 0;
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/env/browser.js:
--------------------------------------------------------------------------------
1 | /**
2 | 检测用户使用的是什么浏览器
3 |
4 | - 仅提供浏览器信息,操作系统等其他信息由其他组件提供。
5 | - 这个组件将结合UA检测和特性检测,力求获取更准确的匹配。
6 |
7 | @module lib/kit/env/browser
8 | **/
9 |
10 | var $ua = require('./ua');
11 |
12 | /**
13 | 浏览器类型
14 | @type {string}
15 | **/
16 | exports.type = '';
17 |
18 | /**
19 | 浏览器版本号
20 | @type {number}
21 | **/
22 | exports.version = 0;
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/generators/app/templates/docs/interface.md:
--------------------------------------------------------------------------------
1 | #接口约定
2 |
3 | ### 接口:接口名称
4 |
5 | 接口地址:http://xxx/xxx
6 |
7 | 参数:
8 | - 参数名称 参数说明
9 | 返回:
10 | 成功:{
11 | "ret": 0,
12 | "msg": "ok",
13 | "errorcode": 0,
14 | "data": {
15 | "属性名" : "范例值"
16 | }
17 | }
18 | 失败:{
19 | "ret": 1,
20 | "msg": "范例错误信息",
21 | "errorcode": 10002,
22 | "data": {
23 | "属性名" : "范例值"
24 | }
25 | }
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/env/touchable.js:
--------------------------------------------------------------------------------
1 | /**
2 | 判断是否支持触摸屏
3 | @module lib/kit/env/touchable
4 | @type {boolean}
5 | @example
6 | var $touchable = require('lib/kit/env/touchable');
7 | if($touchable){
8 | //It is a touch device.
9 | }
10 | **/
11 |
12 | var touchable = ('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch;
13 |
14 | module.exports = touchable;
15 |
16 |
17 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/num/comma.js:
--------------------------------------------------------------------------------
1 | /**
2 | 数字的千分位逗号分隔表示法
3 | IE8 的 toLocalString 给出了小数点后2位: N.00
4 |
5 | http://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript
6 | **/
7 |
8 | module.exports = function(num){
9 | var parts = num.toString().split('.');
10 | parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
11 | return parts.join('.');
12 | };
13 |
14 |
15 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/num/comma.js:
--------------------------------------------------------------------------------
1 | /**
2 | 数字的千分位逗号分隔表示法
3 | IE8 的 toLocalString 给出了小数点后2位: N.00
4 |
5 | http://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript
6 | **/
7 |
8 | module.exports = function(num){
9 | var parts = num.toString().split('.');
10 | parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
11 | return parts.join('.');
12 | };
13 |
14 |
15 |
--------------------------------------------------------------------------------
/generators/app/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Document
8 |
9 |
10 |
11 |
12 | - 首页
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/generators/app/templates/js/plugin/extra.js:
--------------------------------------------------------------------------------
1 |
2 | exports.mixTo = function($){
3 | $.extend($, {
4 | noop : function(){},
5 | hyphenate : function(str){
6 | return str.replace(/[A-Z]/g, function($0){
7 | return '-' + $0.toLowerCase();
8 | });
9 | }
10 | });
11 |
12 | $.extend($.fn, {
13 | reflow : function(){
14 | var reflow = this.size() && this.get(0).clientLeft;
15 | return this;
16 | }
17 | });
18 | };
19 |
20 |
21 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/env/touchable.js:
--------------------------------------------------------------------------------
1 | /**
2 | 判断是否支持触摸屏
3 | @module lib/kit/env/touchable
4 | @type {boolean}
5 | @example
6 | var $touchable = require('lib/kit/env/touchable');
7 | if($touchable){
8 | //It is a touch device.
9 | }
10 | **/
11 |
12 | var touchable = ('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch;
13 |
14 | module.exports = touchable;
15 |
16 |
17 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/plugin/extra.js:
--------------------------------------------------------------------------------
1 |
2 | exports.mixTo = function($){
3 | $.extend($, {
4 | noop : function(){},
5 | hyphenate : function(str){
6 | return str.replace(/[A-Z]/g, function($0){
7 | return '-' + $0.toLowerCase();
8 | });
9 | }
10 | });
11 |
12 | $.extend($.fn, {
13 | reflow : function(){
14 | var reflow = this.size() && this.get(0).clientLeft;
15 | return this;
16 | }
17 | });
18 | };
19 |
20 |
21 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/common/validator.js:
--------------------------------------------------------------------------------
1 | var $ = require('../../lib');
2 | require('../../plugin/jquery.validate');
3 |
4 | //统一验证规则
5 |
6 | $.extend($.validator.messages, {
7 | required: ' ',
8 | maxlength: ' ',
9 | minlength: ' ',
10 | number: ' '
11 | });
12 |
13 | $.validator.addMethod('isTelCode', function(value, element) {
14 | var tel = /^[0-9]{11}$/;
15 | return this.optional(element) || (tel.test(value));
16 | }, ' ');
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/arr/contains.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/arr/contains
3 | @example
4 | var $contains = require('lib/kit/arr/contains');
5 | console.info($contains([1,2,3,4,5],3)); //true
6 | **/
7 |
8 | /**
9 | 确认对象是否在数组中
10 | @param {array} arr 要操作的数组
11 | @param {*} item 要搜索的对象
12 | @return {boolean} 如果对象在数组中,返回true
13 | **/
14 | module.exports = function(arr, item){
15 | var index = arr.indexOf(item);
16 | return index >= 0;
17 | };
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/common/validator.js:
--------------------------------------------------------------------------------
1 | var $ = require('../../lib');
2 | require('../../plugin/jquery.validate');
3 |
4 | //统一验证规则
5 |
6 | $.extend($.validator.messages, {
7 | required: ' ',
8 | maxlength: ' ',
9 | minlength: ' ',
10 | number: ' '
11 | });
12 |
13 | $.validator.addMethod('isTelCode', function(value, element) {
14 | var tel = /^[0-9]{11}$/;
15 | return this.optional(element) || (tel.test(value));
16 | }, ' ');
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/str/bLength.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/bLength
3 | @example
4 | var $bLength = require('lib/kit/str/bLength');
5 | $bLength('中文cc'); //return 6
6 | **/
7 |
8 | /**
9 | 获取字符串长度,一个中文算2个字符
10 | @param {string} str 要计算长度的字符串
11 | @return {number} 字符串长度
12 | **/
13 | module.exports = function(str){
14 | if (!str) {
15 | return 0;
16 | }
17 | var aMatch = str.match(/[^\x00-\xff]/g);
18 | return (str.length + (!aMatch ? 0 : aMatch.length));
19 | };
20 |
21 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/str/hyphenate.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/hyphenate
3 | @example
4 | var $hyphenate = require('lib/kit/str/hyphenate');
5 | $hyphenate('libKitStrHyphenate'); //return 'lib-kit-str-hyphenate'
6 | **/
7 |
8 | /**
9 | 将驼峰格式变为连字符格式
10 | @param {string} str 驼峰格式的字符串
11 | @return {string} 连字符格式的字符串
12 | **/
13 | module.exports = function(str){
14 | return str.replace(/[A-Z]/g, function($0){
15 | return '-' + $0.toLowerCase();
16 | });
17 | };
18 |
19 |
20 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/arr/contains.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/arr/contains
3 | @example
4 | var $contains = require('lib/kit/arr/contains');
5 | console.info($contains([1,2,3,4,5],3)); //true
6 | **/
7 |
8 | /**
9 | 确认对象是否在数组中
10 | @param {array} arr 要操作的数组
11 | @param {*} item 要搜索的对象
12 | @return {boolean} 如果对象在数组中,返回true
13 | **/
14 | module.exports = function(arr, item){
15 | var index = arr.indexOf(item);
16 | return index >= 0;
17 | };
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/arr/erase.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/arr/erase
3 | @example
4 | var $erase = require('lib/kit/util/erase');
5 | console.info($erase([1,2,3,4,5],3)); //[1,2,4,5]
6 | **/
7 |
8 | /**
9 | 删除数组中的对象
10 | @param {array} arr 要操作的数组
11 | @param {*} item 要清除的对象
12 | @return {number} 对象原本所在位置
13 | **/
14 | module.exports = function(arr, item){
15 | var index = arr.indexOf(item);
16 | if(index >= 0){
17 | arr.splice(index, 1);
18 | }
19 | return index;
20 | };
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/num/fixTo.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/num/fixTo
3 | @example
4 | var $fixTo = require('lib/kit/num/fixTo');
5 | $fixTo(0,2); //return '00'
6 | */
7 |
8 | /**
9 | 修正补位
10 | @param {number|string} num 要补位的数字
11 | @param {number} [w=2] w 补位数量
12 | @return {string} 经过补位的字符串
13 | **/
14 | module.exports = function(num, w){
15 | var str = num.toString();
16 | w = Math.max((w || 2) - str.length + 1, 0);
17 | return new Array(w).join('0') + str;
18 | };
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/str/dbcToSbc.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/dbcToSbc
3 | @example
4 | var $dbcToSbc = require('lib/kit/str/dbcToSbc');
5 | $dbcToSbc('SAASDFSADF'); //return 'SAASDFSADF'
6 | **/
7 |
8 | /**
9 | 全角字符转半角字符
10 | @param {string} str 包含了全角字符的字符串
11 | @return {string} 经过转换的字符串
12 | **/
13 | module.exports = function(str){
14 | return str.replace(/[\uff01-\uff5e]/g,function(a){
15 | return String.fromCharCode(a.charCodeAt(0)-65248);
16 | }).replace(/\u3000/g,' ');
17 | };
18 |
19 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/str/hyphenate.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/hyphenate
3 | @example
4 | var $hyphenate = require('lib/kit/str/hyphenate');
5 | $hyphenate('libKitStrHyphenate'); //return 'lib-kit-str-hyphenate'
6 | **/
7 |
8 | /**
9 | 将驼峰格式变为连字符格式
10 | @param {string} str 驼峰格式的字符串
11 | @return {string} 连字符格式的字符串
12 | **/
13 | module.exports = function(str){
14 | return str.replace(/[A-Z]/g, function($0){
15 | return '-' + $0.toLowerCase();
16 | });
17 | };
18 |
19 |
20 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/str/bLength.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/bLength
3 | @example
4 | var $bLength = require('lib/kit/str/bLength');
5 | $bLength('中文cc'); //return 6
6 | **/
7 |
8 | /**
9 | 获取字符串长度,一个中文算2个字符
10 | @param {string} str 要计算长度的字符串
11 | @return {number} 字符串长度
12 | **/
13 | module.exports = function(str){
14 | if (!str) {
15 | return 0;
16 | }
17 | var aMatch = str.match(/[^\x00-\xff]/g);
18 | return (str.length + (!aMatch ? 0 : aMatch.length));
19 | };
20 |
21 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/num/limit.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/num/limit
3 | @example
4 | var $limit = require('lib/kit/num/limit');
5 | $limit(1, 5, 10); //return 5
6 | $limit(6, 5, 10); //return 6
7 | $limit(11, 5, 10); //return 10
8 | **/
9 |
10 | /**
11 | 限制数字在一个范围内
12 | @param {number} num 要限制的数字
13 | @param {number} min 最小边界数值
14 | @param {number} max 最大边界数值
15 | @return {number} 经过限制的数值
16 | **/
17 | module.exports = function(num, min, max){
18 | return Math.min( Math.max(num, min), max );
19 | };
20 |
21 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/obj/type.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/obj/type
3 | @example
4 | var $type = require('lib/kit/obj/type');
5 | console.info($type({})); //function
6 | console.info($type(undefined)); //undefined
7 | **/
8 |
9 | /**
10 | 确认数据类型
11 | @param {mixed} 任何类型数据
12 | @return {string} 对象类型
13 | **/
14 | module.exports = function(item){
15 | var type = Object.
16 | prototype.
17 | toString.
18 | call(item).
19 | toLowerCase().
20 | replace(/^\[object|\]$/gi, '');
21 |
22 | return type;
23 | };
24 |
--------------------------------------------------------------------------------
/generators/app/templates/css/common/reset.css:
--------------------------------------------------------------------------------
1 | /* reset */
2 | body,h1,h2,h3,h4,h5,h6,dl,dt,dd,ul,ol,li,th,td,p,blockquote,pre,form,fieldset,legend,input,button,textarea,article,aside,footer,header,hgroup,nav,section,menu{margin:0; padding:0;-webkit-text-size-adjust:100%;}
3 | table{border-collapse:collapse;border-spacing:0;}
4 | em,i{font-style:normal;}
5 | li{list-style:none;}
6 | img{border:0;}
7 | input,img{vertical-align:middle;}
8 | article,aside,footer,header,hgroup,nav,section,menu{display:block;}
9 | a{text-decoration:none;}
10 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/num/fixTo.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/num/fixTo
3 | @example
4 | var $fixTo = require('lib/kit/num/fixTo');
5 | $fixTo(0,2); //return '00'
6 | */
7 |
8 | /**
9 | 修正补位
10 | @param {number|string} num 要补位的数字
11 | @param {number} [w=2] w 补位数量
12 | @return {string} 经过补位的字符串
13 | **/
14 | module.exports = function(num, w){
15 | var str = num.toString();
16 | w = Math.max((w || 2) - str.length + 1, 0);
17 | return new Array(w).join('0') + str;
18 | };
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/obj/type.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/obj/type
3 | @example
4 | var $type = require('lib/kit/obj/type');
5 | console.info($type({})); //function
6 | console.info($type(undefined)); //undefined
7 | **/
8 |
9 | /**
10 | 确认数据类型
11 | @param {mixed} 任何类型数据
12 | @return {string} 对象类型
13 | **/
14 | module.exports = function(item){
15 | var type = Object.
16 | prototype.
17 | toString.
18 | call(item).
19 | toLowerCase().
20 | replace(/^\[object|\]$/gi, '');
21 |
22 | return type;
23 | };
24 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/str/dbcToSbc.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/dbcToSbc
3 | @example
4 | var $dbcToSbc = require('lib/kit/str/dbcToSbc');
5 | $dbcToSbc('SAASDFSADF'); //return 'SAASDFSADF'
6 | **/
7 |
8 | /**
9 | 全角字符转半角字符
10 | @param {string} str 包含了全角字符的字符串
11 | @return {string} 经过转换的字符串
12 | **/
13 | module.exports = function(str){
14 | return str.replace(/[\uff01-\uff5e]/g,function(a){
15 | return String.fromCharCode(a.charCodeAt(0)-65248);
16 | }).replace(/\u3000/g,' ');
17 | };
18 |
19 |
--------------------------------------------------------------------------------
/generators/app/templates/src/css/common/reset.css:
--------------------------------------------------------------------------------
1 | /* reset */
2 | body,h1,h2,h3,h4,h5,h6,dl,dt,dd,ul,ol,li,th,td,p,blockquote,pre,form,fieldset,legend,input,button,textarea,article,aside,footer,header,hgroup,nav,section,menu{margin:0; padding:0;-webkit-text-size-adjust:100%;}
3 | table{border-collapse:collapse;border-spacing:0;}
4 | em,i{font-style:normal;}
5 | li{list-style:none;}
6 | img{border:0;}
7 | input,img{vertical-align:middle;}
8 | article,aside,footer,header,hgroup,nav,section,menu{display:block;}
9 | a{text-decoration:none;}
10 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/arr/erase.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/arr/erase
3 | @example
4 | var $erase = require('lib/kit/util/erase');
5 | console.info($erase([1,2,3,4,5],3)); //[1,2,4,5]
6 | **/
7 |
8 | /**
9 | 删除数组中的对象
10 | @param {array} arr 要操作的数组
11 | @param {*} item 要清除的对象
12 | @return {number} 对象原本所在位置
13 | **/
14 | module.exports = function(arr, item){
15 | var index = arr.indexOf(item);
16 | if(index >= 0){
17 | arr.splice(index, 1);
18 | }
19 | return index;
20 | };
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "generator-tomg",
3 | "version": "0.1.3",
4 | "description": "tencent house h5 framework",
5 | "files": [
6 | "generators/app"
7 | ],
8 | "keywords": [
9 | "yeoman-generator"
10 | ],
11 | "dependencies": {
12 | "chalk": "^1.1.1",
13 | "globby": "^3.0.0",
14 | "mkdirp": "^0.5.1",
15 | "underscore.string": "^3.3.4",
16 | "wiredep": "^4.0.0",
17 | "yeoman-generator": "^0.20.3",
18 | "yosay": "^1.1.0"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/num/numerical.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/num/numerical
3 | @example
4 | var $numerical = require('lib/kit/num/numerical');
5 | $numerical('10x'); //return 10
6 | $numerical('x10'); //return 0
7 | **/
8 |
9 | /**
10 | 将数据类型转为整数数字
11 | @param {mixed} str 要转换的数据
12 | @param {number} [def=0] 转换失败时的默认值
13 | @param {number} [sys=10] 进制
14 | @return {number} 转换而得的整数
15 | **/
16 | module.exports = function(str, def, sys){
17 | def = def || 0;
18 | sys = sys || 10;
19 | return parseInt(str, sys) || def;
20 | };
21 |
22 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/num/limit.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/num/limit
3 | @example
4 | var $limit = require('lib/kit/num/limit');
5 | $limit(1, 5, 10); //return 5
6 | $limit(6, 5, 10); //return 6
7 | $limit(11, 5, 10); //return 10
8 | **/
9 |
10 | /**
11 | 限制数字在一个范围内
12 | @param {number} num 要限制的数字
13 | @param {number} min 最小边界数值
14 | @param {number} max 最大边界数值
15 | @return {number} 经过限制的数值
16 | **/
17 | module.exports = function(num, min, max){
18 | return Math.min( Math.max(num, min), max );
19 | };
20 |
21 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/num/numerical.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/num/numerical
3 | @example
4 | var $numerical = require('lib/kit/num/numerical');
5 | $numerical('10x'); //return 10
6 | $numerical('x10'); //return 0
7 | **/
8 |
9 | /**
10 | 将数据类型转为整数数字
11 | @param {mixed} str 要转换的数据
12 | @param {number} [def=0] 转换失败时的默认值
13 | @param {number} [sys=10] 进制
14 | @return {number} 转换而得的整数
15 | **/
16 | module.exports = function(str, def, sys){
17 | def = def || 0;
18 | sys = sys || 10;
19 | return parseInt(str, sys) || def;
20 | };
21 |
22 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/str/ipToHex.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/ipToHex
3 | @example
4 | var $ipToHex = require('lib/kit/str/ipToHex');
5 | $ipToHex('255.255.255.255'); //return 'ffffffff'
6 | **/
7 |
8 | /**
9 | 将驼峰格式变为连字符格式
10 | @param {string} ip 十进制数字的IPV4地址
11 | @return {string} 16进制数字IPV4地址
12 | **/
13 | module.exports = function(ip){
14 | return ip.replace(/(\d+)\.*/g, function(match, num) {
15 | num = parseInt(num, 10) || 0;
16 | num = num.toString(16);
17 | if (num.length < 2) {
18 | num = '0' + num;
19 | }
20 | return num;
21 | });
22 | };
23 |
--------------------------------------------------------------------------------
/generators/app/templates/src/html/pages/home.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | @@include('../common/meta.html')
5 | 首页
6 | @@include('../common/link.html')
7 | @@include('../common/script-head.html')
8 |
9 |
10 | @@include('../common/header.html')
11 |
12 | @@include('../mods/pl-home-banner.html')
13 |
14 | @@include('../common/footer.html')
15 | @@include('../common/script-foot.html')
16 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/str/ipToHex.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/ipToHex
3 | @example
4 | var $ipToHex = require('lib/kit/str/ipToHex');
5 | $ipToHex('255.255.255.255'); //return 'ffffffff'
6 | **/
7 |
8 | /**
9 | 将驼峰格式变为连字符格式
10 | @param {string} ip 十进制数字的IPV4地址
11 | @return {string} 16进制数字IPV4地址
12 | **/
13 | module.exports = function(ip){
14 | return ip.replace(/(\d+)\.*/g, function(match, num) {
15 | num = parseInt(num, 10) || 0;
16 | num = num.toString(16);
17 | if (num.length < 2) {
18 | num = '0' + num;
19 | }
20 | return num;
21 | });
22 | };
23 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/arr/include.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/arr/include
3 | @example
4 | var $include = include('lib/kit/arr/include');
5 | console.info($include([1,2,3],4)); //[1,2,3,4]
6 | console.info($include([1,2,3],3)); //[1,2,3]
7 | **/
8 |
9 | var $contains = require('./contains');
10 |
11 | /**
12 | 确认对象是否在数组中,不存在则将对象插入到数组中
13 | @param {array} arr 要操作的数组
14 | @param {*} item 要插入的对象
15 | @return {array} 经过处理的源数组
16 | **/
17 | module.exports = function(arr, item){
18 | if (!$contains(arr, item)){
19 | arr.push(item);
20 | }
21 | return arr;
22 | };
23 |
24 |
25 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/func/once.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/func/once
3 | @example
4 | var $once = require('lib/kit/func/once');
5 | var fn = $once(function(){
6 | console.info('output');
7 | });
8 | fn(); //log output
9 | fn(); //will do nothing
10 | **/
11 |
12 |
13 | /**
14 | 包装为仅触发一次的函数
15 | @param {function} fn 要延迟触发的函数
16 | @param {object} [bind] 函数的this指向
17 | **/
18 | module.exports = function(fn, bind){
19 | return function(){
20 | bind = bind || this;
21 | if(fn){
22 | fn.apply(bind, arguments);
23 | fn = bind = null;
24 | }
25 | };
26 | };
27 |
28 |
29 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/common/active.js:
--------------------------------------------------------------------------------
1 | /**
2 | 为所有 .link 元素添加 active 事件 class : active
3 | **/
4 |
5 | var $ = require('../../lib');
6 |
7 | var $doc = $(document);
8 |
9 | $doc.delegate('.link', 'touchstart', function(evt){
10 | var link = $(evt.currentTarget);
11 | link.addClass('active');
12 | });
13 |
14 | $doc.delegate('.link', 'touchend', function(evt){
15 | var link = $(evt.currentTarget);
16 | link.removeClass('active');
17 | });
18 |
19 | $doc.delegate('.link', 'touchmove', function(evt){
20 | var link = $(evt.currentTarget);
21 | link.removeClass('active');
22 | });
23 |
24 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/common/active.js:
--------------------------------------------------------------------------------
1 | /**
2 | 为所有 .link 元素添加 active 事件 class : active
3 | **/
4 |
5 | var $ = require('../../lib');
6 |
7 | var $doc = $(document);
8 |
9 | $doc.delegate('.link', 'touchstart', function(evt){
10 | var link = $(evt.currentTarget);
11 | link.addClass('active');
12 | });
13 |
14 | $doc.delegate('.link', 'touchend', function(evt){
15 | var link = $(evt.currentTarget);
16 | link.removeClass('active');
17 | });
18 |
19 | $doc.delegate('.link', 'touchmove', function(evt){
20 | var link = $(evt.currentTarget);
21 | link.removeClass('active');
22 | });
23 |
24 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/arr/include.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/arr/include
3 | @example
4 | var $include = include('lib/kit/arr/include');
5 | console.info($include([1,2,3],4)); //[1,2,3,4]
6 | console.info($include([1,2,3],3)); //[1,2,3]
7 | **/
8 |
9 | var $contains = require('./contains');
10 |
11 | /**
12 | 确认对象是否在数组中,不存在则将对象插入到数组中
13 | @param {array} arr 要操作的数组
14 | @param {*} item 要插入的对象
15 | @return {array} 经过处理的源数组
16 | **/
17 | module.exports = function(arr, item){
18 | if (!$contains(arr, item)){
19 | arr.push(item);
20 | }
21 | return arr;
22 | };
23 |
24 |
25 |
--------------------------------------------------------------------------------
/generators/app/templates/js/entry/static/zepto.js:
--------------------------------------------------------------------------------
1 | var Zepto = require('../../vendor/zepto/zepto');
2 | require('../../vendor/zepto/ajax');
3 | require('../../vendor/zepto/event');
4 | require('../../vendor/zepto/form');
5 | require('../../vendor/zepto/ie');
6 |
7 | var $extra = require('../../plugin/extra');
8 | var $prefixfree = require('../../plugin/prefixfree');
9 | var $transit = require('../../plugin/transit');
10 | var $transform = require('../../plugin/transform');
11 |
12 | $extra .mixTo(Zepto);
13 | $prefixfree.mixTo(Zepto);
14 | $transit.mixTo(Zepto);
15 | $transform.mixTo(Zepto);
16 |
17 | module.exports = Zepto;
--------------------------------------------------------------------------------
/generators/app/templates/src/js/mods/pl/goTop.js:
--------------------------------------------------------------------------------
1 | /**
2 | 公共 - 点击返回页面顶端
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $smoothScrollTo = require('../../lib/kit/fx/smoothScrollTo');
7 | var $tplGoTop = require('../tpl/goTop.tpl');
8 |
9 | var root = $($tplGoTop);
10 |
11 | var check = function(){
12 | var scrollHeight = window.scrollY;
13 | if(scrollHeight > 300){
14 | root.show();
15 | }else{
16 | root.hide();
17 | }
18 | };
19 |
20 | root.on('click', function(){
21 | $smoothScrollTo(document.body);
22 | });
23 |
24 | root.appendTo(document.body);
25 | $(window).on('scroll', check);
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/generators/app/templates/js/vendor/zepto/ie.js:
--------------------------------------------------------------------------------
1 | // Zepto.js
2 | // (c) 2010-2015 Thomas Fuchs
3 | // Zepto.js may be freely distributed under the MIT license.
4 |
5 | ;(function(){
6 | // getComputedStyle shouldn't freak out when called
7 | // without a valid element as argument
8 | try {
9 | getComputedStyle(undefined)
10 | } catch(e) {
11 | var nativeGetComputedStyle = getComputedStyle;
12 | window.getComputedStyle = function(element){
13 | try {
14 | return nativeGetComputedStyle(element)
15 | } catch(e) {
16 | return null
17 | }
18 | }
19 | }
20 | })()
21 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/entry/static/zepto.js:
--------------------------------------------------------------------------------
1 | var Zepto = require('../../vendor/zepto/zepto');
2 | require('../../vendor/zepto/ajax');
3 | require('../../vendor/zepto/event');
4 | require('../../vendor/zepto/form');
5 | require('../../vendor/zepto/ie');
6 |
7 | var $extra = require('../../plugin/extra');
8 | var $prefixfree = require('../../plugin/prefixfree');
9 | var $transit = require('../../plugin/transit');
10 | var $transform = require('../../plugin/transform');
11 |
12 | $extra .mixTo(Zepto);
13 | $prefixfree.mixTo(Zepto);
14 | $transit.mixTo(Zepto);
15 | $transform.mixTo(Zepto);
16 |
17 | module.exports = Zepto;
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/func/once.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/func/once
3 | @example
4 | var $once = require('lib/kit/func/once');
5 | var fn = $once(function(){
6 | console.info('output');
7 | });
8 | fn(); //log output
9 | fn(); //will do nothing
10 | **/
11 |
12 |
13 | /**
14 | 包装为仅触发一次的函数
15 | @param {function} fn 要延迟触发的函数
16 | @param {object} [bind] 函数的this指向
17 | **/
18 | module.exports = function(fn, bind){
19 | return function(){
20 | bind = bind || this;
21 | if(fn){
22 | fn.apply(bind, arguments);
23 | fn = bind = null;
24 | }
25 | };
26 | };
27 |
28 |
29 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/vendor/zepto/ie.js:
--------------------------------------------------------------------------------
1 | // Zepto.js
2 | // (c) 2010-2015 Thomas Fuchs
3 | // Zepto.js may be freely distributed under the MIT license.
4 |
5 | ;(function(){
6 | // getComputedStyle shouldn't freak out when called
7 | // without a valid element as argument
8 | try {
9 | getComputedStyle(undefined)
10 | } catch(e) {
11 | var nativeGetComputedStyle = getComputedStyle;
12 | window.getComputedStyle = function(element){
13 | try {
14 | return nativeGetComputedStyle(element)
15 | } catch(e) {
16 | return null
17 | }
18 | }
19 | }
20 | })()
21 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/util/scrollFix.js:
--------------------------------------------------------------------------------
1 | /**
2 | 屏幕滚动区域固定
3 | **/
4 |
5 | var $ = require('../../../lib');
6 | var $stockMonitor = require('./stockMonitor');
7 |
8 | var $body = $(document.body);
9 |
10 | var scrollFix = new $stockMonitor();
11 |
12 | var prevWidth = 0;
13 |
14 | scrollFix.on = function(){
15 | //禁止屏幕滚动
16 | prevWidth = $body.width();
17 | $body.css('width', prevWidth + 'px');
18 | $body.css('overflow', 'hidden');
19 | };
20 |
21 | scrollFix.off = function(){
22 | prevWidth = 0;
23 | $body.css('overflow', '');
24 | $body.css('width', '');
25 | };
26 |
27 | module.exports = scrollFix;
28 |
29 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/util/scrollFix.js:
--------------------------------------------------------------------------------
1 | /**
2 | 屏幕滚动区域固定
3 | **/
4 |
5 | var $ = require('../../../lib');
6 | var $stockMonitor = require('./stockMonitor');
7 |
8 | var $body = $(document.body);
9 |
10 | var scrollFix = new $stockMonitor();
11 |
12 | var prevWidth = 0;
13 |
14 | scrollFix.on = function(){
15 | //禁止屏幕滚动
16 | prevWidth = $body.width();
17 | $body.css('width', prevWidth + 'px');
18 | $body.css('overflow', 'hidden');
19 | };
20 |
21 | scrollFix.off = function(){
22 | prevWidth = 0;
23 | $body.css('overflow', '');
24 | $body.css('width', '');
25 | };
26 |
27 | module.exports = scrollFix;
28 |
29 |
--------------------------------------------------------------------------------
/generators/app/templates/src/css/common/sprite.css:
--------------------------------------------------------------------------------
1 | .icon {
2 | background-image: url(../images/sprite.png);
3 | }
4 | @media (-webkit-min-device-pixel-ratio: 2),
5 | (min-resolution: 192dpi) {
6 | .icon {
7 | background-image: url(../images/sprite@2x.png);
8 | background-size: 0.35rem 0.96rem;
9 | }
10 | }
11 | .icon-to-top {
12 | background-position: 0rem 0rem;
13 | width: 0.26rem;
14 | height: 0.26rem;
15 | }
16 | .icon-right {
17 | background-position: 0rem -0.26rem;
18 | width: 0.35rem;
19 | height: 0.35rem;
20 | }
21 | .icon-warn {
22 | background-position: 0rem -0.61rem;
23 | width: 0.35rem;
24 | height: 0.35rem;
25 | }
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/arr/find.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/arr/find
3 | @example
4 | var $find = require('lib/kit/util/find');
5 | console.info($find([1,2,3,4,5],function(item){
6 | return item < 3;
7 | }); //[0, 1]
8 | **/
9 |
10 | /**
11 | 查找符合条件的元素在数组中的位置
12 | @param {array} arr 要操作的数组
13 | @param {function} fn 条件函数
14 | @param {object} [context] 函数的this指向
15 | @return {array} 符合条件的元素在数组中的位置
16 | **/
17 | module.exports = function(arr, fn, context){
18 | var positions = [];
19 | arr.forEach(function(item, index){
20 | if(fn.call(context, item, index, arr)){
21 | positions.push(index);
22 | }
23 | });
24 | return positions;
25 | };
26 |
27 |
28 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/str/leftB.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/leftB
3 | @example
4 | var $leftB = require('lib/kit/str/leftB');
5 | //向汉编致敬
6 | $leftB('世界真和谐', 6); //return '世界真'
7 | **/
8 |
9 | /**
10 | 从左到右取字符串,中文算两个字符
11 | @param {String} str
12 | @param {Number} lens
13 | @return {String} str
14 | **/
15 | var $bLength = require('./bLength');
16 |
17 | module.exports = function(str, lens){
18 | var s = str.replace(/\*/g, ' ').replace(/[^\x00-\xff]/g, '**');
19 | str = str.slice(0, s.slice(0, lens).replace(/\*\*/g, ' ').replace(/\*/g, '').length);
20 | if ($bLength(str) > lens && lens > 0) {
21 | str = str.slice(0, str.length - 1);
22 | }
23 | return str;
24 | };
25 |
26 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/tpl/confirm.tpl:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/generators/app/templates/html/common/header.html:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/tpl/confirm.tpl:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/arr/find.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/arr/find
3 | @example
4 | var $find = require('lib/kit/util/find');
5 | console.info($find([1,2,3,4,5],function(item){
6 | return item < 3;
7 | }); //[0, 1]
8 | **/
9 |
10 | /**
11 | 查找符合条件的元素在数组中的位置
12 | @param {array} arr 要操作的数组
13 | @param {function} fn 条件函数
14 | @param {object} [context] 函数的this指向
15 | @return {array} 符合条件的元素在数组中的位置
16 | **/
17 | module.exports = function(arr, fn, context){
18 | var positions = [];
19 | arr.forEach(function(item, index){
20 | if(fn.call(context, item, index, arr)){
21 | positions.push(index);
22 | }
23 | });
24 | return positions;
25 | };
26 |
27 |
28 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/arr/flatten.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/arr/flatten
3 | @example
4 | var $flatten = require('lib/kit/util/flatten');
5 | console.info($flatten([1,[2,3],[4,5]])); //[1,2,3,4,5]
6 | **/
7 |
8 | /**
9 | 数组扁平化
10 | @param {array} arr 要操作的数组
11 | @return {array} 经过扁平化处理的数组
12 | **/
13 |
14 | var $ = require('../../lib');
15 |
16 | var flatten = function(arr){
17 | var array = [];
18 | for (var i = 0, l = arr.length; i < l; i++){
19 | var type = $.type(arr[i]);
20 | if (type === 'null'){
21 | continue;
22 | }
23 | array = array.concat(
24 | type === 'array' ? flatten(arr[i]) : arr[i]
25 | );
26 | }
27 | return array;
28 | };
29 |
30 | module.exports = flatten;
31 |
32 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/str/decodeHTML.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/decodeHTML
3 | @example
4 | var $decodeHTML = require('lib/kit/str/decodeHTML');
5 | $decodeHTML('&<>$nbsp;"'); //return '&<> "'
6 | **/
7 |
8 | /**
9 | 解码HTML,将实体字符转换为HTML字符
10 | @param {string} str 含有实体字符标记的字符串
11 | @return {string} HTML字符串
12 | **/
13 | module.exports = function(str){
14 | if(typeof str !== 'string'){
15 | throw 'decodeHTML need a string as parameter';
16 | }
17 | return str.replace(/"/g,'"').
18 | replace(/</g,'<').
19 | replace(/>/g,'>').
20 | replace(/'/g,'\'').
21 | replace(/ /g,'\u00A0').
22 | replace(/ /g,'\u0020').
23 | replace(/&/g,'&');
24 | };
25 |
26 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/str/leftB.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/leftB
3 | @example
4 | var $leftB = require('lib/kit/str/leftB');
5 | //向汉编致敬
6 | $leftB('世界真和谐', 6); //return '世界真'
7 | **/
8 |
9 | /**
10 | 从左到右取字符串,中文算两个字符
11 | @param {String} str
12 | @param {Number} lens
13 | @return {String} str
14 | **/
15 | var $bLength = require('./bLength');
16 |
17 | module.exports = function(str, lens){
18 | var s = str.replace(/\*/g, ' ').replace(/[^\x00-\xff]/g, '**');
19 | str = str.slice(0, s.slice(0, lens).replace(/\*\*/g, ' ').replace(/\*/g, '').length);
20 | if ($bLength(str) > lens && lens > 0) {
21 | str = str.slice(0, str.length - 1);
22 | }
23 | return str;
24 | };
25 |
26 |
--------------------------------------------------------------------------------
/generators/app/templates/src/html/common/script-head.html:
--------------------------------------------------------------------------------
1 |
20 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/dom/placeholder.js:
--------------------------------------------------------------------------------
1 | /**
2 | placeholder兼容性处理
3 | **/
4 |
5 | var $ = require('../../../lib');
6 | var support_placeholder = 'placeholder' in $('input').get(0);
7 |
8 | module.exports = function(node){
9 | if(support_placeholder){return;}
10 | node = $(node);
11 |
12 | var text = node.attr('placeholder');
13 | var checkBlur = function(){
14 | if(!node.val()){
15 | node.val(text);
16 | node.css('color', '#a1a1a1');
17 | }else{
18 | node.css('color', '');
19 | }
20 | };
21 |
22 | node.on('blur', checkBlur);
23 | node.on('focus', function(){
24 | if(node.val() === text){
25 | node.val('');
26 | node.css('color', '');
27 | }
28 | });
29 |
30 | checkBlur();
31 | };
32 |
33 |
34 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/str/encodeHTML.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/encodeHTML
3 | @example
4 | var $encodeHTML = require('lib/kit/str/encodeHTML');
5 | $encodeHTML('&<>" '); //return '&<>"$nbsp;'
6 | **/
7 |
8 | /**
9 | 编码HTML,将HTML字符转为实体字符
10 | @param {string} str 含有HTML字符的字符串
11 | @return {string} 经过转换的字符串
12 | **/
13 | module.exports = function(str){
14 | if(typeof str !== 'string'){
15 | throw 'encodeHTML need a string as parameter';
16 | }
17 | return str.replace(/\&/g,'&').
18 | replace(/"/g,'"').
19 | replace(//g,'>').
21 | replace(/\'/g,''').
22 | replace(/\u00A0/g,' ').
23 | replace(/(\u0020|\u000B|\u2028|\u2029|\f)/g,' ');
24 | };
25 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/dom/placeholder.js:
--------------------------------------------------------------------------------
1 | /**
2 | placeholder兼容性处理
3 | **/
4 |
5 | var $ = require('../../../lib');
6 | var support_placeholder = 'placeholder' in $('input').get(0);
7 |
8 | module.exports = function(node){
9 | if(support_placeholder){return;}
10 | node = $(node);
11 |
12 | var text = node.attr('placeholder');
13 | var checkBlur = function(){
14 | if(!node.val()){
15 | node.val(text);
16 | node.css('color', '#a1a1a1');
17 | }else{
18 | node.css('color', '');
19 | }
20 | };
21 |
22 | node.on('blur', checkBlur);
23 | node.on('focus', function(){
24 | if(node.val() === text){
25 | node.val('');
26 | node.css('color', '');
27 | }
28 | });
29 |
30 | checkBlur();
31 | };
32 |
33 |
34 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/arr/flatten.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/arr/flatten
3 | @example
4 | var $flatten = require('lib/kit/util/flatten');
5 | console.info($flatten([1,[2,3],[4,5]])); //[1,2,3,4,5]
6 | **/
7 |
8 | /**
9 | 数组扁平化
10 | @param {array} arr 要操作的数组
11 | @return {array} 经过扁平化处理的数组
12 | **/
13 |
14 | var $ = require('../../lib');
15 |
16 | var flatten = function(arr){
17 | var array = [];
18 | for (var i = 0, l = arr.length; i < l; i++){
19 | var type = $.type(arr[i]);
20 | if (type === 'null'){
21 | continue;
22 | }
23 | array = array.concat(
24 | type === 'array' ? flatten(arr[i]) : arr[i]
25 | );
26 | }
27 | return array;
28 | };
29 |
30 | module.exports = flatten;
31 |
32 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/func/lock.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/func/lock
3 | @example
4 | var $lock = require('lib/kit/func/lock');
5 | var request = function(){
6 | console.info('do request');
7 | };
8 | $('#input').keydown($lock(request, 200, comp));
9 | //连续按键,仅在200ms结束后再次按键,才会再次请求
10 | **/
11 |
12 | /**
13 | 包装为触发一次后,预置时间内不能再次触发的函数
14 | @param {function} fn 要延迟触发的函数
15 | @param {number} delay 延迟时间[ms]
16 | @param {object} [bind] 函数的this指向
17 | **/
18 | module.exports = function(fn, delay, bind){
19 | var timer = null;
20 | return function(){
21 | if(timer){return;}
22 | bind = bind || this;
23 | var args = arguments;
24 | timer = setTimeout(function(){
25 | timer = null;
26 | }, delay);
27 | fn.apply(bind, args);
28 | };
29 | };
30 |
31 |
32 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/func/lock.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/func/lock
3 | @example
4 | var $lock = require('lib/kit/func/lock');
5 | var request = function(){
6 | console.info('do request');
7 | };
8 | $('#input').keydown($lock(request, 200, comp));
9 | //连续按键,仅在200ms结束后再次按键,才会再次请求
10 | **/
11 |
12 | /**
13 | 包装为触发一次后,预置时间内不能再次触发的函数
14 | @param {function} fn 要延迟触发的函数
15 | @param {number} delay 延迟时间[ms]
16 | @param {object} [bind] 函数的this指向
17 | **/
18 | module.exports = function(fn, delay, bind){
19 | var timer = null;
20 | return function(){
21 | if(timer){return;}
22 | bind = bind || this;
23 | var args = arguments;
24 | timer = setTimeout(function(){
25 | timer = null;
26 | }, delay);
27 | fn.apply(bind, args);
28 | };
29 | };
30 |
31 |
32 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/str/substitute.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/substitute
3 | @example
4 | var $substitute = require('lib/kit/str/substitute');
5 | $substitute('{{city}}欢迎您', {{city:'北京'}}); //return '北京欢迎您'
6 | **/
7 |
8 | /**
9 | 简单模板函数
10 | @param {string} str 要替换模板的字符串
11 | @param {object} obj 模板对应的数据对象
12 | @param {regExp} [reg=/\\?\{\{([^{}]+)\}\}/g] 解析模板的正则表达式
13 | @return {string} 替换了模板的字符串
14 | **/
15 | module.exports = function(str, obj, reg){
16 | return str.replace(reg || (/\\?\{\{([^{}]+)\}\}/g), function(match, name){
17 | if (match.charAt(0) === '\\'){
18 | return match.slice(1);
19 | }
20 | //注意:obj[name] != null 等同于 obj[name] !== null && obj[name] !== undefined
21 | return (obj[name] != null) ? obj[name] : '';
22 | });
23 | };
24 |
25 |
26 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/str/decodeHTML.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/decodeHTML
3 | @example
4 | var $decodeHTML = require('lib/kit/str/decodeHTML');
5 | $decodeHTML('&<>$nbsp;"'); //return '&<> "'
6 | **/
7 |
8 | /**
9 | 解码HTML,将实体字符转换为HTML字符
10 | @param {string} str 含有实体字符标记的字符串
11 | @return {string} HTML字符串
12 | **/
13 | module.exports = function(str){
14 | if(typeof str !== 'string'){
15 | throw 'decodeHTML need a string as parameter';
16 | }
17 | return str.replace(/"/g,'"').
18 | replace(/</g,'<').
19 | replace(/>/g,'>').
20 | replace(/'/g,'\'').
21 | replace(/ /g,'\u00A0').
22 | replace(/ /g,'\u0020').
23 | replace(/`/g, '`').
24 | replace(/&/g,'&');
25 | };
26 |
27 |
28 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/str/encodeHTML.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/encodeHTML
3 | @example
4 | var $encodeHTML = require('lib/kit/str/encodeHTML');
5 | $encodeHTML('&<>" '); //return '&<>"$nbsp;'
6 | **/
7 |
8 | /**
9 | 编码HTML,将HTML字符转为实体字符
10 | @param {string} str 含有HTML字符的字符串
11 | @return {string} 经过转换的字符串
12 | **/
13 | module.exports = function(str){
14 | if(typeof str !== 'string'){
15 | throw 'encodeHTML need a string as parameter';
16 | }
17 | return str.replace(/\&/g,'&').
18 | replace(/"/g,'"').
19 | replace(//g,'>').
21 | replace(/\'/g,''').
22 | replace(/\u00A0/g,' ').
23 | replace(/`/g,'`').
24 | replace(/(\u0020|\u000B|\u2028|\u2029|\f)/g,' ');
25 | };
26 |
27 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/obj/find.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/obj/find
3 | @example
4 | var $find = require('lib/kit/obj/find');
5 | var obj = {a:{b:{c:1}}};
6 | console.info($find(obj,'a.b.c')); //1
7 | console.info($find(obj,'a.c')); //undefined
8 | **/
9 |
10 | /**
11 | 查找对象路径上的值
12 | @param {object} object 要查找的对象
13 | @param {string} path 要查找的路径
14 | @return {*} 对象路径上的值
15 | **/
16 | module.exports = function(object, path){
17 | path = path || '';
18 | if(!path){return object;}
19 | if(!object){return object;}
20 |
21 | var queue = path.split('.');
22 | var name;
23 | var pos = object;
24 |
25 | while(queue.length){
26 | name = queue.shift();
27 | if(!pos[name]){
28 | return pos[name];
29 | }else{
30 | pos = pos[name];
31 | }
32 | }
33 |
34 | return pos;
35 | };
36 |
37 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/obj/find.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/obj/find
3 | @example
4 | var $find = require('lib/kit/obj/find');
5 | var obj = {a:{b:{c:1}}};
6 | console.info($find(obj,'a.b.c')); //1
7 | console.info($find(obj,'a.c')); //undefined
8 | **/
9 |
10 | /**
11 | 查找对象路径上的值
12 | @param {object} object 要查找的对象
13 | @param {string} path 要查找的路径
14 | @return {*} 对象路径上的值
15 | **/
16 | module.exports = function(object, path){
17 | path = path || '';
18 | if(!path){return object;}
19 | if(!object){return object;}
20 |
21 | var queue = path.split('.');
22 | var name;
23 | var pos = object;
24 |
25 | while(queue.length){
26 | name = queue.shift();
27 | if(!pos[name]){
28 | return pos[name];
29 | }else{
30 | pos = pos[name];
31 | }
32 | }
33 |
34 | return pos;
35 | };
36 |
37 |
--------------------------------------------------------------------------------
/generators/app/templates/html/common/script-head.html:
--------------------------------------------------------------------------------
1 |
23 |
26 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/str/substitute.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/substitute
3 | @example
4 | var $substitute = require('lib/kit/str/substitute');
5 | $substitute('{{city}}欢迎您', {{city:'北京'}}); //return '北京欢迎您'
6 | **/
7 |
8 | /**
9 | 简单模板函数
10 | @param {string} str 要替换模板的字符串
11 | @param {object} obj 模板对应的数据对象
12 | @param {regExp} [reg=/\\?\{\{([^{}]+)\}\}/g] 解析模板的正则表达式
13 | @return {string} 替换了模板的字符串
14 | **/
15 | module.exports = function(str, obj, reg){
16 | return str.replace(reg || (/\\?\{\{([^{}]+)\}\}/g), function(match, name){
17 | if (match.charAt(0) === '\\'){
18 | return match.slice(1);
19 | }
20 | //注意:obj[name] != null 等同于 obj[name] !== null && obj[name] !== undefined
21 | return (obj[name] != null) ? obj[name] : '';
22 | });
23 | };
24 |
25 |
26 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/func/delay.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/func/delay
3 | @example
4 | var $delay = require('lib/kit/func/delay');
5 | var comp = {
6 | countWords : function(){
7 | console.info(this.length);
8 | }
9 | };
10 | $('#input').keydown($delay(function(){
11 | this.length = $('#input').val().length;
12 | this.countWords();
13 | }, 200, comp));
14 | **/
15 |
16 | /**
17 | 包装为延迟触发的函数
18 | @param {function} fn 要延迟触发的函数
19 | @param {number} delay 延迟时间[ms]
20 | @param {object} [bind] 函数的this指向
21 | **/
22 | module.exports = function(fn, delay, bind){
23 | var timer = null;
24 | return function(){
25 | bind = bind || this;
26 | if(timer){clearTimeout(timer);}
27 | var args = arguments;
28 | timer = setTimeout(function(){
29 | fn.apply(bind, args);
30 | }, delay);
31 | };
32 | };
33 |
34 |
35 |
--------------------------------------------------------------------------------
/generators/app/templates/docs/spec-code.md:
--------------------------------------------------------------------------------
1 | # 开发规范
2 |
3 | - 代码缩进使用tab。
4 | - tab缩进在很多编辑器很容易修改缩进宽度。
5 | - 另:请原谅我这个tab党。
6 |
7 | - 除第三方组件外,所有文件名称必须为驼峰格式。
8 | - 方便引用时直接copy字符串。
9 |
10 | - 所有变量名称尽量使用驼峰格式,避免使用下划线。
11 | - 除非需要修改的源数据内是下划线格式。
12 | - 可稍微缩短代码宽度。
13 |
14 | - 广播名称必须为连字符(减号"-")格式。
15 | - 至少2个单词
16 | - 这样便于搜索
17 |
18 | - 引用外部模块式,指向外部模块的变量名应当使用'$'字符作为变量名前缀。
19 | - 便于搜索
20 | - 避免占用易于使用的变量名
21 |
22 | - 字符串统一使用单引号包裹。
23 | - 同意添加html内容
24 |
25 | - 需要后端输出到页面的所有全局变量,统一放在 window.$CONFIG 对象。
26 | - 避免全局变量
27 | - 方便控制台查询
28 |
29 | - 代码开发完成后,请运行 grunt test 检测代码格式。
30 | - 使用jshint规范了代码格式
31 |
32 | - 所有要引用库的地方,使用 require('lib')。
33 | - 组件不仅仅用于PC端,也希望能复用到移动端
34 |
35 | - html属性名称使用连字符分隔单词,如: id="box-name", role="data-action"。
36 | - 方便搜索,避免与变量名重合
37 |
38 | - 提交代码时,先提交src目录,再提交dist,online目录
39 | - 这样可以避免每次提交很多文件。
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/func/delay.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/func/delay
3 | @example
4 | var $delay = require('lib/kit/func/delay');
5 | var comp = {
6 | countWords : function(){
7 | console.info(this.length);
8 | }
9 | };
10 | $('#input').keydown($delay(function(){
11 | this.length = $('#input').val().length;
12 | this.countWords();
13 | }, 200, comp));
14 | **/
15 |
16 | /**
17 | 包装为延迟触发的函数
18 | @param {function} fn 要延迟触发的函数
19 | @param {number} delay 延迟时间[ms]
20 | @param {object} [bind] 函数的this指向
21 | **/
22 | module.exports = function(fn, delay, bind){
23 | var timer = null;
24 | return function(){
25 | bind = bind || this;
26 | if(timer){clearTimeout(timer);}
27 | var args = arguments;
28 | timer = setTimeout(function(){
29 | fn.apply(bind, args);
30 | }, delay);
31 | };
32 | };
33 |
34 |
35 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/util/stockMonitor.js:
--------------------------------------------------------------------------------
1 | /**
2 | 存量监视器
3 |
4 | 提供固定的 watch unwtach 方法
5 | 检查存量数组是否存在指定数量的对象,并触发开关接口函数 on, off
6 | **/
7 |
8 | var $ = require('../../../lib');
9 | var $include = require('../arr/include');
10 | var $erase = require('../arr/erase');
11 |
12 | var StockMonitor = function(spec){
13 | this.conf = $.extend({
14 | length : 0
15 | }, spec);
16 | this.observed = [];
17 | };
18 |
19 | StockMonitor.prototype = {
20 | watch : function(obj){
21 | $include(this.observed, obj);
22 | this.check();
23 | },
24 | ignore : function(obj){
25 | $erase(this.observed, obj);
26 | this.check();
27 | },
28 | check : function(){
29 | if(this.observed.length > this.conf.length){
30 | this.on();
31 | }else{
32 | this.off();
33 | }
34 | },
35 | on : $.noop,
36 | off : $.noop
37 | };
38 |
39 | module.exports = StockMonitor;
40 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/util/stockMonitor.js:
--------------------------------------------------------------------------------
1 | /**
2 | 存量监视器
3 |
4 | 提供固定的 watch unwtach 方法
5 | 检查存量数组是否存在指定数量的对象,并触发开关接口函数 on, off
6 | **/
7 |
8 | var $ = require('../../../lib');
9 | var $include = require('../arr/include');
10 | var $erase = require('../arr/erase');
11 |
12 | var StockMonitor = function(spec){
13 | this.conf = $.extend({
14 | length : 0
15 | }, spec);
16 | this.observed = [];
17 | };
18 |
19 | StockMonitor.prototype = {
20 | watch : function(obj){
21 | $include(this.observed, obj);
22 | this.check();
23 | },
24 | ignore : function(obj){
25 | $erase(this.observed, obj);
26 | this.check();
27 | },
28 | check : function(){
29 | if(this.observed.length > this.conf.length){
30 | this.on();
31 | }else{
32 | this.off();
33 | }
34 | },
35 | on : $.noop,
36 | off : $.noop
37 | };
38 |
39 | module.exports = StockMonitor;
40 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/obj/cover.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/obj/cover
3 | @example
4 | var $cover = require('lib/kit/obj/cover');
5 | var obj = {a:1,b:2};
6 | console.info($cover(obj,{b:3,c:4})); //{a:1,b:3}
7 | **/
8 |
9 | /**
10 | 覆盖对象,不添加新的键
11 | @param {object} object 要覆盖的对象
12 | @param {object} item 要覆盖的属性键值对
13 | @return {object} 覆盖后的源对象
14 | **/
15 | module.exports = function(){
16 | var args = Array.prototype.slice.call(arguments);
17 | var object = args.shift();
18 | if(object && typeof(object.hasOwnProperty) === 'function'){
19 | var keys = Object.keys(object);
20 | args.forEach(function(item){
21 | if(item && typeof(item.hasOwnProperty) === 'function'){
22 | keys.forEach(function(key){
23 | if(item.hasOwnProperty(key)){
24 | object[key] = item[key];
25 | }
26 | });
27 | }
28 | });
29 | }else{
30 | return object;
31 | }
32 |
33 | return object;
34 | };
35 |
36 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/obj/cover.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/obj/cover
3 | @example
4 | var $cover = require('lib/kit/obj/cover');
5 | var obj = {a:1,b:2};
6 | console.info($cover(obj,{b:3,c:4})); //{a:1,b:3}
7 | **/
8 |
9 | /**
10 | 覆盖对象,不添加新的键
11 | @param {object} object 要覆盖的对象
12 | @param {object} item 要覆盖的属性键值对
13 | @return {object} 覆盖后的源对象
14 | **/
15 | module.exports = function(){
16 | var args = Array.prototype.slice.call(arguments);
17 | var object = args.shift();
18 | if(object && typeof(object.hasOwnProperty) === 'function'){
19 | var keys = Object.keys(object);
20 | args.forEach(function(item){
21 | if(item && typeof(item.hasOwnProperty) === 'function'){
22 | keys.forEach(function(key){
23 | if(item.hasOwnProperty(key)){
24 | object[key] = item[key];
25 | }
26 | });
27 | }
28 | });
29 | }else{
30 | return object;
31 | }
32 |
33 | return object;
34 | };
35 |
36 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/func/regular.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/func/regular
3 | @example
4 | var comp = {
5 | countWords : function(){
6 | console.info(this.length);
7 | }
8 | };
9 | $('#input').keydown($regular(function(){
10 | this.length = $('#input').val().length;
11 | this.countWords();
12 | }, 200, comp));
13 | **/
14 |
15 | /**
16 | 包装为规律触发的函数,用于降低密集事件的处理频率
17 | @param {function} fn 要延迟触发的函数
18 | @param {number} delay 延迟时间[ms]
19 | @param {object} [bind] 函数的this指向
20 | **/
21 | module.exports = function(fn, delay, bind){
22 | var enable = true;
23 | var timer = null;
24 | return function(){
25 | bind = bind || this;
26 | enable = true;
27 | var args = arguments;
28 | if(!timer){
29 | timer = setInterval(function(){
30 | fn.apply(bind, args);
31 | if(!enable){
32 | clearInterval(timer);
33 | timer = null;
34 | }
35 | enable = false;
36 | }, delay);
37 | }
38 | };
39 | };
40 |
41 |
--------------------------------------------------------------------------------
/generators/app/templates/css/common/public.css:
--------------------------------------------------------------------------------
1 |
2 | .icon{
3 | display: block;
4 | overflow: hidden;
5 | }
6 | .loadMore{
7 | height: 0.8rem;
8 | line-height: 0.8rem;
9 | background: #fff;
10 | text-align: center;
11 | display: none;
12 | }
13 | .loadMore .icon-loading{
14 | display: inline-block;
15 | vertical-align: middle;
16 | }
17 | .table{
18 | padding: 0.12rem;
19 | background-color: #fff;
20 | }
21 | .table .tr{
22 | display: -webkit-box;
23 | display: -moz-box;
24 | display: -ms-flexbox;
25 | display: flex;
26 | -webkit-box-pack: justify;
27 | -moz-box-pack: justify;
28 | -ms-flex-pack: justify;
29 | -webkit-box-align: center;
30 | -moz-box-align: justify;
31 | -ms-flex-align: center;
32 | justify-content: space-between;
33 | margin-bottom: 0.1rem;
34 | }
35 | .table .tr .column{
36 | -webkit-box-flex: 1;
37 | -moz-box-flex: 1;
38 | -webkit-flex: 1;
39 | -ms-flex: 1;
40 | flex: 1;
41 | }
42 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/io/loadScript.js:
--------------------------------------------------------------------------------
1 | /**
2 | 该方法为zepto而存在,使用jquery请用$.getScript替代
3 | @module lib/kit/io/loadScript
4 | **/
5 |
6 | var $ = require('../../../lib');
7 |
8 | /**
9 | 加载script
10 | @param {object} options script选项
11 | @param {string} options.url script地址
12 | @param {string} [options.type='text/javascript'] script类型
13 | @param {string} [options.charset='utf-8'] script编码
14 | @param {function} [options.onLoad] script加载完成的回调函数
15 | **/
16 | module.exports = function(options){
17 | var conf = $.extend({
18 | url : '',
19 | type : 'text/javascript',
20 | charset : 'utf-8',
21 | onLoad : $.noop
22 | }, options);
23 |
24 | var script = $(document.createElement('script'));
25 | script.on('load', function(){
26 | conf.onLoad();
27 | delete script.onload;
28 | $(script).off().remove();
29 | }).attr({
30 | src : conf.url,
31 | charset : conf.charset,
32 | type : conf.type
33 | }).appendTo( $('head') );
34 | };
35 |
36 |
37 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/common/tip.js:
--------------------------------------------------------------------------------
1 | /**
2 | tip提示信息
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $tip = require('../ui/tip');
7 | var $cover = require('../../lib/kit/obj/cover');
8 |
9 | var TIMEOUT = 2000;
10 | var layer = null;
11 | var timer = null;
12 |
13 | module.exports = function(content, options){
14 | if(!options && $.isPlainObject(content)){
15 | options = content;
16 | }else{
17 | options = options || {};
18 | options.content = content;
19 | }
20 |
21 | var conf = $cover({
22 | target : 'screen',
23 | parent : null,
24 | visiblePos : 0,
25 | content : ''
26 | }, options);
27 |
28 | if(!layer){
29 | layer = new $tip();
30 | }
31 |
32 | layer.setOptions(conf);
33 |
34 | layer.role('root').html(conf.content);
35 |
36 | if(timer){
37 | clearTimeout(timer);
38 | timer = null;
39 | }
40 |
41 | layer.show();
42 |
43 | timer = setTimeout(function(){
44 | layer.hide();
45 | timer = null;
46 | }, TIMEOUT);
47 | };
48 |
49 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/common/tip.js:
--------------------------------------------------------------------------------
1 | /**
2 | tip提示信息
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $tip = require('../ui/tip');
7 | var $cover = require('../../lib/kit/obj/cover');
8 |
9 | var TIMEOUT = 2000;
10 | var layer = null;
11 | var timer = null;
12 |
13 | module.exports = function(content, options){
14 | if(!options && $.isPlainObject(content)){
15 | options = content;
16 | }else{
17 | options = options || {};
18 | options.content = content;
19 | }
20 |
21 | var conf = $cover({
22 | target : 'screen',
23 | parent : null,
24 | visiblePos : 0,
25 | content : ''
26 | }, options);
27 |
28 | if(!layer){
29 | layer = new $tip();
30 | }
31 |
32 | layer.setOptions(conf);
33 |
34 | layer.role('root').html(conf.content);
35 |
36 | if(timer){
37 | clearTimeout(timer);
38 | timer = null;
39 | }
40 |
41 | layer.show();
42 |
43 | timer = setTimeout(function(){
44 | layer.hide();
45 | timer = null;
46 | }, TIMEOUT);
47 | };
48 |
49 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/func/regular.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/func/regular
3 | @example
4 | var comp = {
5 | countWords : function(){
6 | console.info(this.length);
7 | }
8 | };
9 | $('#input').keydown($regular(function(){
10 | this.length = $('#input').val().length;
11 | this.countWords();
12 | }, 200, comp));
13 | **/
14 |
15 | /**
16 | 包装为规律触发的函数,用于降低密集事件的处理频率
17 | @param {function} fn 要延迟触发的函数
18 | @param {number} delay 延迟时间[ms]
19 | @param {object} [bind] 函数的this指向
20 | **/
21 | module.exports = function(fn, delay, bind){
22 | var enable = true;
23 | var timer = null;
24 | return function(){
25 | bind = bind || this;
26 | enable = true;
27 | var args = arguments;
28 | if(!timer){
29 | timer = setInterval(function(){
30 | fn.apply(bind, args);
31 | if(!enable){
32 | clearInterval(timer);
33 | timer = null;
34 | }
35 | enable = false;
36 | }, delay);
37 | }
38 | };
39 | };
40 |
41 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/func/queue.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/func/queue
3 | @example
4 | var $queue = require('lib/kit/func/queue');
5 | var t1 = Date.now();
6 | var doSomthing = $queue(function(index){
7 | console.info(index + ':' + (Date.now() - t1));
8 | }, 200);
9 | //每隔200ms输出一个日志。
10 | for(var i = 0; i < 10; i++){
11 | doSomthing(i);
12 | }
13 | **/
14 |
15 | /**
16 | 包装为一个队列,按设置的时间间隔触发
17 | @param {function} fn 要延迟触发的函数
18 | @param {number} delay 延迟时间[ms]
19 | @param {object} [bind] 函数的this指向
20 | **/
21 | module.exports = function(fn, delay, bind){
22 | var timer = null;
23 | var queue = [];
24 | return function(){
25 | bind = bind || this;
26 | var args = arguments;
27 | queue.push(function(){
28 | fn.apply(bind, args);
29 | });
30 | if(!timer){
31 | timer = setInterval(function(){
32 | if(!queue.length){
33 | clearInterval(timer);
34 | timer = null;
35 | }else{
36 | queue.shift()();
37 | }
38 | }, delay);
39 | }
40 | };
41 | };
42 |
43 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/func/queue.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/func/queue
3 | @example
4 | var $queue = require('lib/kit/func/queue');
5 | var t1 = Date.now();
6 | var doSomthing = $queue(function(index){
7 | console.info(index + ':' + (Date.now() - t1));
8 | }, 200);
9 | //每隔200ms输出一个日志。
10 | for(var i = 0; i < 10; i++){
11 | doSomthing(i);
12 | }
13 | **/
14 |
15 | /**
16 | 包装为一个队列,按设置的时间间隔触发
17 | @param {function} fn 要延迟触发的函数
18 | @param {number} delay 延迟时间[ms]
19 | @param {object} [bind] 函数的this指向
20 | **/
21 | module.exports = function(fn, delay, bind){
22 | var timer = null;
23 | var queue = [];
24 | return function(){
25 | bind = bind || this;
26 | var args = arguments;
27 | queue.push(function(){
28 | fn.apply(bind, args);
29 | });
30 | if(!timer){
31 | timer = setInterval(function(){
32 | if(!queue.length){
33 | clearInterval(timer);
34 | timer = null;
35 | }else{
36 | queue.shift()();
37 | }
38 | }, delay);
39 | }
40 | };
41 | };
42 |
43 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/io/loadScript.js:
--------------------------------------------------------------------------------
1 | /**
2 | 该方法为zepto而存在,使用jquery请用$.getScript替代
3 | @module lib/kit/io/loadScript
4 | **/
5 |
6 | var $ = require('../../../lib');
7 |
8 | /**
9 | 加载script
10 | @param {object} options script选项
11 | @param {string} options.url script地址
12 | @param {string} [options.type='text/javascript'] script类型
13 | @param {string} [options.charset='utf-8'] script编码
14 | @param {function} [options.onLoad] script加载完成的回调函数
15 | **/
16 | module.exports = function(options){
17 | var conf = $.extend({
18 | url : '',
19 | type : 'text/javascript',
20 | charset : 'utf-8',
21 | onLoad : $.noop
22 | }, options);
23 |
24 | var script = $(document.createElement('script'));
25 | script.on('load', function(){
26 | conf.onLoad();
27 | delete script.onload;
28 | $(script).off().remove();
29 | }).attr({
30 | src : conf.url,
31 | charset : conf.charset,
32 | type : conf.type
33 | }).appendTo( $('head') );
34 | };
35 |
36 |
37 |
--------------------------------------------------------------------------------
/generators/app/templates/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.0.0",
3 | "description": "",
4 | "main": "index.js",
5 | "scripts": {
6 | "test": "echo \"Error: no test specified\" && exit 1"
7 | },
8 | "author": "",
9 | "license": "ISC",
10 | "devDependencies": {
11 | "autoprefixer": "^6.0.3",
12 | "browser-sync": "^2.9.11",
13 | "del": "^2.0.2",
14 | "grunt": "^0.4.5",
15 | "grunt-contrib-clean": "^0.7.0",
16 | "grunt-contrib-copy": "^0.8.2",
17 | "grunt-contrib-jshint": "^0.11.3",
18 | "grunt-sprity": "^1.0.0",
19 | "grunt-svn-workflow": "^0.2.9",
20 | "grunt-tcms-upload": "^0.1.0",
21 | "gulp": "^3.9.0",
22 | "gulp-cssmin": "^0.1.7",
23 | "gulp-file-include": "^0.13.7",
24 | "gulp-if": "^2.0.0",
25 | "gulp-postcss": "^6.0.1",
26 | "gulp-rename": "^1.2.2",
27 | "gulp-replace": "^0.5.4",
28 | "gulp-uglify": "^1.5.1",
29 | "gulp-webpack": "^1.5.0",
30 | "html-loader": "^0.3.0",
31 | "webpack": "^1.12.11"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/dom/getHiddenBox.js:
--------------------------------------------------------------------------------
1 | /**
2 | 页面统一隐藏容器工具
3 | @module lib/kit/dom/hiddenContainer
4 | @example
5 | var $hiddenContainer = require('lib/kit/dom/hiddenContainer');
6 | $hiddenContainer.append('');
7 | **/
8 |
9 | var $ = require('../../../lib');
10 |
11 | var hiddenNode;
12 |
13 | var getHiddenNode = function(){
14 | if(!hiddenNode){
15 | hiddenNode = $('').css({
16 | 'display' : 'none',
17 | 'position' : 'absolute',
18 | 'top' : '-9999px',
19 | 'left' : '-9999px'
20 | }).appendTo($('body'));
21 | }
22 | return hiddenNode;
23 | };
24 |
25 | module.exports = {
26 | /**
27 | 插入需要隐藏的 dom 元素
28 | @param {element} node 要存放在隐藏容器中的 dom 元素
29 | **/
30 | append : function(node){
31 | getHiddenNode().append($(node));
32 | },
33 | /**
34 | 清除容器内所有元素
35 | **/
36 | clear : function(){
37 | getHiddenNode().html('');
38 | },
39 | /**
40 | 获取容器本身 dom 元素
41 | @return {element} 容器 dom 元素
42 | **/
43 | get : function(){
44 | return getHiddenNode();
45 | }
46 | };
47 |
48 |
49 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/str/parseURL.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/parseURL
3 | @example
4 | var $parseURL = require('lib/kit/str/parseURL');
5 | console.info( $parseURL('http://t.sina.com.cn/profile?beijing=huanyingni') );
6 | // {
7 | // hash : ''
8 | // host : 't.sina.com.cn'
9 | // path : 'profile'
10 | // port : ''
11 | // query : 'beijing=huanyingni'
12 | // scheme : http
13 | // slash : '//'
14 | // url : 'http://t.sina.com.cn/profile?beijing=huanyingni'
15 | // }
16 | **/
17 |
18 | /**
19 | 解析URL为一个JSON对象
20 | @param {string} str URL字符串
21 | @return {object} JSON对象
22 | **/
23 | module.exports = function(url){
24 | var parse_url = /^(?:([A-Za-z]+):(\/{0,3}))?([0-9.\-A-Za-z]+\.[0-9A-Za-z]+)?(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/;
25 | var names = ['url', 'scheme', 'slash', 'host', 'port', 'path', 'query', 'hash'];
26 | var results = parse_url.exec(url);
27 | var that = {};
28 | for (var i = 0, len = names.length; i < len; i += 1) {
29 | that[names[i]] = results[i] || '';
30 | }
31 | return that;
32 | };
33 |
34 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/str/parseURL.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/str/parseURL
3 | @example
4 | var $parseURL = require('lib/kit/str/parseURL');
5 | console.info( $parseURL('http://t.sina.com.cn/profile?beijing=huanyingni') );
6 | // {
7 | // hash : ''
8 | // host : 't.sina.com.cn'
9 | // path : 'profile'
10 | // port : ''
11 | // query : 'beijing=huanyingni'
12 | // scheme : http
13 | // slash : '//'
14 | // url : 'http://t.sina.com.cn/profile?beijing=huanyingni'
15 | // }
16 | **/
17 |
18 | /**
19 | 解析URL为一个JSON对象
20 | @param {string} str URL字符串
21 | @return {object} JSON对象
22 | **/
23 | module.exports = function(url){
24 | var parse_url = /^(?:([A-Za-z]+):(\/{0,3}))?([0-9.\-A-Za-z]+\.[0-9A-Za-z]+)?(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/;
25 | var names = ['url', 'scheme', 'slash', 'host', 'port', 'path', 'query', 'hash'];
26 | var results = parse_url.exec(url);
27 | var that = {};
28 | for (var i = 0, len = names.length; i < len; i += 1) {
29 | that[names[i]] = results[i] || '';
30 | }
31 | return that;
32 | };
33 |
34 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/dom/getHiddenBox.js:
--------------------------------------------------------------------------------
1 | /**
2 | 页面统一隐藏容器工具
3 | @module lib/kit/dom/hiddenContainer
4 | @example
5 | var $hiddenContainer = require('lib/kit/dom/hiddenContainer');
6 | $hiddenContainer.append('');
7 | **/
8 |
9 | var $ = require('../../../lib');
10 |
11 | var hiddenNode;
12 |
13 | var getHiddenNode = function(){
14 | if(!hiddenNode){
15 | hiddenNode = $('').css({
16 | 'display' : 'none',
17 | 'position' : 'absolute',
18 | 'top' : '-9999px',
19 | 'left' : '-9999px'
20 | }).appendTo($('body'));
21 | }
22 | return hiddenNode;
23 | };
24 |
25 | module.exports = {
26 | /**
27 | 插入需要隐藏的 dom 元素
28 | @param {element} node 要存放在隐藏容器中的 dom 元素
29 | **/
30 | append : function(node){
31 | getHiddenNode().append($(node));
32 | },
33 | /**
34 | 清除容器内所有元素
35 | **/
36 | clear : function(){
37 | getHiddenNode().html('');
38 | },
39 | /**
40 | 获取容器本身 dom 元素
41 | @return {element} 容器 dom 元素
42 | **/
43 | get : function(){
44 | return getHiddenNode();
45 | }
46 | };
47 |
48 |
49 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/ui/reuseDialog.js:
--------------------------------------------------------------------------------
1 | /**
2 | 获取可重用对话框
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $dialog = require('../ui/dialog');
7 |
8 | module.exports = function(spec){
9 |
10 | //可重用的对话框存储在 cache 队列中
11 | var cache = [];
12 |
13 | //队列有最大限制,如果队列已满,对话框隐藏时直接销毁
14 | var maxLength = 5;
15 |
16 | var that = {};
17 |
18 | var defaults = $.extend({}, spec);
19 |
20 | //可以通过 get 方法取得缓存的对话框实例
21 | that.get = function(){
22 | var dialog;
23 | var conf = $.extend({}, defaults);
24 |
25 | //如果队列为空,则创建新的对话框实例
26 | if(cache.length){
27 | dialog = cache.shift();
28 | }else{
29 | dialog = new $dialog(conf);
30 |
31 | //对话框隐藏时,存入队列
32 | dialog.on('hide', function(){
33 | if(cache.length >= maxLength){
34 | dialog.destroy();
35 | }else{
36 | cache.push(dialog);
37 | }
38 | });
39 | }
40 |
41 | dialog.off('ok');
42 | dialog.off('close');
43 | dialog.off('cancel');
44 | dialog.role('title').html('');
45 | dialog.role('content').html('');
46 |
47 | return dialog;
48 | };
49 |
50 | return that;
51 | };
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/evt/tapStop.js:
--------------------------------------------------------------------------------
1 | /**
2 | 用遮罩的方式阻止tap事件穿透引发表单元素获取焦点
3 | **/
4 |
5 | var $ = require('../../../lib');
6 |
7 | var miniMask = $('');
8 | miniMask.css({
9 | 'display' : 'none',
10 | 'position' : 'absolute',
11 | 'left' : 0,
12 | 'top' : 0,
13 | 'margin-left' : '-20px',
14 | 'margin-top' : '-20px',
15 | 'z-index' : 10000,
16 | 'background-color' : 'rgba(0,0,0,0)',
17 | 'width' : '40px',
18 | 'height' : '40px'
19 | }).appendTo(document.body);
20 |
21 | var pos = {};
22 | var timer = null;
23 | $(document).on('touchstart', function(evt){
24 | if(!(evt && evt.touches && evt.touches.length)){
25 | return;
26 | }
27 |
28 | var touch = evt.touches[0];
29 | pos.pageX = touch.pageX;
30 | pos.pageY = touch.pageY;
31 | });
32 |
33 | var tapStop = function(delay){
34 | delay = parseInt(delay, 10) || 0;
35 | miniMask.show().css({
36 | 'left' : pos.pageX + 'px',
37 | 'top' : pos.pageY + 'px'
38 | });
39 | clearTimeout(timer);
40 | timer = setTimeout(function(){
41 | miniMask.hide();
42 | }, delay || 500);
43 | };
44 |
45 | module.exports = tapStop;
46 |
47 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/ui/reuseDialog.js:
--------------------------------------------------------------------------------
1 | /**
2 | 获取可重用对话框
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $dialog = require('../ui/dialog');
7 |
8 | module.exports = function(spec){
9 |
10 | //可重用的对话框存储在 cache 队列中
11 | var cache = [];
12 |
13 | //队列有最大限制,如果队列已满,对话框隐藏时直接销毁
14 | var maxLength = 5;
15 |
16 | var that = {};
17 |
18 | var defaults = $.extend({}, spec);
19 |
20 | //可以通过 get 方法取得缓存的对话框实例
21 | that.get = function(){
22 | var dialog;
23 | var conf = $.extend({}, defaults);
24 |
25 | //如果队列为空,则创建新的对话框实例
26 | if(cache.length){
27 | dialog = cache.shift();
28 | }else{
29 | dialog = new $dialog(conf);
30 |
31 | //对话框隐藏时,存入队列
32 | dialog.on('hide', function(){
33 | if(cache.length >= maxLength){
34 | dialog.destroy();
35 | }else{
36 | cache.push(dialog);
37 | }
38 | });
39 | }
40 |
41 | dialog.off('ok');
42 | dialog.off('close');
43 | dialog.off('cancel');
44 | dialog.role('title').html('');
45 | dialog.role('content').html('');
46 |
47 | return dialog;
48 | };
49 |
50 | return that;
51 | };
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/evt/tapStop.js:
--------------------------------------------------------------------------------
1 | /**
2 | 用遮罩的方式阻止tap事件穿透引发表单元素获取焦点
3 | **/
4 |
5 | var $ = require('../../../lib');
6 |
7 | var miniMask = $('');
8 | miniMask.css({
9 | 'display' : 'none',
10 | 'position' : 'absolute',
11 | 'left' : 0,
12 | 'top' : 0,
13 | 'margin-left' : '-20px',
14 | 'margin-top' : '-20px',
15 | 'z-index' : 10000,
16 | 'background-color' : 'rgba(0,0,0,0)',
17 | 'width' : '40px',
18 | 'height' : '40px'
19 | }).appendTo(document.body);
20 |
21 | var pos = {};
22 | var timer = null;
23 | $(document).on('touchstart', function(evt){
24 | if(!(evt && evt.touches && evt.touches.length)){
25 | return;
26 | }
27 |
28 | var touch = evt.touches[0];
29 | pos.pageX = touch.pageX;
30 | pos.pageY = touch.pageY;
31 | });
32 |
33 | var tapStop = function(delay){
34 | delay = parseInt(delay, 10) || 0;
35 | miniMask.show().css({
36 | 'left' : pos.pageX + 'px',
37 | 'top' : pos.pageY + 'px'
38 | });
39 | clearTimeout(timer);
40 | timer = setTimeout(function(){
41 | miniMask.hide();
42 | }, delay || 500);
43 | };
44 |
45 | module.exports = tapStop;
46 |
47 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/core/transmission.js:
--------------------------------------------------------------------------------
1 | /**
2 | 接口管理器
3 | @module lib/common/transmission
4 | **/
5 |
6 | var $ = require('../../lib');
7 | var $transport = require('./transport');
8 |
9 | // Transmission
10 | // -----------------
11 | // 封装与后台的HTTP交互,提供一个统一的接口列表
12 | // 包含ajax,jsonp方式
13 |
14 | var Transmission = function(options){
15 | this._transports = {};
16 | this.conf = $.extend({}, options);
17 | };
18 |
19 | Transmission.prototype = {
20 | register : function(name, options){
21 | if(!this._transports[name]){
22 | options = $.extend({
23 | name : name
24 | }, this.conf, options);
25 | this._transports[name] = new $transport(options);
26 | }
27 | },
28 | remove : function(name){
29 | if(this._transports[name]){
30 | this._transports[name].destroy();
31 | delete this._transports[name];
32 | }
33 | },
34 | request : function(name, options){
35 | var trans = this._transports[name];
36 | if(trans){
37 | return trans.request(options);
38 | }
39 | },
40 | destroy : function(){
41 | $.each(this._transports, function(name, transport){
42 | transport.destroy();
43 | });
44 | }
45 | };
46 |
47 | module.exports = Transmission;
48 |
49 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/ui/loginLayer.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by echochi on 15/12/1.
3 | */
4 |
5 | var $ = require('../../lib');
6 | var $reuse = require('../ui/reuseDialog');
7 |
8 | var cache = $reuse({
9 | template : '',
10 | target : 'screen',
11 | parent : null,
12 | mask : true,
13 | styles: {
14 | 'z-index': 10000,
15 | 'width': '622px',
16 | 'height': '368px'
17 | }
18 | });
19 |
20 | var loginDialog = {};
21 |
22 | var loginLayer = {
23 |
24 | initLayer: function(opt) {
25 |
26 | loginDialog = cache.get();
27 |
28 | loginDialog.role('loginFrame');
29 | loginDialog.role('loginFrame').attr({'src': opt.url, 'style': 'width: 622px, height: 368px;'});
30 |
31 | loginDialog.show();
32 | },
33 |
34 |
35 | resizeLayer: function(width, height) {
36 | loginDialog.role('loginFrame').css({width: width + 'px', height: height + 'px'});
37 | loginDialog.role('root').css({width: width + 'px', height: height + 'px'});
38 | },
39 |
40 | closeLayer: function() {
41 | loginDialog.hide();
42 | }
43 | };
44 |
45 | module.exports = loginLayer;
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/ui/loginLayer.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by echochi on 15/12/1.
3 | */
4 |
5 | var $ = require('../../lib');
6 | var $reuse = require('../ui/reuseDialog');
7 |
8 | var cache = $reuse({
9 | template : '',
10 | target : 'screen',
11 | parent : null,
12 | mask : true,
13 | styles: {
14 | 'z-index': 10000,
15 | 'width': '622px',
16 | 'height': '368px'
17 | }
18 | });
19 |
20 | var loginDialog = {};
21 |
22 | var loginLayer = {
23 |
24 | initLayer: function(opt) {
25 |
26 | loginDialog = cache.get();
27 |
28 | loginDialog.role('loginFrame');
29 | loginDialog.role('loginFrame').attr({'src': opt.url, 'style': 'width: 622px, height: 368px;'});
30 |
31 | loginDialog.show();
32 | },
33 |
34 |
35 | resizeLayer: function(width, height) {
36 | loginDialog.role('loginFrame').css({width: width + 'px', height: height + 'px'});
37 | loginDialog.role('root').css({width: width + 'px', height: height + 'px'});
38 | },
39 |
40 | closeLayer: function() {
41 | loginDialog.hide();
42 | }
43 | };
44 |
45 | module.exports = loginLayer;
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/core/transmission.js:
--------------------------------------------------------------------------------
1 | /**
2 | 接口管理器
3 | @module lib/common/transmission
4 | **/
5 |
6 | var $ = require('../../lib');
7 | var $transport = require('./transport');
8 |
9 | // Transmission
10 | // -----------------
11 | // 封装与后台的HTTP交互,提供一个统一的接口列表
12 | // 包含ajax,jsonp方式
13 |
14 | var Transmission = function(options){
15 | this._transports = {};
16 | this.conf = $.extend({}, options);
17 | };
18 |
19 | Transmission.prototype = {
20 | register : function(name, options){
21 | if(!this._transports[name]){
22 | options = $.extend({
23 | name : name
24 | }, this.conf, options);
25 | this._transports[name] = new $transport(options);
26 | }
27 | },
28 | remove : function(name){
29 | if(this._transports[name]){
30 | this._transports[name].destroy();
31 | delete this._transports[name];
32 | }
33 | },
34 | request : function(name, options){
35 | var trans = this._transports[name];
36 | if(trans){
37 | return trans.request(options);
38 | }
39 | },
40 | destroy : function(){
41 | $.each(this._transports, function(name, transport){
42 | transport.destroy();
43 | });
44 | }
45 | };
46 |
47 | module.exports = Transmission;
48 |
49 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/common/confirm.js:
--------------------------------------------------------------------------------
1 | /**
2 | confirm对话框
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $reuse = require('../ui/reuseDialog');
7 | var $tplConfirm = require('../tpl/confirm.tpl');
8 |
9 | var cache = $reuse({
10 | template : $tplConfirm,
11 | target : 'screen',
12 | parent : null,
13 | mask : true,
14 | styles : {
15 | 'z-index' : 10000,
16 | 'position' : 'absolute',
17 | 'display' : 'none'
18 | }
19 | });
20 |
21 | module.exports = function(content, options){
22 | if(!options && $.isPlainObject(content)){
23 | options = content;
24 | }else{
25 | options = options || {};
26 | options.content = content;
27 | }
28 |
29 | var conf = $.extend({
30 | title : '',
31 | styleOk : '确定',
32 | styleCancel : '取消',
33 | ok : $.noop,
34 | cancel : $.noop
35 | }, options);
36 |
37 | var dialog = cache.get();
38 | dialog.role('title').html(conf.title);
39 | dialog.role('content').html(conf.content);
40 | dialog.role('ok').html(conf.styleOk);
41 | dialog.role('cancel').html(conf.styleCancel);
42 |
43 | dialog.on('ok', conf.ok);
44 | dialog.on('cancel', conf.cancel);
45 |
46 | //重用对话框时,清除了对话框自动绑定的 ok, cancel 事件
47 | //所以这里需要重新绑定一次
48 | dialog.on('ok', function(){
49 | dialog.hide();
50 | });
51 |
52 | dialog.on('cancel', function(){
53 | dialog.hide();
54 | });
55 |
56 | dialog.show();
57 | };
58 |
59 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/common/confirm.js:
--------------------------------------------------------------------------------
1 | /**
2 | confirm对话框
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $reuse = require('../ui/reuseDialog');
7 | var $tplConfirm = require('../tpl/confirm.tpl');
8 |
9 | var cache = $reuse({
10 | template : $tplConfirm,
11 | target : 'screen',
12 | parent : null,
13 | mask : true,
14 | styles : {
15 | 'z-index' : 10000,
16 | 'position' : 'absolute',
17 | 'display' : 'none'
18 | }
19 | });
20 |
21 | module.exports = function(content, options){
22 | if(!options && $.isPlainObject(content)){
23 | options = content;
24 | }else{
25 | options = options || {};
26 | options.content = content;
27 | }
28 |
29 | var conf = $.extend({
30 | title : '',
31 | styleOk : '确定',
32 | styleCancel : '取消',
33 | ok : $.noop,
34 | cancel : $.noop
35 | }, options);
36 |
37 | var dialog = cache.get();
38 | dialog.role('title').html(conf.title);
39 | dialog.role('content').html(conf.content);
40 | dialog.role('ok').html(conf.styleOk);
41 | dialog.role('cancel').html(conf.styleCancel);
42 |
43 | dialog.on('ok', conf.ok);
44 | dialog.on('cancel', conf.cancel);
45 |
46 | //重用对话框时,清除了对话框自动绑定的 ok, cancel 事件
47 | //所以这里需要重新绑定一次
48 | dialog.on('ok', function(){
49 | dialog.hide();
50 | });
51 |
52 | dialog.on('cancel', function(){
53 | dialog.hide();
54 | });
55 |
56 | dialog.show();
57 | };
58 |
59 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/core/listener.js:
--------------------------------------------------------------------------------
1 | /**
2 | 广播组件
3 | @module lib/common/listener
4 | **/
5 |
6 | var $ = require('../../lib');
7 | var $events = require('./events');
8 | // Listener
9 | // -----------------
10 | // 用于全局广播的白名单控制机制
11 |
12 | var Listener = function(events){
13 | this._whiteList = {};
14 | this._receiver = new $events();
15 | if(Array.isArray(events)){
16 | events.forEach(this.define.bind(this));
17 | }
18 | };
19 |
20 | //事件添加,移除,激发的调用方法参考Events
21 | Listener.prototype = {
22 | constructor : Listener,
23 | //在白名单上定义一个事件名称
24 | define : function(eventName){
25 | this._whiteList[eventName] = true;
26 | },
27 | //取消白名单上的事件名称
28 | undefine : function(eventName){
29 | delete this._whiteList[eventName];
30 | },
31 | on : function(){
32 | this._receiver.on.apply(this._receiver, arguments);
33 | },
34 | off : function(){
35 | this._receiver.off.apply(this._receiver, arguments);
36 | },
37 | trigger : function(events){
38 | var rest = [].slice.call(arguments, 1);
39 |
40 | //按照Events.trigger的调用方式,第一个参数是用空格分隔的事件名称列表
41 | events = events.split(/\s+/);
42 |
43 | //遍历事件列表,依据白名单决定事件是否激发
44 | events.forEach(function(evtName){
45 | if(this._whiteList[evtName]){
46 | this._receiver.trigger.apply(this._receiver, [evtName].concat(rest));
47 | }
48 | }.bind(this));
49 | }
50 | };
51 |
52 | module.exports = Listener;
53 |
54 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/common/alert.js:
--------------------------------------------------------------------------------
1 | /**
2 | alert对话框
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $reuse = require('../ui/reuseDialog');
7 | var $tplAlert = require('../tpl/alert.tpl');
8 |
9 | var cache = $reuse({
10 | template : $tplAlert,
11 | target : 'screen',
12 | parent : null,
13 | mask : true,
14 | styles : {
15 | 'z-index' : 10000,
16 | 'position' : 'absolute',
17 | 'display' : 'none'
18 | }
19 | });
20 |
21 | module.exports = function(content, options){
22 | if(!options && $.isPlainObject(content)){
23 | options = content;
24 | }else{
25 | options = options || {};
26 | options.content = content;
27 | }
28 |
29 | var conf = $.extend({
30 | title : '提 示',
31 | styleOk : '确 定',
32 | ok : $.noop,
33 | cancel : null
34 | }, options);
35 |
36 | var dialog = cache.get();
37 | dialog.role('title').html(conf.title);
38 | dialog.role('content').html(conf.content);
39 | dialog.role('ok').html(conf.styleOk);
40 |
41 | dialog.on('ok', conf.ok);
42 | if($.type(conf.cancel) === 'function'){
43 | dialog.on('cancel', conf.cancel);
44 | }else{
45 | dialog.on('cancel', conf.ok);
46 | }
47 |
48 | //重用对话框时,清除了对话框自动绑定的 ok, cancel 事件
49 | //所以这里需要重新绑定一次
50 | dialog.on('ok', function(){
51 | dialog.hide();
52 | });
53 |
54 | dialog.on('cancel', function(){
55 | dialog.hide();
56 | });
57 |
58 | dialog.show();
59 | };
60 |
61 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/common/alert.js:
--------------------------------------------------------------------------------
1 | /**
2 | alert对话框
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $reuse = require('../ui/reuseDialog');
7 | var $tplAlert = require('../tpl/alert.tpl');
8 |
9 | var cache = $reuse({
10 | template : $tplAlert,
11 | target : 'screen',
12 | parent : null,
13 | mask : true,
14 | styles : {
15 | 'z-index' : 10000,
16 | 'position' : 'absolute',
17 | 'display' : 'none'
18 | }
19 | });
20 |
21 | module.exports = function(content, options){
22 | if(!options && $.isPlainObject(content)){
23 | options = content;
24 | }else{
25 | options = options || {};
26 | options.content = content;
27 | }
28 |
29 | var conf = $.extend({
30 | title : '提 示',
31 | styleOk : '确 定',
32 | ok : $.noop,
33 | cancel : null
34 | }, options);
35 |
36 | var dialog = cache.get();
37 | dialog.role('title').html(conf.title);
38 | dialog.role('content').html(conf.content);
39 | dialog.role('ok').html(conf.styleOk);
40 |
41 | dialog.on('ok', conf.ok);
42 | if($.type(conf.cancel) === 'function'){
43 | dialog.on('cancel', conf.cancel);
44 | }else{
45 | dialog.on('cancel', conf.ok);
46 | }
47 |
48 | //重用对话框时,清除了对话框自动绑定的 ok, cancel 事件
49 | //所以这里需要重新绑定一次
50 | dialog.on('ok', function(){
51 | dialog.hide();
52 | });
53 |
54 | dialog.on('cancel', function(){
55 | dialog.hide();
56 | });
57 |
58 | dialog.show();
59 | };
60 |
61 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/core/listener.js:
--------------------------------------------------------------------------------
1 | /**
2 | 广播组件
3 | @module lib/common/listener
4 | **/
5 |
6 | var $ = require('../../lib');
7 | var $events = require('./events');
8 | // Listener
9 | // -----------------
10 | // 用于全局广播的白名单控制机制
11 |
12 | var Listener = function(events){
13 | this._whiteList = {};
14 | this._receiver = new $events();
15 | if(Array.isArray(events)){
16 | events.forEach(this.define.bind(this));
17 | }
18 | };
19 |
20 | //事件添加,移除,激发的调用方法参考Events
21 | Listener.prototype = {
22 | constructor : Listener,
23 | //在白名单上定义一个事件名称
24 | define : function(eventName){
25 | this._whiteList[eventName] = true;
26 | },
27 | //取消白名单上的事件名称
28 | undefine : function(eventName){
29 | delete this._whiteList[eventName];
30 | },
31 | on : function(){
32 | this._receiver.on.apply(this._receiver, arguments);
33 | },
34 | off : function(){
35 | this._receiver.off.apply(this._receiver, arguments);
36 | },
37 | trigger : function(events){
38 | var rest = [].slice.call(arguments, 1);
39 |
40 | //按照Events.trigger的调用方式,第一个参数是用空格分隔的事件名称列表
41 | events = events.split(/\s+/);
42 |
43 | //遍历事件列表,依据白名单决定事件是否激发
44 | events.forEach(function(evtName){
45 | if(this._whiteList[evtName]){
46 | this._receiver.trigger.apply(this._receiver, [evtName].concat(rest));
47 | }
48 | }.bind(this));
49 | }
50 | };
51 |
52 | module.exports = Listener;
53 |
54 |
--------------------------------------------------------------------------------
/generators/app/templates/js/vendor/zepto/form.js:
--------------------------------------------------------------------------------
1 | // Zepto.js
2 | // (c) 2010-2015 Thomas Fuchs
3 | // Zepto.js may be freely distributed under the MIT license.
4 |
5 | ;(function($){
6 | $.fn.serializeArray = function() {
7 | var name, type, result = [],
8 | add = function(value) {
9 | if (value.forEach) return value.forEach(add)
10 | result.push({ name: name, value: value })
11 | }
12 | if (this[0]) $.each(this[0].elements, function(_, field){
13 | type = field.type, name = field.name
14 | if (name && field.nodeName.toLowerCase() != 'fieldset' &&
15 | !field.disabled && type != 'submit' && type != 'reset' && type != 'button' && type != 'file' &&
16 | ((type != 'radio' && type != 'checkbox') || field.checked))
17 | add($(field).val())
18 | })
19 | return result
20 | }
21 |
22 | $.fn.serialize = function(){
23 | var result = []
24 | this.serializeArray().forEach(function(elm){
25 | result.push(encodeURIComponent(elm.name) + '=' + encodeURIComponent(elm.value))
26 | })
27 | return result.join('&')
28 | }
29 |
30 | $.fn.submit = function(callback) {
31 | if (0 in arguments) this.bind('submit', callback)
32 | else if (this.length) {
33 | var event = $.Event('submit')
34 | this.eq(0).trigger(event)
35 | if (!event.isDefaultPrevented()) this.get(0).submit()
36 | }
37 | return this
38 | }
39 |
40 | })(Zepto)
41 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/fx/flashAction.js:
--------------------------------------------------------------------------------
1 | /**
2 | 封装闪烁动作
3 |
4 | @param {object} options 选项
5 | @param {number} [options.times=3] 闪烁次数
6 | @param {number} [options.delay=100] 闪烁间隔时间,单位为毫秒
7 | @param {function} [options.actionOdd=$.noop] 奇数回调
8 | @param {function} [options.actionEven=$.noop] 偶数回调
9 | @param {function} [options.recover] 状态恢复回调
10 |
11 | @example
12 |
13 | var $flashAction = require('lib/kit/fx/flashAction');
14 | var text = $('#target span.txt');
15 | $flashAction({
16 | actionOdd : function(){
17 | text.css('color', '#f00');
18 | },
19 | actionEven : function(){
20 | text.css('color', '#00f');
21 | },
22 | recover : function(){
23 | text.css('color', '#000');
24 | }
25 | });
26 |
27 | **/
28 |
29 | var $ = require('../../../lib');
30 |
31 | var flashAction = function(options){
32 | var conf = $.extend({
33 | times : 3,
34 | delay : 100,
35 | actionOdd : $.noop,
36 | actionEven : $.noop,
37 | recover : $.noop
38 | }, options);
39 |
40 | var queue = [];
41 | for(var i = 0; i < (conf.times * 2 + 1); i++){
42 | queue.push( (i + 1) * conf.delay );
43 | }
44 |
45 | $.each(queue, function(index, time){
46 | setTimeout(function(){
47 | if(index >= queue.length - 1){
48 | conf.recover();
49 | }else{
50 | if(index % 2 === 0){
51 | conf.actionEven();
52 | }else{
53 | conf.actionOdd();
54 | }
55 | }
56 | }, time);
57 | });
58 | };
59 |
60 | module.exports = flashAction;
61 |
62 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/vendor/zepto/form.js:
--------------------------------------------------------------------------------
1 | // Zepto.js
2 | // (c) 2010-2015 Thomas Fuchs
3 | // Zepto.js may be freely distributed under the MIT license.
4 |
5 | ;(function($){
6 | $.fn.serializeArray = function() {
7 | var name, type, result = [],
8 | add = function(value) {
9 | if (value.forEach) return value.forEach(add)
10 | result.push({ name: name, value: value })
11 | }
12 | if (this[0]) $.each(this[0].elements, function(_, field){
13 | type = field.type, name = field.name
14 | if (name && field.nodeName.toLowerCase() != 'fieldset' &&
15 | !field.disabled && type != 'submit' && type != 'reset' && type != 'button' && type != 'file' &&
16 | ((type != 'radio' && type != 'checkbox') || field.checked))
17 | add($(field).val())
18 | })
19 | return result
20 | }
21 |
22 | $.fn.serialize = function(){
23 | var result = []
24 | this.serializeArray().forEach(function(elm){
25 | result.push(encodeURIComponent(elm.name) + '=' + encodeURIComponent(elm.value))
26 | })
27 | return result.join('&')
28 | }
29 |
30 | $.fn.submit = function(callback) {
31 | if (0 in arguments) this.bind('submit', callback)
32 | else if (this.length) {
33 | var event = $.Event('submit')
34 | this.eq(0).trigger(event)
35 | if (!event.isDefaultPrevented()) this.get(0).submit()
36 | }
37 | return this
38 | }
39 |
40 | })(Zepto)
41 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/fx/flashAction.js:
--------------------------------------------------------------------------------
1 | /**
2 | 封装闪烁动作
3 |
4 | @param {object} options 选项
5 | @param {number} [options.times=3] 闪烁次数
6 | @param {number} [options.delay=100] 闪烁间隔时间,单位为毫秒
7 | @param {function} [options.actionOdd=$.noop] 奇数回调
8 | @param {function} [options.actionEven=$.noop] 偶数回调
9 | @param {function} [options.recover] 状态恢复回调
10 |
11 | @example
12 |
13 | var $flashAction = require('lib/kit/fx/flashAction');
14 | var text = $('#target span.txt');
15 | $flashAction({
16 | actionOdd : function(){
17 | text.css('color', '#f00');
18 | },
19 | actionEven : function(){
20 | text.css('color', '#00f');
21 | },
22 | recover : function(){
23 | text.css('color', '#000');
24 | }
25 | });
26 |
27 | **/
28 |
29 | var $ = require('../../../lib');
30 |
31 | var flashAction = function(options){
32 | var conf = $.extend({
33 | times : 3,
34 | delay : 100,
35 | actionOdd : $.noop,
36 | actionEven : $.noop,
37 | recover : $.noop
38 | }, options);
39 |
40 | var queue = [];
41 | for(var i = 0; i < (conf.times * 2 + 1); i++){
42 | queue.push( (i + 1) * conf.delay );
43 | }
44 |
45 | $.each(queue, function(index, time){
46 | setTimeout(function(){
47 | if(index >= queue.length - 1){
48 | conf.recover();
49 | }else{
50 | if(index % 2 === 0){
51 | conf.actionEven();
52 | }else{
53 | conf.actionOdd();
54 | }
55 | }
56 | }, time);
57 | });
58 | };
59 |
60 | module.exports = flashAction;
61 |
62 |
--------------------------------------------------------------------------------
/generators/app/templates/src/css/common/common.css:
--------------------------------------------------------------------------------
1 | /* common -- for all projects */
2 | html{
3 | font-size: 100px;
4 | }
5 |
6 | body{
7 | text-size-adjust:100%;
8 | -webkit-font-smoothing: antialiased;
9 | -moz-font-smoothing: antialiased;
10 | font-smoothing: antialiased;
11 | font-family:SimHei, Helvetica,Droid Sans Fallback;
12 | font-size: 0.14rem;
13 | }
14 |
15 | *{
16 | -webkit-tap-highlight-color:rgba(255,255,255,0);
17 | tap-highlight-color:rgba(255,255,255,0);
18 | outline:none;
19 | }
20 |
21 | .fl{float: left;}
22 | .fr{float: right;}
23 | .bold{font-weight:bold}
24 | .bold{font-weight:bold}
25 | .hidden{overflow:hidden;height:0;}
26 | .dib{display: inline-block;}
27 | .txt_r{text-align:right;}
28 | .txt_l{text-align:left ;}
29 | .txt_c{text-align:center;}
30 | .hidden{overflow:hidden;height:0;}
31 | .clear{clear:both;}
32 |
33 | .clearfix{
34 | zoom:1;
35 | }
36 | .clearfix:after{
37 | content:'';
38 | display:block;
39 | visibility:hidden;
40 | clear:both;
41 | height:0;
42 | }
43 |
44 | .elps{
45 | overflow: hidden;
46 | text-overflow:ellipsis;
47 | white-space: nowrap;
48 | }
49 | .clipline{
50 | overflow: hidden;
51 | word-break: normal;
52 | white-space: nowrap;
53 | text-overflow: ellipsis;
54 | }
55 | .cliplines{
56 | display: -webkit-box!important;
57 | overflow: hidden;
58 | text-overflow: ellipsis;
59 | -webkit-box-orient: vertical;
60 | }
61 | .line2{
62 | -webkit-line-clamp: 2;
63 | }
64 | .line3{
65 | -webkit-line-clamp: 3;
66 | }
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/ui/screenMask.js:
--------------------------------------------------------------------------------
1 | /**
2 | 屏幕遮罩
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $mask = require('./mask');
7 | var $stockMonitor = require('../../lib/kit/util/stockMonitor');
8 |
9 | var ScreenMask = $mask.extend({
10 | defaults : {
11 | template : '',
12 | target : 'screen',
13 | bgColor : 'rgba(0,0,0,0.3)',
14 | styles : {
15 | 'z-index' : 9999,
16 | 'position' : 'fixed',
17 | 'width' : '100%',
18 | 'height' : '100%',
19 | 'background-color' : 'rgba(0,0,0,0)',
20 | 'display' : 'none'
21 | }
22 | },
23 | build : function(){
24 | this.supr();
25 | this.buildMonitor();
26 | },
27 | buildMonitor : function(){
28 | var self = this;
29 | var monitor = new $stockMonitor();
30 | monitor.on = function(){
31 | self.show();
32 | };
33 | monitor.off = function(){
34 | self.hide();
35 | };
36 | this.monitor = monitor;
37 | },
38 | watch : function(obj){
39 | this.monitor.watch(obj);
40 | },
41 | ignore : function(obj){
42 | this.monitor.ignore(obj);
43 | }
44 | });
45 |
46 | var masks = {};
47 | module.exports = function(spec){
48 | var conf = $.extend({
49 | zIndex : 9999
50 | }, spec);
51 |
52 | var zIndex = conf.zIndex;
53 | delete conf.zIndex;
54 | conf.styles = conf.styles || {};
55 | conf.styles['z-index'] = zIndex;
56 |
57 | var mask = masks[zIndex];
58 | if(!mask){
59 | mask = new ScreenMask(conf);
60 | masks[zIndex] = mask;
61 | }else{
62 | mask.setOptions(conf);
63 | }
64 |
65 | return mask;
66 | };
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/ui/screenMask.js:
--------------------------------------------------------------------------------
1 | /**
2 | 屏幕遮罩
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $mask = require('./mask');
7 | var $stockMonitor = require('../../lib/kit/util/stockMonitor');
8 |
9 | var ScreenMask = $mask.extend({
10 | defaults : {
11 | template : '',
12 | target : 'screen',
13 | bgColor : 'rgba(0,0,0,0.3)',
14 | styles : {
15 | 'z-index' : 9999,
16 | 'position' : 'fixed',
17 | 'width' : '100%',
18 | 'height' : '100%',
19 | 'background-color' : 'rgba(0,0,0,0)',
20 | 'display' : 'none'
21 | }
22 | },
23 | build : function(){
24 | this.supr();
25 | this.buildMonitor();
26 | },
27 | buildMonitor : function(){
28 | var self = this;
29 | var monitor = new $stockMonitor();
30 | monitor.on = function(){
31 | self.show();
32 | };
33 | monitor.off = function(){
34 | self.hide();
35 | };
36 | this.monitor = monitor;
37 | },
38 | watch : function(obj){
39 | this.monitor.watch(obj);
40 | },
41 | ignore : function(obj){
42 | this.monitor.ignore(obj);
43 | }
44 | });
45 |
46 | var masks = {};
47 | module.exports = function(spec){
48 | var conf = $.extend({
49 | zIndex : 9999
50 | }, spec);
51 |
52 | var zIndex = conf.zIndex;
53 | delete conf.zIndex;
54 | conf.styles = conf.styles || {};
55 | conf.styles['z-index'] = zIndex;
56 |
57 | var mask = masks[zIndex];
58 | if(!mask){
59 | mask = new ScreenMask(conf);
60 | masks[zIndex] = mask;
61 | }else{
62 | mask.setOptions(conf);
63 | }
64 |
65 | return mask;
66 | };
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/generators/app/templates/docs/debug.md:
--------------------------------------------------------------------------------
1 | # 调试环境启动说明
2 |
3 | - 安装 node, npm
4 | - 安装 svn命令行
5 | - 安装 grunt-cli
6 | - 运行 `grunt --version` 检查 grunt-cli 是否已安装。
7 | - 运行 `npm install grunt-cli -g` 安装,unix环境可能需要 sudo 权限。
8 | - 安装 gulp-cli
9 | - 运行 `gulp --version` 检查 gulp-cli 是否已安装。
10 | - 运行 `npm install gulp-cli -g` 安装,unix环境可能需要 sudo 权限。
11 | - 安装项目依赖文件
12 | - 运行 `npm install`
13 | - 运行 `gulp` 启动开发环境
14 |
15 | ## 持续构建说明
16 |
17 | - src 目录下的文件会被持续构建到 dist 目录和 online 目录
18 | - JS打包使用的是 webpack
19 | - 如果发现有些文件未及时同步到 dist 或者 online 目录,尝试停止持续构建任务,然后重新执行 `gulp` 。
20 | - js 入口文件都要放在 src/js/entry/ 目录下,如果要添加新的打包输出JS文件,需要配置webpack.config.js 。
21 |
22 | ## gulp 任务说明
23 |
24 | - 项目使用 gulp 执行持续构建任务
25 | - 如果还未使用过 gulp,请参考下列资料:
26 | - [gulp](http://gulpjs.com/)
27 | - [gulp简体中文文档](https://github.com/lisposter/gulp-docs-zh-cn)
28 |
29 | ### 本项目使用的 gulp 命令列表:
30 |
31 | #### gulp serve
32 | - 这是默认任务,直接执行 `gulp` 即可执行。
33 | - 该任务启动一个服务器,访问其首页,静态文件更新时会自动刷新页面
34 |
35 | #### gulp clean
36 | - 删除持续构建任务生成的文件,online 目录和 dist 目录都会被完全移除。
37 |
38 | ## grunt 任务说明
39 |
40 | - 项目使用 grunt 执行分步骤构建任务
41 | - 如果还未使用过 grunt,请参考下列资料:
42 | - [gruntjs](http://www.gruntjs.net/)
43 |
44 | ### 本项目使用的 grunt 命令列表:
45 |
46 | #### grunt test
47 | - 这是默认任务,直接执行 `grunt` 即可执行。
48 | - 依据 .jshintrc 检查代码规范。
49 |
50 | #### grunt sprity
51 | - 生成 sprite 图片和对应 css
52 | - 如果调试环境已启动, sprity 样式会自动 copy 到 dist 和 online 目录。
53 | - sprity 插件在 windows 环境安装会出现报错,解决方案参考: [node-gyp](https://github.com/nodejs/node-gyp#installation)
54 |
55 | #### grunt publish
56 | - 如果项目文件需要发布到CDN服务器,执行 grunt publish 发布 online 目录下的文件到线上。
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/generators/app/templates/css/common/common.css:
--------------------------------------------------------------------------------
1 | /* common -- for all projects */
2 | html{
3 | font-size: 100px;
4 | }
5 |
6 | body{
7 | text-size-adjust:100%;
8 | -webkit-font-smoothing: antialiased;
9 | -moz-font-smoothing: antialiased;
10 | font-smoothing: antialiased;
11 | font-family:SimHei, Helvetica,Droid Sans Fallback;
12 | font-size: 0.14rem;
13 | color: #444;
14 | }
15 |
16 | *{
17 | -webkit-tap-highlight-color:rgba(255,255,255,0);
18 | tap-highlight-color:rgba(255,255,255,0);
19 | -webkit-appearance: none;
20 | outline:none;
21 | }
22 | ol, ul {
23 | list-style: none;
24 | }
25 | a{
26 | color: #444;
27 | }
28 | .fl{float: left;}
29 | .fr{float: right;}
30 | .bold{font-weight:bold}
31 | .bold{font-weight:bold}
32 | .hidden{overflow:hidden;height:0;}
33 | .dib{display: inline-block;}
34 | .txt_r{text-align:right;}
35 | .txt_l{text-align:left ;}
36 | .txt_c{text-align:center;}
37 | .hidden{overflow:hidden;height:0;}
38 | .clear{clear:both;}
39 |
40 | .clearfix{
41 | zoom:1;
42 | }
43 | .clearfix:after{
44 | content:'';
45 | display:block;
46 | visibility:hidden;
47 | clear:both;
48 | height:0;
49 | }
50 |
51 | .elps{
52 | overflow: hidden;
53 | text-overflow:ellipsis;
54 | white-space: nowrap;
55 | }
56 | .clipline{
57 | overflow: hidden;
58 | word-break: normal;
59 | white-space: nowrap;
60 | text-overflow: ellipsis;
61 | }
62 | .cliplines{
63 | display: -webkit-box!important;
64 | overflow: hidden;
65 | text-overflow: ellipsis;
66 | -webkit-box-orient: vertical;
67 | }
68 | .line2{
69 | -webkit-line-clamp: 2;
70 | }
71 | .line3{
72 | -webkit-line-clamp: 3;
73 | }
74 |
--------------------------------------------------------------------------------
/generators/app/templates/docs/dir.md:
--------------------------------------------------------------------------------
1 | # 目录文件说明
2 |
3 | ## 项目基本目录文件
4 |
5 | - online 最终上线文件目录
6 | - dist 本地调试部署目录
7 | - src 源文件目录
8 | - docs 项目文档目录
9 | - .jshintrc 代码质量控制工具 jshint 的配置文件
10 | - gruntfile.js grunt 构建工具配置脚本,用于配置串行任务
11 | - gulpfile.js gulp 构建工具配置脚本,用于配置开发环境实时构建并行任务
12 | - index.html 项目页面列表,需要手工维护
13 | - package.json npm 环境配置文件
14 | - webpack.config.js JS 打包工具 webpack 配置文件
15 |
16 | ## html 目录说明
17 |
18 | src/html 目录为前端html源文件存放位置
19 |
20 | - common 公共html模块
21 | - mods 业务模块
22 | - pages 页面文件
23 |
24 | ## images 目录说明
25 |
26 | src/images 目录为前端images源文件存放位置
27 |
28 | - sprite 用于 grunt sprity 脚本合成 sprite 图片的小图片资源目录
29 | - temp 存放项目中使用的临时图片
30 |
31 | ## css 目录说明
32 |
33 | src/css 目录为前端css源文件存放位置
34 |
35 | - common 公共css,一般用于存放 reset 样式和各个页面的公共样式
36 | - mods 模块css,用于存放各个业务模块的样式
37 | - pages
38 |
39 | ## JS 目录说明
40 |
41 | src/js 目录为前端JS源文件存放位置
42 |
43 | #### entry 业务入口文件
44 |
45 | - entry/page 页面入口文件
46 | - entry/module 独立加载的模块
47 | - entry/static 其他静态脚本,例如统计等
48 | - entry/global.js 公共组件
49 |
50 | #### lib 和业务无关的公共组件
51 |
52 | - lib/core 项目构建骨架
53 | - lib/kit 各类工具函数
54 | - lib/more 项目支撑模块
55 | - lib/mvc 用于支持MVC设计模式的组件
56 |
57 | #### comp 可在其他项目复用的业务组件,使用时还需根据项目环境配置
58 |
59 | - comp/channel 可复用广播
60 | - comp/common 可复用项目公共组件
61 | - comp/model 可复用数据模型
62 | - comp/tpl 可复用模板
63 | - comp/ui 有固定交互方式的组件
64 |
65 | #### mods 不易在其他项目复用的组件
66 |
67 | - mods/channel 业务广播
68 | - mods/model 可复用数据模型
69 | - mods/layer 各种浮层
70 | - mods/pl 页面业务模块,取自 pagelet
71 | - mods/tpl 业务组件所需模板
72 | - mods/trans 统一定义业务所需接口
73 | - mods/view 页面业务模块需要复用的交互逻辑
74 |
75 | #### plugin 采用的JS库的插件
76 |
77 | #### vendor 采用的第三方库
78 |
79 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/util/template.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/util/template
3 | @example
4 | var $tpl = require('lib/kit/util/template');
5 | var TPL = $tpl({
6 | item : [
7 | ''
10 | ],
11 | str : 'test'
12 | });
13 | TPL.item; //['']
14 | TPL.get('item'); //''
15 | TPL.str; //'test'
16 | TPL.get('str'); //'test'
17 | **/
18 |
19 | var $ = require('../../../lib');
20 |
21 | /**
22 | 模板管理器
23 |
24 | 模板对象是一个简单的单体对象,每个属性为一个模板数组或者模板字符串。
25 |
26 | 模板数组在定义时不会做任何处理,但在获取时会被转换为模板字符串。
27 |
28 | 这个机制是为了减少代码初始化时字符串拼接带来的性能消耗。
29 |
30 | @constructor module:lib/kit/util/template
31 | @param {object} obj 模板对象
32 | **/
33 | module.exports = function(obj){
34 | var tpl = {};
35 | var that = {};
36 |
37 | /**
38 | 配置模板
39 | @function set
40 | @memberof module:lib/kit/util/template
41 | @param {object} object 模板对象
42 | **/
43 | that.set = function(object){
44 | $.extend(that, object);
45 | $.extend(tpl, object);
46 | };
47 |
48 | /**
49 | 获取模板字符串
50 | @function get
51 | @memberof module:lib/kit/util/template
52 | @param {string} name 模板名称
53 | @return {string} 拼接完成的模板字符串
54 | **/
55 | that.get = function(name){
56 | var str = '';
57 | var part = tpl[name];
58 | if(part){
59 | if(typeof part === 'string'){
60 | str = part;
61 | }else if(Array.isArray(part)){
62 | tpl[name] = str = part.join('');
63 | }
64 | }
65 | return str;
66 | };
67 |
68 | that.set(obj);
69 |
70 | return that;
71 | };
72 |
73 |
74 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/fx/smoothScrollTo.js:
--------------------------------------------------------------------------------
1 | /**
2 | 平滑滚动到某个元素
3 |
4 | @param {element} node 目标DOM元素
5 | @param {object} spec 选项
6 | @param {number} [spec.delta=0] 目标滚动位置与目标元素顶部的间距,可以为负值
7 | @param {function} [options.callback=$.noop] 滚动完成的回调函数
8 |
9 | @example
10 |
11 | var $smoothScrollTo = require('lib/kit/fx/smoothScrollTo');
12 |
13 | //滚动到页面顶端
14 | $smoothScrollTo(document.body);
15 |
16 | **/
17 |
18 | var $ = require('../../../lib');
19 |
20 | var smoothScrollTo = function(node, spec){
21 | var conf = $.extend({
22 | delta : 0,
23 | callback : $.noop
24 | },spec);
25 |
26 | var offset = $(node).offset();
27 | var target = offset.top + conf.delta;
28 | var duration = 1000;
29 | var callback = conf.callback;
30 |
31 | var prevStep;
32 | var stayCount = 3;
33 | var timer = setInterval(function(){
34 | var sTop = $(window).scrollTop();
35 | var delta = sTop - target;
36 | if(delta > 0){
37 | delta = Math.floor(delta * 0.8);
38 | }else if(delta < 0){
39 | delta = Math.ceil(delta * 0.8);
40 | }
41 |
42 | var step = target + delta;
43 | if(step === prevStep){
44 | stayCount --;
45 | }
46 | prevStep = step;
47 |
48 | window.scrollTo(0, step);
49 |
50 | if(step === target || stayCount <= 0){
51 | stopTimer();
52 | }
53 | }, 16);
54 |
55 | var stopTimer = function(){
56 | if(timer){
57 | clearInterval(timer);
58 | timer = null;
59 | window.scrollTo(0, target);
60 | if($.isFunction(callback)){
61 | callback();
62 | }
63 | }
64 | };
65 |
66 | setTimeout(function(){
67 | stopTimer();
68 | }, 3000);
69 | };
70 |
71 | module.exports = smoothScrollTo;
72 |
73 |
74 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/fx/smoothScrollTo.js:
--------------------------------------------------------------------------------
1 | /**
2 | 平滑滚动到某个元素
3 |
4 | @param {element} node 目标DOM元素
5 | @param {object} spec 选项
6 | @param {number} [spec.delta=0] 目标滚动位置与目标元素顶部的间距,可以为负值
7 | @param {function} [options.callback=$.noop] 滚动完成的回调函数
8 |
9 | @example
10 |
11 | var $smoothScrollTo = require('lib/kit/fx/smoothScrollTo');
12 |
13 | //滚动到页面顶端
14 | $smoothScrollTo(document.body);
15 |
16 | **/
17 |
18 | var $ = require('../../../lib');
19 |
20 | var smoothScrollTo = function(node, spec){
21 | var conf = $.extend({
22 | delta : 0,
23 | callback : $.noop
24 | },spec);
25 |
26 | var offset = $(node).offset();
27 | var target = offset.top + conf.delta;
28 | var duration = 1000;
29 | var callback = conf.callback;
30 |
31 | var prevStep;
32 | var stayCount = 3;
33 | var timer = setInterval(function(){
34 | var sTop = $(window).scrollTop();
35 | var delta = sTop - target;
36 | if(delta > 0){
37 | delta = Math.floor(delta * 0.8);
38 | }else if(delta < 0){
39 | delta = Math.ceil(delta * 0.8);
40 | }
41 |
42 | var step = target + delta;
43 | if(step === prevStep){
44 | stayCount --;
45 | }
46 | prevStep = step;
47 |
48 | window.scrollTo(0, step);
49 |
50 | if(step === target || stayCount <= 0){
51 | stopTimer();
52 | }
53 | }, 16);
54 |
55 | var stopTimer = function(){
56 | if(timer){
57 | clearInterval(timer);
58 | timer = null;
59 | window.scrollTo(0, target);
60 | if($.isFunction(callback)){
61 | callback();
62 | }
63 | }
64 | };
65 |
66 | setTimeout(function(){
67 | stopTimer();
68 | }, 3000);
69 | };
70 |
71 | module.exports = smoothScrollTo;
72 |
73 |
74 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/util/template.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/util/template
3 | @example
4 | var $tpl = require('lib/kit/util/template');
5 | var TPL = $tpl({
6 | item : [
7 | ''
10 | ],
11 | str : 'test'
12 | });
13 | TPL.item; //['']
14 | TPL.get('item'); //''
15 | TPL.str; //'test'
16 | TPL.get('str'); //'test'
17 | **/
18 |
19 | var $ = require('../../../lib');
20 |
21 | /**
22 | 模板管理器
23 |
24 | 模板对象是一个简单的单体对象,每个属性为一个模板数组或者模板字符串。
25 |
26 | 模板数组在定义时不会做任何处理,但在获取时会被转换为模板字符串。
27 |
28 | 这个机制是为了减少代码初始化时字符串拼接带来的性能消耗。
29 |
30 | @constructor module:lib/kit/util/template
31 | @param {object} obj 模板对象
32 | **/
33 | module.exports = function(obj){
34 | var tpl = {};
35 | var that = {};
36 |
37 | /**
38 | 配置模板
39 | @function set
40 | @memberof module:lib/kit/util/template
41 | @param {object} object 模板对象
42 | **/
43 | that.set = function(object){
44 | $.extend(that, object);
45 | $.extend(tpl, object);
46 | };
47 |
48 | /**
49 | 获取模板字符串
50 | @function get
51 | @memberof module:lib/kit/util/template
52 | @param {string} name 模板名称
53 | @return {string} 拼接完成的模板字符串
54 | **/
55 | that.get = function(name){
56 | var str = '';
57 | var part = tpl[name];
58 | if(part){
59 | if(typeof part === 'string'){
60 | str = part;
61 | }else if(Array.isArray(part)){
62 | tpl[name] = str = part.join('');
63 | }
64 | }
65 | return str;
66 | };
67 |
68 | that.set(obj);
69 |
70 | return that;
71 | };
72 |
73 |
74 |
--------------------------------------------------------------------------------
/generators/app/templates/js/plugin/transform.js:
--------------------------------------------------------------------------------
1 | /**
2 | transform属性获取与设置
3 |
4 | @mixin lib/plugin/transform
5 | @param {String} property 要设置的 transform 属性
6 | @param {Object} property transform 键值对
7 | @param {String} value 要设置的 transform 值
8 | @returns transform属性值, transform字符串,或者undefined
9 | @example
10 | $('div').transform('translateX', '20px');
11 | $('div').transform({
12 | 'translateX' : '20px'
13 | });
14 | $('div').transform(); //'translateX(20px)'
15 | $('div').transform('translateX'); //'20px'
16 | **/
17 |
18 | exports.mixTo = function($){
19 |
20 | $.fn.transform = function(property, value){
21 | var obj = {};
22 | var transform = $(this).css('transform') || '';
23 | transform = transform === 'none' ? '' : transform;
24 |
25 | transform = transform.replace(/,\s+/gi, ',');
26 |
27 | $.each(transform.split(/\s+/gi), function(index, str){
28 | if(!str){return;}
29 | var name = str.match(/\w+/)[0];
30 | var val = str.replace(name, '').replace(/[\(\)]/gi,'');
31 | val = $.trim(val);
32 | obj[name] = val;
33 | });
34 |
35 | if(!property){
36 | return obj;
37 | }
38 |
39 | if(typeof property === 'string'){
40 | if($.type(value) === 'undefined'){
41 | return obj[property] || 0;
42 | }else{
43 | obj[property] = value;
44 | }
45 | }else{
46 | $.extend(obj, property);
47 | }
48 |
49 | transform = [];
50 | $.each(obj, function(key, val){
51 | var str = key + '(' + val + ')';
52 | transform.push(str);
53 | });
54 |
55 | if(transform.length){
56 | transform = transform.join(' ');
57 | }else{
58 | transform = '';
59 | }
60 |
61 | return $(this).css('transform', transform);
62 | };
63 |
64 | };
65 |
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/util/makeReady.js:
--------------------------------------------------------------------------------
1 | /**
2 | 构建一个Ready事件管理组件
3 |
4 | 执行任务前判断条件是否齐备,若未未齐备,则延迟到齐备时按调用顺序执行任务。
5 |
6 | 若已条件齐备,则立即执行。
7 |
8 | @module lib/kit/util/makeReady
9 | @example
10 | var $makeReady = require('lib/kit/util/makeReady');
11 | var prop = 'not ready';
12 | var obj = $makeReady();
13 | setTimeout(function(){
14 | prop = 'ready';
15 | obj.setReady();
16 | }, 1000);
17 |
18 | console.info(prop); //not ready
19 |
20 | obj.ready(function(){
21 | console.info(prop); //ready
22 | });
23 |
24 | setTimeout(function(){
25 | var str = 'exec immediatelly';
26 | obj.ready(function(){
27 | console.info(prop); //ready
28 | console.info(str); //exec immediatelly
29 | });
30 | }, 2000);
31 | **/
32 |
33 | var $ = require('../../../lib');
34 |
35 | /**
36 | 构建一个缓存队列,在未设置条件完成前收集需要执行的任务
37 | @constructor module:lib/kit/util/makeReady
38 | **/
39 | module.exports = function(){
40 | var isReady = false;
41 | var cache = [];
42 |
43 | return {
44 | /**
45 | 设置条件完成,缓存的任务会立即执行
46 | **/
47 | setReady : function(){
48 | isReady = true;
49 | if(isReady){
50 | while(cache.length > 0){
51 | cache.shift()();
52 | }
53 | }
54 | },
55 | /**
56 | 添加条件完成时需要执行的任务
57 | @param {function} fn 任务函数
58 | **/
59 | ready : function(fn){
60 | if($.type(fn) === 'function'){
61 | if(isReady){
62 | fn();
63 | }else{
64 | cache.push(fn);
65 | }
66 | }
67 | },
68 | /**
69 | 重置对象,清空所有任务,准备条件设置为false
70 | **/
71 | reset : function(){
72 | isReady = false;
73 | cache.length = 0;
74 | },
75 | /**
76 | 销毁任务准备对象,清空所有任务,准备条件设置为false,尽量释放内存
77 | **/
78 | destroy : function(){
79 | this.reset();
80 | }
81 | };
82 | };
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/mvc/delegate.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/mvc/delegate
3 | **/
4 |
5 | /**
6 | 事件对象绑定,将events中包含的键值对映射为代理的事件
7 |
8 | 事件键值对格式可以为:
9 |
10 | - {'selector event':'method'}
11 | - {'event':'method'}
12 | - {'selector event':'method1 method2'}
13 | - {'event':'method1 method2'}
14 |
15 | @param {boolean} action 开/关代理,可选:['on', 'off']。
16 | @param {object} root 设置代理的根节点,可以是一个jquery对象,或者是混合了 lib/more/events 方法的对象。
17 | @param {object} events 事件键值对
18 | @param {object} bind 指定事件函数绑定的对象,必须为MVC类的实例。
19 | **/
20 |
21 | var $ = require('../../lib');
22 |
23 | module.exports = function(action, root, events, bind){
24 |
25 | var proxy, delegate;
26 | if(!root){return;}
27 | if(!bind || !$.isFunction(bind.proxy)){return;}
28 |
29 | proxy = bind.proxy();
30 | action = action === 'on' ? 'on' : 'off';
31 | delegate = action === 'on' ? 'delegate' : 'undelegate';
32 | events = $.extend({}, events);
33 |
34 | $.each(events, function(handle, method){
35 |
36 | var selector, event, fns = [];
37 | handle = handle.split(/\s+/);
38 |
39 | if($.type(method) === 'string'){
40 | fns = method.split(/\s+/).map(function(fname){
41 | return proxy(fname);
42 | });
43 | }else if($.isFunction(method)){
44 | fns = [method];
45 | }else{
46 | return;
47 | }
48 |
49 | event = handle.pop();
50 |
51 | if(handle.length >= 1){
52 | selector = handle.join(' ');
53 | if($.isFunction(root[delegate])){
54 | fns.forEach(function(fn){
55 | root[delegate](selector, event, fn);
56 | });
57 | }
58 | }else{
59 | if($.isFunction(root[action])){
60 | fns.forEach(function(fn){
61 | root[action](event, fn);
62 | });
63 | }
64 | }
65 |
66 | });
67 |
68 | };
69 |
70 |
71 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/env/ua.js:
--------------------------------------------------------------------------------
1 | /**
2 | 通过UA获取设备信息
3 |
4 | - 仅根据设备UA来进行检测,不考虑其他特征,如需获取更准确匹配,请使用其他组件。
5 |
6 | @module lib/kit/env/ua
7 | @see http://www.useragentstring.com/
8 | @see module:lib/kit/env/platform
9 | @see module:lib/kit/env/os
10 | @see module:lib/kit/env/browser
11 | @see module:lib/kit/env/device
12 | @example
13 | var $ua = require('lib/kit/env/ua');
14 | console.info($ua.os, $ua.browser, $ua.device, $ua.platform);
15 |
16 | var info = $ua.test('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36');
17 | console.info(info.os); //{type:'mac', version:10.10}
18 | console.info(info.browser); //{type:'chrome', version:40.0}
19 | console.info(info.device); //{type:'pc', version:0.00}
20 | console.info(info.platform); //mac
21 | **/
22 |
23 | /**
24 | 测试 UA 字符串,返回测试结果
25 | @alias module:lib/kit/env/ua.test
26 | @param {string} [ua=navigator.userAgent] UA字符串
27 | @return {object} 测试结果对象
28 | **/
29 | var testUA = function(ua){
30 | var info = {};
31 | ua = ua || navigator.userAgent;
32 |
33 | info.platform = '';
34 | info.os = {
35 | type : '',
36 | version : 0
37 | };
38 | info.browser = {
39 | type : '',
40 | version : 0
41 | };
42 | info.device = {
43 | type : '',
44 | version : 0
45 | };
46 | return info;
47 | };
48 |
49 | var uainfo = testUA();
50 |
51 | exports.test = testUA;
52 |
53 | /**
54 | 平台信息
55 | @type {string}
56 | **/
57 | exports.platform = uainfo.platform;
58 |
59 | /**
60 | 操作系统信息
61 | @type {object}
62 | **/
63 | exports.os = uainfo.os;
64 |
65 | /**
66 | 浏览器信息
67 | @type {object}
68 | **/
69 | exports.browser = uainfo.browser;
70 |
71 | /**
72 | 设备信息
73 | @type {object}
74 | **/
75 | exports.device = uainfo.device;
76 |
77 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/env/ua.js:
--------------------------------------------------------------------------------
1 | /**
2 | 通过UA获取设备信息
3 |
4 | - 仅根据设备UA来进行检测,不考虑其他特征,如需获取更准确匹配,请使用其他组件。
5 |
6 | @module lib/kit/env/ua
7 | @see http://www.useragentstring.com/
8 | @see module:lib/kit/env/platform
9 | @see module:lib/kit/env/os
10 | @see module:lib/kit/env/browser
11 | @see module:lib/kit/env/device
12 | @example
13 | var $ua = require('lib/kit/env/ua');
14 | console.info($ua.os, $ua.browser, $ua.device, $ua.platform);
15 |
16 | var info = $ua.test('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36');
17 | console.info(info.os); //{type:'mac', version:10.10}
18 | console.info(info.browser); //{type:'chrome', version:40.0}
19 | console.info(info.device); //{type:'pc', version:0.00}
20 | console.info(info.platform); //mac
21 | **/
22 |
23 | /**
24 | 测试 UA 字符串,返回测试结果
25 | @alias module:lib/kit/env/ua.test
26 | @param {string} [ua=navigator.userAgent] UA字符串
27 | @return {object} 测试结果对象
28 | **/
29 | var testUA = function(ua){
30 | var info = {};
31 | ua = ua || navigator.userAgent;
32 |
33 | info.platform = '';
34 | info.os = {
35 | type : '',
36 | version : 0
37 | };
38 | info.browser = {
39 | type : '',
40 | version : 0
41 | };
42 | info.device = {
43 | type : '',
44 | version : 0
45 | };
46 | return info;
47 | };
48 |
49 | var uainfo = testUA();
50 |
51 | exports.test = testUA;
52 |
53 | /**
54 | 平台信息
55 | @type {string}
56 | **/
57 | exports.platform = uainfo.platform;
58 |
59 | /**
60 | 操作系统信息
61 | @type {object}
62 | **/
63 | exports.os = uainfo.os;
64 |
65 | /**
66 | 浏览器信息
67 | @type {object}
68 | **/
69 | exports.browser = uainfo.browser;
70 |
71 | /**
72 | 设备信息
73 | @type {object}
74 | **/
75 | exports.device = uainfo.device;
76 |
77 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/time/split.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/time/split
3 |
4 | @example
5 | var $timeSplit = require('lib/kit/time/split.js');
6 |
7 | console.info( $timeSplit(12345 * 67890) );
8 | //Object {day: 9, hour: 16, minute: 48, second: 22, ms: 50}
9 |
10 | console.info( $timeSplit(12345 * 67890, {maxUnit : 'hour'}) );
11 | //Object {hour: 232, minute: 48, second: 22, ms: 50}
12 | **/
13 |
14 | var $ = require('../../../lib');
15 | var $numerical = require('../num/numerical');
16 |
17 | var UNIT = {
18 | day : 24 * 60 * 60 * 1000,
19 | hour : 60 * 60 * 1000,
20 | minute : 60 * 1000,
21 | second : 1000
22 | };
23 |
24 | /**
25 | 时间数字拆分为天时分秒
26 | @param {number} time 毫秒数
27 | @param {object} spec 选项
28 | @param {string} [spec.maxUnit='day'] 拆分时间的最大单位,可选 ['day', 'hour', 'minute', 'second']
29 | @return {object} 拆分完成的天时分秒
30 | **/
31 | module.exports = function(time, spec){
32 |
33 | var conf = $.extend({
34 | maxUnit : 'day'
35 | }, spec);
36 |
37 | var data = {};
38 | var maxUnit = $numerical(UNIT[conf.maxUnit]);
39 | var uDay = UNIT.day;
40 | var uHour = UNIT.hour;
41 | var uMinute = UNIT.minute;
42 | var uSecond = UNIT.second;
43 |
44 | if(maxUnit >= uDay){
45 | time = $numerical(time);
46 | data.day = Math.floor(time / uDay);
47 | }
48 |
49 | if(maxUnit >= uHour){
50 | time = time - $numerical(data.day * uDay);
51 | data.hour = Math.floor(time / uHour);
52 | }
53 |
54 | if(maxUnit >= uMinute){
55 | time = time - $numerical(data.hour * uHour);
56 | data.minute = Math.floor(time / uMinute);
57 | }
58 |
59 | if(maxUnit >= uSecond){
60 | time = time - $numerical(data.minute * uMinute);
61 | data.second = Math.floor(time / uSecond);
62 | }
63 |
64 | data.ms = time - data.second * uSecond;
65 |
66 | return data;
67 | };
68 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/plugin/transform.js:
--------------------------------------------------------------------------------
1 | /**
2 | transform属性获取与设置
3 |
4 | @mixin lib/plugin/transform
5 | @param {String} property 要设置的 transform 属性
6 | @param {Object} property transform 键值对
7 | @param {String} value 要设置的 transform 值
8 | @returns transform属性值, transform字符串,或者undefined
9 | @example
10 | $('div').transform('translateX', '20px');
11 | $('div').transform({
12 | 'translateX' : '20px'
13 | });
14 | $('div').transform(); //'translateX(20px)'
15 | $('div').transform('translateX'); //'20px'
16 | **/
17 |
18 | exports.mixTo = function($){
19 |
20 | $.fn.transform = function(property, value){
21 | var obj = {};
22 | var transform = $(this).css('transform') || '';
23 | transform = transform === 'none' ? '' : transform;
24 |
25 | transform = transform.replace(/,\s+/gi, ',');
26 |
27 | $.each(transform.split(/\s+/gi), function(index, str){
28 | if(!str){return;}
29 | var name = str.match(/\w+/)[0];
30 | var val = str.replace(name, '').replace(/[\(\)]/gi,'');
31 | val = $.trim(val);
32 | obj[name] = val;
33 | });
34 |
35 | if(!property){
36 | return obj;
37 | }
38 |
39 | if(typeof property === 'string'){
40 | if($.type(value) === 'undefined'){
41 | return obj[property] || 0;
42 | }else{
43 | obj[property] = value;
44 | }
45 | }else{
46 | $.extend(obj, property);
47 | }
48 |
49 | transform = [];
50 | $.each(obj, function(key, val){
51 | var str = key + '(' + val + ')';
52 | transform.push(str);
53 | });
54 |
55 | if(transform.length){
56 | transform = transform.join(' ');
57 | }else{
58 | transform = '';
59 | }
60 |
61 | return $(this).css('transform', transform);
62 | };
63 |
64 | };
65 |
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/generators/app/templates/html/pages/home.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | @@include('../common/meta.html')
5 | 首页
6 | @@include('../common/link.html')
7 | @@include('../common/script-head.html')
8 |
9 |
10 |
11 |
查看全部
12 |
官微消息
13 |
27 |
32 |
33 |
34 | @@include('../common/script-foot.html')
35 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/time/split.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/time/split
3 |
4 | @example
5 | var $timeSplit = require('lib/kit/time/split.js');
6 |
7 | console.info( $timeSplit(12345 * 67890) );
8 | //Object {day: 9, hour: 16, minute: 48, second: 22, ms: 50}
9 |
10 | console.info( $timeSplit(12345 * 67890, {maxUnit : 'hour'}) );
11 | //Object {hour: 232, minute: 48, second: 22, ms: 50}
12 | **/
13 |
14 | var $ = require('../../../lib');
15 | var $numerical = require('../num/numerical');
16 |
17 | var UNIT = {
18 | day : 24 * 60 * 60 * 1000,
19 | hour : 60 * 60 * 1000,
20 | minute : 60 * 1000,
21 | second : 1000
22 | };
23 |
24 | /**
25 | 时间数字拆分为天时分秒
26 | @param {number} time 毫秒数
27 | @param {object} spec 选项
28 | @param {string} [spec.maxUnit='day'] 拆分时间的最大单位,可选 ['day', 'hour', 'minute', 'second']
29 | @return {object} 拆分完成的天时分秒
30 | **/
31 | module.exports = function(time, spec){
32 |
33 | var conf = $.extend({
34 | maxUnit : 'day'
35 | }, spec);
36 |
37 | var data = {};
38 | var maxUnit = $numerical(UNIT[conf.maxUnit]);
39 | var uDay = UNIT.day;
40 | var uHour = UNIT.hour;
41 | var uMinute = UNIT.minute;
42 | var uSecond = UNIT.second;
43 |
44 | if(maxUnit >= uDay){
45 | time = $numerical(time);
46 | data.day = Math.floor(time / uDay);
47 | }
48 |
49 | if(maxUnit >= uHour){
50 | time = time - $numerical(data.day * uDay);
51 | data.hour = Math.floor(time / uHour);
52 | }
53 |
54 | if(maxUnit >= uMinute){
55 | time = time - $numerical(data.hour * uHour);
56 | data.minute = Math.floor(time / uMinute);
57 | }
58 |
59 | if(maxUnit >= uSecond){
60 | time = time - $numerical(data.minute * uMinute);
61 | data.second = Math.floor(time / uSecond);
62 | }
63 |
64 | data.ms = time - data.second * uSecond;
65 |
66 | return data;
67 | };
68 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/mvc/delegate.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/mvc/delegate
3 | **/
4 |
5 | /**
6 | 事件对象绑定,将events中包含的键值对映射为代理的事件
7 |
8 | 事件键值对格式可以为:
9 |
10 | - {'selector event':'method'}
11 | - {'event':'method'}
12 | - {'selector event':'method1 method2'}
13 | - {'event':'method1 method2'}
14 |
15 | @param {boolean} action 开/关代理,可选:['on', 'off']。
16 | @param {object} root 设置代理的根节点,可以是一个jquery对象,或者是混合了 lib/more/events 方法的对象。
17 | @param {object} events 事件键值对
18 | @param {object} bind 指定事件函数绑定的对象,必须为MVC类的实例。
19 | **/
20 |
21 | var $ = require('../../lib');
22 |
23 | module.exports = function(action, root, events, bind){
24 |
25 | var proxy, delegate;
26 | if(!root){return;}
27 | if(!bind || !$.isFunction(bind.proxy)){return;}
28 |
29 | proxy = bind.proxy();
30 | action = action === 'on' ? 'on' : 'off';
31 | delegate = action === 'on' ? 'delegate' : 'undelegate';
32 | events = $.extend({}, events);
33 |
34 | $.each(events, function(handle, method){
35 |
36 | var selector, event, fns = [];
37 | handle = handle.split(/\s+/);
38 |
39 | if($.type(method) === 'string'){
40 | fns = method.split(/\s+/).map(function(fname){
41 | return proxy(fname);
42 | });
43 | }else if($.isFunction(method)){
44 | fns = [method];
45 | }else{
46 | return;
47 | }
48 |
49 | event = handle.pop();
50 |
51 | if(handle.length >= 1){
52 | selector = handle.join(' ');
53 | if($.isFunction(root[delegate])){
54 | fns.forEach(function(fn){
55 | root[delegate](selector, event, fn);
56 | });
57 | }
58 | }else{
59 | if($.isFunction(root[action])){
60 | fns.forEach(function(fn){
61 | root[action](event, fn);
62 | });
63 | }
64 | }
65 |
66 | });
67 |
68 | };
69 |
70 |
71 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/util/makeReady.js:
--------------------------------------------------------------------------------
1 | /**
2 | 构建一个Ready事件管理组件
3 |
4 | 执行任务前判断条件是否齐备,若未未齐备,则延迟到齐备时按调用顺序执行任务。
5 |
6 | 若已条件齐备,则立即执行。
7 |
8 | @module lib/kit/util/makeReady
9 | @example
10 | var $makeReady = require('lib/kit/util/makeReady');
11 | var prop = 'not ready';
12 | var obj = $makeReady();
13 | setTimeout(function(){
14 | prop = 'ready';
15 | obj.setReady();
16 | }, 1000);
17 |
18 | console.info(prop); //not ready
19 |
20 | obj.ready(function(){
21 | console.info(prop); //ready
22 | });
23 |
24 | setTimeout(function(){
25 | var str = 'exec immediatelly';
26 | obj.ready(function(){
27 | console.info(prop); //ready
28 | console.info(str); //exec immediatelly
29 | });
30 | }, 2000);
31 | **/
32 |
33 | var $ = require('../../../lib');
34 |
35 | /**
36 | 构建一个缓存队列,在未设置条件完成前收集需要执行的任务
37 | @constructor module:lib/kit/util/makeReady
38 | **/
39 | module.exports = function(){
40 | var isReady = false;
41 | var cache = [];
42 |
43 | return {
44 | /**
45 | 设置条件完成,缓存的任务会立即执行
46 | **/
47 | setReady : function(){
48 | isReady = true;
49 | if(isReady){
50 | while(cache.length > 0){
51 | cache.shift()();
52 | }
53 | }
54 | },
55 | /**
56 | 添加条件完成时需要执行的任务
57 | @param {function} fn 任务函数
58 | **/
59 | ready : function(fn){
60 | if($.type(fn) === 'function'){
61 | if(isReady){
62 | fn();
63 | }else{
64 | cache.push(fn);
65 | }
66 | }
67 | },
68 | /**
69 | 重置对象,清空所有任务,准备条件设置为false
70 | **/
71 | reset : function(){
72 | isReady = false;
73 | cache.length = 0;
74 | },
75 | /**
76 | 销毁任务准备对象,清空所有任务,准备条件设置为false,尽量释放内存
77 | **/
78 | destroy : function(){
79 | this.reset();
80 | }
81 | };
82 | };
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/ui/autoloadList.js:
--------------------------------------------------------------------------------
1 | var $ = require('../../lib');
2 | var $view = require('../../lib/mvc/view');
3 | var $tplLoading = require('../tpl/loading.tpl');
4 | var $tplLoaded = require('../tpl/loaded.tpl');
5 |
6 | var AutoloadList = $view.extend({
7 | defaults : {
8 | node : null,
9 | role : {
10 | list : 'ul',
11 | loading : '.loading'
12 | }
13 | },
14 | build : function(){
15 | this.curPage = 1;
16 | this.loadedAll = false;
17 | this.setLoading();
18 | this.checkScroll();
19 | },
20 | setEvents : function(){
21 | $(window).on('scroll', this.proxy('checkScroll'));
22 | },
23 | loadNextPage : function(){
24 | var nextPage = this.curPage + 1;
25 | this.request(nextPage);
26 | },
27 | request : function(page){
28 | //请求分页数据
29 | },
30 | //在列表中追加请求到的单页数据
31 | append : function(pageData){
32 | pageData = pageData || {};
33 | var page = parseInt(pageData.page, 10) || 0;
34 | if(page === this.curPage + 1){
35 | var appendNodes = $(this.render(pageData));
36 | appendNodes.appendTo(this.role('list'));
37 | this.curPage++;
38 | }
39 | },
40 | render : function(pageData){
41 | //渲染单页数据
42 | },
43 | setLoadedAll : function(){
44 | this.loadedAll = true;
45 | var loadingNode = this.role('loading');
46 | loadingNode.html($($tplLoaded).html());
47 | },
48 | setLoading : function(){
49 | if(!this.role('loading').length){
50 | var loadingNode = $($tplLoading).insertAfter(this.role('list'));
51 | this.role('loading', loadingNode);
52 | }else{
53 | this.role('loading').html($($tplLoading).html());
54 | }
55 | },
56 | checkScroll : function(){
57 | if(this.loadedAll){return;}
58 | var loadingNode = this.role('loading');
59 | var offset = loadingNode.offset();
60 | if(offset.top < window.innerHeight + $(window).scrollTop()){
61 | this.loadNextPage();
62 | }
63 | }
64 | });
65 |
66 | module.exports = AutoloadList;
67 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/ui/autoloadList.js:
--------------------------------------------------------------------------------
1 | var $ = require('../../lib');
2 | var $view = require('../../lib/mvc/view');
3 | var $tplLoading = require('../tpl/loading.tpl');
4 | var $tplLoaded = require('../tpl/loaded.tpl');
5 |
6 | var AutoloadList = $view.extend({
7 | defaults : {
8 | node : null,
9 | role : {
10 | list : 'ul',
11 | loading : '.loading'
12 | }
13 | },
14 | build : function(){
15 | this.curPage = 1;
16 | this.loadedAll = false;
17 | this.setLoading();
18 | this.checkScroll();
19 | },
20 | setEvents : function(){
21 | $(window).on('scroll', this.proxy('checkScroll'));
22 | },
23 | loadNextPage : function(){
24 | var nextPage = this.curPage + 1;
25 | this.request(nextPage);
26 | },
27 | request : function(page){
28 | //请求分页数据
29 | },
30 | //在列表中追加请求到的单页数据
31 | append : function(pageData){
32 | pageData = pageData || {};
33 | var page = parseInt(pageData.page, 10) || 0;
34 | if(page === this.curPage + 1){
35 | var appendNodes = $(this.render(pageData));
36 | appendNodes.appendTo(this.role('list'));
37 | this.curPage++;
38 | }
39 | },
40 | render : function(pageData){
41 | //渲染单页数据
42 | },
43 | setLoadedAll : function(){
44 | this.loadedAll = true;
45 | var loadingNode = this.role('loading');
46 | loadingNode.html($($tplLoaded).html());
47 | },
48 | setLoading : function(){
49 | if(!this.role('loading').length){
50 | var loadingNode = $($tplLoading).insertAfter(this.role('list'));
51 | this.role('loading', loadingNode);
52 | }else{
53 | this.role('loading').html($($tplLoading).html());
54 | }
55 | },
56 | checkScroll : function(){
57 | if(this.loadedAll){return;}
58 | var loadingNode = this.role('loading');
59 | var offset = loadingNode.offset();
60 | if(offset.top < window.innerHeight + $(window).scrollTop()){
61 | this.loadNextPage();
62 | }
63 | }
64 | });
65 |
66 | module.exports = AutoloadList;
67 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/util/cookie.js:
--------------------------------------------------------------------------------
1 | var $ = require('../../../lib');
2 |
3 | /**
4 | 设置、获取cookie
5 | @exports lib/kit/util/cookie
6 | **/
7 | var Cookie = {
8 | /**
9 | 将数据保存到cookie
10 | @param {string} sKey cookie名称
11 | @param {string} sValue 要存储的值
12 |
13 | @param {object} [oOpts] 存储选项
14 | @param {string} oOpts.expire 过期时间(小时)
15 | @param {string} [oOpts.path='/'] 路径
16 | @param {string} [oOpts.domain] 域名
17 | @param {boolean} [oOpts.secure=false] 是否为安全连接
18 | @param {boolean} [oOpts.encode=true] 存储的数据是否自动用escape编码
19 | **/
20 | set: function(sKey, sValue, oOpts){
21 | var arr = [];
22 | var d, t;
23 | var cfg = $.extend({
24 | 'expire': null,
25 | 'path': '/',
26 | 'domain': null,
27 | 'secure': false,
28 | 'encode': true
29 | }, oOpts);
30 |
31 | if (cfg.encode === true) {
32 | sValue = window.escape(sValue);
33 | }
34 | arr.push(sKey + '=' + sValue);
35 |
36 | if (cfg.path !== null) {
37 | arr.push('path=' + cfg.path);
38 | }
39 | if (cfg.domain !== null) {
40 | arr.push('domain=' + cfg.domain);
41 | }
42 | if (cfg.secure) {
43 | arr.push('secure');
44 | }
45 | if (cfg.expire !== null) {
46 | d = new Date();
47 | t = d.getTime() + cfg.expire * 3600000;
48 | d.setTime(t);
49 | arr.push('expires=' + d.toGMTString());
50 | }
51 | document.cookie = arr.join(';');
52 | },
53 | /**
54 | 获取cookie中存储的数据
55 | @param {string} sKey cookie名称
56 | @return {string} 存储的数据
57 | **/
58 | get: function(sKey){
59 | var cookies = document.cookie.split(/\s*;\s*/);
60 | var cobj = {};
61 | cookies.forEach(function(pair){
62 | var arr = pair.split(/=/);
63 | cobj[arr[0]] = arr[1];
64 | });
65 | return cobj[sKey];
66 | },
67 | /**
68 | 移除cookie中存储的数据
69 | @param {string} sKey cookie名称
70 | @param {object} [oOpts] 同时需要设置的选项
71 | **/
72 | remove: function(sKey, oOpts){
73 | oOpts = oOpts || {};
74 | oOpts.expire = -10;
75 | this.set(sKey, '', oOpts);
76 | }
77 | };
78 |
79 | module.exports = Cookie;
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/generators/app/templates/gruntfile.js:
--------------------------------------------------------------------------------
1 | var $path = require('path');
2 |
3 | module.exports = function(grunt) {
4 |
5 | var timeStamp = Date.now();
6 |
7 | grunt.initConfig({
8 | projectDir : $path.resolve(__dirname, 'test'),
9 | timeStamp : timeStamp,
10 | clean : {
11 |
12 | },
13 | jshint: {
14 | options: {
15 | jshintrc: '.jshintrc'
16 | },
17 | client : {
18 | src : [
19 | 'src/js/lib/kit/**/*.js',
20 | 'src/js/entry/module/**/*.js',
21 | 'src/js/entry/page/**/*.js',
22 | 'src/js/entry/*.js',
23 | 'src/js/comp/**/*.js',
24 | 'src/js/mods/**/*.js'
25 | ]
26 | }
27 | },
28 | copy : {
29 | //sprity 替换 px 单位为rem
30 | sprity_rem : {
31 | expand : true,
32 | cwd : 'src/css/common/',
33 | src : 'sprite.css',
34 | dest : 'src/css/common/',
35 | options: {
36 | process: function (content, srcpath) {
37 | return content.replace(
38 | /([\d\.-]+)px/mg,
39 | function(word, num){
40 | num = parseFloat(num);
41 | num = (num / 100);
42 | return num + 'rem';
43 | }
44 | );
45 | }
46 | }
47 | }
48 | },
49 | sprity : {
50 | options : {
51 | cssPath : '../images',
52 | margin : 4,
53 | dimension : [{
54 | ratio : 1, dpi: 72
55 | }, {
56 | ratio : 2, dpi: 192
57 | }]
58 | },
59 | sprite : {
60 | options : {
61 | 'style' : '../../css/common/sprite.css'
62 | },
63 | src : [
64 | 'src/images/sprite/*'
65 | ],
66 | dest : 'src/images/sprite-output/sprite'
67 | }
68 | }
69 | });
70 |
71 | grunt.loadNpmTasks('grunt-contrib-clean');
72 | grunt.loadNpmTasks('grunt-contrib-jshint');
73 | grunt.loadNpmTasks('grunt-contrib-copy');
74 | grunt.loadNpmTasks('grunt-sprity');
75 |
76 | grunt.registerTask('sprity-rem', [
77 | 'sprity',
78 | 'copy:sprity_rem'
79 | ]);
80 |
81 | grunt.registerTask('test', [
82 | 'jshint'
83 | ]);
84 |
85 | // By default, lint and run all tests.
86 | grunt.registerTask('default', [
87 | 'test'
88 | ]);
89 |
90 | };
91 |
92 |
93 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/ui/switchGroup.js:
--------------------------------------------------------------------------------
1 | /**
2 | 开关按钮组
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $view = require('../../lib/mvc/view');
7 |
8 | var SwitchGroup = $view.extend({
9 | defaults : {
10 | closeAble : false,
11 | activeClass : 'on',
12 | node : null,
13 | role : {
14 | 'button' : '[role="button"]'
15 | }
16 | },
17 | events : {
18 | '[role="button"] click' : 'onBtnClick'
19 | },
20 | build : function(){
21 | var self = this;
22 | self.role('button').each(function(){
23 | var button = $(this);
24 | var active = self.getStatus(button);
25 | if(active){
26 | self.active = button;
27 | return false;
28 | }
29 | });
30 | },
31 | getStatus : function(button){
32 | return !!button.hasClass(this.conf.activeClass);
33 | },
34 | setStatus : function(button, active){
35 | var activeClass = this.conf.activeClass;
36 | if(active){
37 | button.addClass(activeClass);
38 | }else{
39 | button.removeClass(activeClass);
40 | }
41 | },
42 | getActive : function(){
43 | return this.active;
44 | },
45 | checkActive : function(){
46 | if(this.active){
47 | this.setStatus(this.active, false);
48 | this.active = null;
49 | }
50 | },
51 | setActive : function(button, active){
52 | active = !!active;
53 | var curActive = this.getStatus(button);
54 | if(active !== curActive){
55 | this.checkActive();
56 | this.setStatus(button, active);
57 | if(active){
58 | this.active = button;
59 | }
60 | this.trigger('change');
61 | }
62 | },
63 | open : function(button){
64 | this.setActive(button, true);
65 | },
66 | close : function(button){
67 | this.setActive(button, false);
68 | },
69 | toggle : function(button){
70 | var active = this.getStatus(button);
71 | if(this.conf.closeAble){
72 | this.setActive(button, !active);
73 | }else{
74 | this.setActive(button, true);
75 | }
76 | },
77 | onBtnClick : function(evt){
78 | evt.preventDefault();
79 | var button = $(evt.currentTarget);
80 | this.toggle(button);
81 | }
82 | });
83 |
84 | module.exports = SwitchGroup;
85 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/ui/switchGroup.js:
--------------------------------------------------------------------------------
1 | /**
2 | 开关按钮组
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $view = require('../../lib/mvc/view');
7 |
8 | var SwitchGroup = $view.extend({
9 | defaults : {
10 | closeAble : false,
11 | activeClass : 'on',
12 | node : null,
13 | role : {
14 | 'button' : '[role="button"]'
15 | }
16 | },
17 | events : {
18 | '[role="button"] click' : 'onBtnClick'
19 | },
20 | build : function(){
21 | var self = this;
22 | self.role('button').each(function(){
23 | var button = $(this);
24 | var active = self.getStatus(button);
25 | if(active){
26 | self.active = button;
27 | return false;
28 | }
29 | });
30 | },
31 | getStatus : function(button){
32 | return !!button.hasClass(this.conf.activeClass);
33 | },
34 | setStatus : function(button, active){
35 | var activeClass = this.conf.activeClass;
36 | if(active){
37 | button.addClass(activeClass);
38 | }else{
39 | button.removeClass(activeClass);
40 | }
41 | },
42 | getActive : function(){
43 | return this.active;
44 | },
45 | checkActive : function(){
46 | if(this.active){
47 | this.setStatus(this.active, false);
48 | this.active = null;
49 | }
50 | },
51 | setActive : function(button, active){
52 | active = !!active;
53 | var curActive = this.getStatus(button);
54 | if(active !== curActive){
55 | this.checkActive();
56 | this.setStatus(button, active);
57 | if(active){
58 | this.active = button;
59 | }
60 | this.trigger('change');
61 | }
62 | },
63 | open : function(button){
64 | this.setActive(button, true);
65 | },
66 | close : function(button){
67 | this.setActive(button, false);
68 | },
69 | toggle : function(button){
70 | var active = this.getStatus(button);
71 | if(this.conf.closeAble){
72 | this.setActive(button, !active);
73 | }else{
74 | this.setActive(button, true);
75 | }
76 | },
77 | onBtnClick : function(evt){
78 | evt.preventDefault();
79 | var button = $(evt.currentTarget);
80 | this.toggle(button);
81 | }
82 | });
83 |
84 | module.exports = SwitchGroup;
85 |
--------------------------------------------------------------------------------
/generators/app/templates/js/lib/kit/date/format.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/date/format
3 | @example
4 | var $dateFormat = require('lib/kit/date/format');
5 | console.info(
6 | $dateFormat(
7 | new Date(),
8 | {
9 | weekday : '日一二三四五六'.split(''),
10 | template : '{{YYYY}}年{{MM}}月{{DD}}日 周{{d}} {{hh}}时{{mm}}分{{ss}}秒'
11 | }
12 | )
13 | );
14 | //2015年09月09日 周三 14时19分42秒
15 | **/
16 |
17 | var $ = require('../../../lib');
18 | var $substitute = require('../str/substitute');
19 | var $fixTo = require('../num/fixTo');
20 |
21 | var rLimit = function(num, w){
22 | var str = $fixTo(num, w);
23 | var delta = str.length - w;
24 | return delta > 0 ? str.substr(delta) : str;
25 | };
26 |
27 | /**
28 | 日期对象格式化输出
29 | @param {date} dobj 日期对象,或者可以被转换为日期对象的数据
30 | @param {object} spec 格式化选项
31 | @param {array} [spec.weekday='日一二三四五六'.split('')] 一周内各天对应字符,从周日算起
32 | @param {string} [spec.template='{{YYYY}}-{{MM}}-{{DD}} {{hh}}:{{mm}}'] 格式化模板
33 | @return {string} 格式化完成的字符串
34 | **/
35 | module.exports = function(dobj, spec){
36 | var output = '';
37 | var data = {};
38 | var conf = $.extend({
39 | weekday : '日一二三四五六'.split(''),
40 | template : '{{YYYY}}-{{MM}}-{{DD}} {{hh}}:{{mm}}'
41 | }, spec);
42 |
43 | dobj = new Date(dobj);
44 | data.year = dobj.getFullYear();
45 | data.month = dobj.getMonth() + 1;
46 | data.date = dobj.getDate();
47 | data.day = dobj.getDay();
48 | data.hours = dobj.getHours();
49 | data.miniutes = dobj.getMinutes();
50 | data.seconds = dobj.getSeconds();
51 |
52 | data.YYYY = rLimit(data.year, 4);
53 | data.YY = rLimit(data.year, 2);
54 | data.Y = data.year;
55 |
56 | data.MM = $fixTo(data.month, 2);
57 | data.M = data.month;
58 |
59 | data.DD = $fixTo(data.date, 2);
60 | data.D = data.date;
61 |
62 | data.d = conf.weekday[data.day];
63 |
64 | data.hh = $fixTo(data.hours, 2);
65 | data.h = data.hours;
66 |
67 | data.mm = $fixTo(data.miniutes, 2);
68 | data.m = data.miniutes;
69 |
70 | data.ss = $fixTo(data.seconds, 2);
71 | data.s = data.seconds;
72 |
73 | output = $substitute(conf.template, data);
74 | return output;
75 | };
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/date/format.js:
--------------------------------------------------------------------------------
1 | /**
2 | @module lib/kit/date/format
3 | @example
4 | var $dateFormat = require('lib/kit/date/format');
5 | console.info(
6 | $dateFormat(
7 | new Date(),
8 | {
9 | weekday : '日一二三四五六'.split(''),
10 | template : '{{YYYY}}年{{MM}}月{{DD}}日 周{{d}} {{hh}}时{{mm}}分{{ss}}秒'
11 | }
12 | )
13 | );
14 | //2015年09月09日 周三 14时19分42秒
15 | **/
16 |
17 | var $ = require('../../../lib');
18 | var $substitute = require('../str/substitute');
19 | var $fixTo = require('../num/fixTo');
20 |
21 | var rLimit = function(num, w){
22 | var str = $fixTo(num, w);
23 | var delta = str.length - w;
24 | return delta > 0 ? str.substr(delta) : str;
25 | };
26 |
27 | /**
28 | 日期对象格式化输出
29 | @param {date} dobj 日期对象,或者可以被转换为日期对象的数据
30 | @param {object} spec 格式化选项
31 | @param {array} [spec.weekday='日一二三四五六'.split('')] 一周内各天对应字符,从周日算起
32 | @param {string} [spec.template='{{YYYY}}-{{MM}}-{{DD}} {{hh}}:{{mm}}'] 格式化模板
33 | @return {string} 格式化完成的字符串
34 | **/
35 | module.exports = function(dobj, spec){
36 | var output = '';
37 | var data = {};
38 | var conf = $.extend({
39 | weekday : '日一二三四五六'.split(''),
40 | template : '{{YYYY}}-{{MM}}-{{DD}} {{hh}}:{{mm}}'
41 | }, spec);
42 |
43 | dobj = new Date(dobj);
44 | data.year = dobj.getFullYear();
45 | data.month = dobj.getMonth() + 1;
46 | data.date = dobj.getDate();
47 | data.day = dobj.getDay();
48 | data.hours = dobj.getHours();
49 | data.miniutes = dobj.getMinutes();
50 | data.seconds = dobj.getSeconds();
51 |
52 | data.YYYY = rLimit(data.year, 4);
53 | data.YY = rLimit(data.year, 2);
54 | data.Y = data.year;
55 |
56 | data.MM = $fixTo(data.month, 2);
57 | data.M = data.month;
58 |
59 | data.DD = $fixTo(data.date, 2);
60 | data.D = data.date;
61 |
62 | data.d = conf.weekday[data.day];
63 |
64 | data.hh = $fixTo(data.hours, 2);
65 | data.h = data.hours;
66 |
67 | data.mm = $fixTo(data.miniutes, 2);
68 | data.m = data.miniutes;
69 |
70 | data.ss = $fixTo(data.seconds, 2);
71 | data.s = data.seconds;
72 |
73 | output = $substitute(conf.template, data);
74 | return output;
75 | };
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/lib/kit/util/cookie.js:
--------------------------------------------------------------------------------
1 | var $ = require('../../../lib');
2 |
3 | /**
4 | 设置、获取cookie
5 | @exports lib/kit/util/cookie
6 | **/
7 | var Cookie = {
8 | /**
9 | 将数据保存到cookie
10 | @param {string} sKey cookie名称
11 | @param {string} sValue 要存储的值
12 |
13 | @param {object} [oOpts] 存储选项
14 | @param {string} oOpts.expire 过期时间(小时)
15 | @param {string} [oOpts.path='/'] 路径
16 | @param {string} [oOpts.domain] 域名
17 | @param {boolean} [oOpts.secure=false] 是否为安全连接
18 | @param {boolean} [oOpts.encode=true] 存储的数据是否自动用escape编码
19 | **/
20 | set: function(sKey, sValue, oOpts){
21 | var arr = [];
22 | var d, t;
23 | var cfg = $.extend({
24 | 'expire': null,
25 | 'path': '/',
26 | 'domain': null,
27 | 'secure': false,
28 | 'encode': true
29 | }, oOpts);
30 |
31 | if (cfg.encode === true) {
32 | sValue = window.escape(sValue);
33 | }
34 | arr.push(sKey + '=' + sValue);
35 |
36 | if (cfg.path !== null) {
37 | arr.push('path=' + cfg.path);
38 | }
39 | if (cfg.domain !== null) {
40 | arr.push('domain=' + cfg.domain);
41 | }
42 | if (cfg.secure) {
43 | arr.push('secure');
44 | }
45 | if (cfg.expire !== null) {
46 | d = new Date();
47 | t = d.getTime() + cfg.expire * 3600000;
48 | d.setTime(t);
49 | arr.push('expires=' + d.toGMTString());
50 | }
51 | document.cookie = arr.join(';');
52 | },
53 | /**
54 | 获取cookie中存储的数据
55 | @param {string} sKey cookie名称
56 | @return {string} 存储的数据
57 | **/
58 | get: function(sKey){
59 | var cookies = document.cookie.split(/\s*;\s*/);
60 | var cobj = {};
61 | cookies.forEach(function(pair){
62 | var arr = pair.split(/=/);
63 | cobj[arr[0]] = arr[1];
64 | });
65 | return cobj[sKey];
66 | },
67 | /**
68 | 移除cookie中存储的数据
69 | @param {string} sKey cookie名称
70 | @param {object} [oOpts] 同时需要设置的选项
71 | **/
72 | remove: function(sKey, oOpts){
73 | oOpts = oOpts || {};
74 | oOpts.expire = -10;
75 | this.set(sKey, '', oOpts);
76 | }
77 | };
78 |
79 | module.exports = Cookie;
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/ui/overlay.js:
--------------------------------------------------------------------------------
1 | /**
2 | 基本覆盖物
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $model = require('../../lib/mvc/model');
7 | var $view = require('../../lib/mvc/view');
8 |
9 | var Overlay = $view.extend({
10 | defaults : {
11 | template : '',
12 | parent : null,
13 | styles : {
14 | 'z-index' : 1,
15 | 'display' : 'none',
16 | 'position' : 'absolute'
17 | }
18 | },
19 | build : function(){
20 | this.model = new $model();
21 | this.setStyles(this.conf.styles);
22 | },
23 | setStyles : function(styles){
24 | styles = styles || {};
25 | this.role('root').css(styles);
26 | },
27 | setParent : function(){
28 | var conf = this.conf;
29 | var root = this.role('root');
30 | var curParent = root.get(0).parentNode;
31 | var parent = null;
32 | if(conf.parent){
33 | parent = $(conf.parent).get(0);
34 | }else{
35 | parent = document.body;
36 | }
37 | if(parent !== curParent){
38 | root.appendTo(parent);
39 | //切换 parentNode 后,第一次定位计算会出错,执行2遍可得正确结果
40 | //在 update 函数中还有一次 setPosition
41 | this.setPosition();
42 | }
43 | },
44 | setPosition : $.noop,
45 | setEvents : function(action){
46 | this.model[action]('change:visible', this.proxy('checkVisible'));
47 | },
48 | preventDefault : function(evt){
49 | if(evt && evt.preventDefault){
50 | evt.preventDefault();
51 | }
52 | },
53 | update : function(){
54 | this.setParent();
55 | this.setStyles();
56 | this.setPosition();
57 | },
58 | checkVisible : function(){
59 | var root = this.role('root');
60 | if(this.model.get('visible')){
61 | root.css('display', 'block');
62 | this.trigger('show');
63 | }else{
64 | root.css('display', 'none');
65 | this.trigger('hide');
66 | }
67 | },
68 | toggle : function(){
69 | if(this.model.get('visible')){
70 | this.hide();
71 | }else{
72 | this.show();
73 | }
74 | },
75 | show : function(){
76 | this.model.set('visible', true);
77 | this.update();
78 | },
79 | hide : function(){
80 | this.model.set('visible', false);
81 | },
82 | destroy : function(){
83 | this.role('root').remove();
84 | this.supr();
85 | }
86 | });
87 |
88 | module.exports = Overlay;
89 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/ui/overlay.js:
--------------------------------------------------------------------------------
1 | /**
2 | 基本覆盖物
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $model = require('../../lib/mvc/model');
7 | var $view = require('../../lib/mvc/view');
8 |
9 | var Overlay = $view.extend({
10 | defaults : {
11 | template : '',
12 | parent : null,
13 | styles : {
14 | 'z-index' : 1,
15 | 'display' : 'none',
16 | 'position' : 'absolute'
17 | }
18 | },
19 | build : function(){
20 | this.model = new $model();
21 | this.setStyles(this.conf.styles);
22 | },
23 | setStyles : function(styles){
24 | styles = styles || {};
25 | this.role('root').css(styles);
26 | },
27 | setParent : function(){
28 | var conf = this.conf;
29 | var root = this.role('root');
30 | var curParent = root.get(0).parentNode;
31 | var parent = null;
32 | if(conf.parent){
33 | parent = $(conf.parent).get(0);
34 | }else{
35 | parent = document.body;
36 | }
37 | if(parent !== curParent){
38 | root.appendTo(parent);
39 | //切换 parentNode 后,第一次定位计算会出错,执行2遍可得正确结果
40 | //在 update 函数中还有一次 setPosition
41 | this.setPosition();
42 | }
43 | },
44 | setPosition : $.noop,
45 | setEvents : function(action){
46 | this.model[action]('change:visible', this.proxy('checkVisible'));
47 | },
48 | preventDefault : function(evt){
49 | if(evt && evt.preventDefault){
50 | evt.preventDefault();
51 | }
52 | },
53 | update : function(){
54 | this.setParent();
55 | this.setStyles();
56 | this.setPosition();
57 | },
58 | checkVisible : function(){
59 | var root = this.role('root');
60 | if(this.model.get('visible')){
61 | root.css('display', 'block');
62 | this.trigger('show');
63 | }else{
64 | root.css('display', 'none');
65 | this.trigger('hide');
66 | }
67 | },
68 | toggle : function(){
69 | if(this.model.get('visible')){
70 | this.hide();
71 | }else{
72 | this.show();
73 | }
74 | },
75 | show : function(){
76 | this.model.set('visible', true);
77 | this.update();
78 | },
79 | hide : function(){
80 | this.model.set('visible', false);
81 | },
82 | destroy : function(){
83 | this.role('root').remove();
84 | this.supr();
85 | }
86 | });
87 |
88 | module.exports = Overlay;
89 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/ui/tip.js:
--------------------------------------------------------------------------------
1 | /**
2 | 简单提示信息
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $position = require('../../lib/more/position');
7 | var $overlay = require('./overlay');
8 |
9 | var Tip = $overlay.extend({
10 | defaults : {
11 | template : '',
12 | target : 'screen',
13 | parent : null,
14 | visiblePos : 0,
15 | styles : {
16 | 'display' : 'none',
17 | 'position' : 'fixed',
18 | 'z-index' : 10000,
19 | 'padding' : '0.1rem',
20 | 'overflow' : 'hidden',
21 | 'background' : 'rgb(0,0,0)',
22 | 'background-color' : 'rgba(0,0,0,0.7)',
23 | 'border-radius' : '0.05rem',
24 | 'min-height' : '0.18rem',
25 | 'font-size' : '0.16rem',
26 | 'color' : '#fff'
27 | }
28 | },
29 | getTarget : function(){
30 | var conf = this.conf;
31 | if(conf.target === 'screen'){
32 | return $(window);
33 | }else{
34 | return $(conf.target);
35 | }
36 | },
37 | setStyles : function(styles){
38 | var conf = this.conf;
39 | styles = styles || {};
40 | if(conf.target === 'screen'){
41 | styles.position = 'fixed';
42 | }else{
43 | styles.position = 'absolute';
44 | }
45 | this.role('root').css(styles);
46 | },
47 | //tip浮层一般显示在容器底部
48 | setPosition : function(){
49 | var conf = this.conf;
50 | var target = this.getTarget();
51 | this.visiblePos = this.role('root').height() + 20;
52 | $position.pin({
53 | element : this.role('root'),
54 | x : '50%',
55 | y : '50%'
56 | }, {
57 | element : conf.target === 'screen' ? $position.VIEWPORT : target,
58 | x : '50%',
59 | y : '100% + ' + 20 + 'px'
60 | });
61 | },
62 | checkVisible : function(){
63 | var self = this;
64 | var conf = this.conf;
65 | var model = self.model;
66 | var root = self.role('root');
67 | if(model.get('visible')){
68 | if(root.css('display') === 'none'){
69 | root.show();
70 | }
71 | this.trigger('show');
72 | setTimeout(function(){
73 | var visiblePos = conf.visiblePos || self.visiblePos || 100;
74 | visiblePos = visiblePos / 100;
75 | if(model.get('visible')){
76 | root.transit({
77 | 'translateY' : 0 - visiblePos + 'rem'
78 | }, 300, 'ease-out');
79 | }
80 | });
81 | }else{
82 | root.transit({
83 | 'translateY' : 0
84 | }, 300, 'ease-in', function(){
85 | if(!model.get('visible')){
86 | root.hide();
87 | }
88 | });
89 | this.trigger('hide');
90 | }
91 | }
92 | });
93 |
94 | module.exports = Tip;
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/ui/tip.js:
--------------------------------------------------------------------------------
1 | /**
2 | 简单提示信息
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $position = require('../../lib/more/position');
7 | var $overlay = require('./overlay');
8 |
9 | var Tip = $overlay.extend({
10 | defaults : {
11 | template : '',
12 | target : 'screen',
13 | parent : null,
14 | visiblePos : 0,
15 | styles : {
16 | 'display' : 'none',
17 | 'position' : 'fixed',
18 | 'z-index' : 10000,
19 | 'padding' : '0.1rem',
20 | 'overflow' : 'hidden',
21 | 'background' : 'rgb(0,0,0)',
22 | 'background-color' : 'rgba(0,0,0,0.7)',
23 | 'border-radius' : '0.05rem',
24 | 'min-height' : '0.18rem',
25 | 'font-size' : '0.16rem',
26 | 'color' : '#fff'
27 | }
28 | },
29 | getTarget : function(){
30 | var conf = this.conf;
31 | if(conf.target === 'screen'){
32 | return $(window);
33 | }else{
34 | return $(conf.target);
35 | }
36 | },
37 | setStyles : function(styles){
38 | var conf = this.conf;
39 | styles = styles || {};
40 | if(conf.target === 'screen'){
41 | styles.position = 'fixed';
42 | }else{
43 | styles.position = 'absolute';
44 | }
45 | this.role('root').css(styles);
46 | },
47 | //tip浮层一般显示在容器底部
48 | setPosition : function(){
49 | var conf = this.conf;
50 | var target = this.getTarget();
51 | this.visiblePos = this.role('root').height() + 20;
52 | $position.pin({
53 | element : this.role('root'),
54 | x : '50%',
55 | y : '50%'
56 | }, {
57 | element : conf.target === 'screen' ? $position.VIEWPORT : target,
58 | x : '50%',
59 | y : '100% + ' + 20 + 'px'
60 | });
61 | },
62 | checkVisible : function(){
63 | var self = this;
64 | var conf = this.conf;
65 | var model = self.model;
66 | var root = self.role('root');
67 | if(model.get('visible')){
68 | if(root.css('display') === 'none'){
69 | root.show();
70 | }
71 | this.trigger('show');
72 | setTimeout(function(){
73 | var visiblePos = conf.visiblePos || self.visiblePos || 100;
74 | visiblePos = visiblePos / 100;
75 | if(model.get('visible')){
76 | root.transit({
77 | 'translateY' : 0 - visiblePos + 'rem'
78 | }, 300, 'ease-out');
79 | }
80 | });
81 | }else{
82 | root.transit({
83 | 'translateY' : 0
84 | }, 300, 'ease-in', function(){
85 | if(!model.get('visible')){
86 | root.hide();
87 | }
88 | });
89 | this.trigger('hide');
90 | }
91 | }
92 | });
93 |
94 | module.exports = Tip;
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/model/paging.js:
--------------------------------------------------------------------------------
1 | /**
2 | 分页模型
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $model = require('../../lib/mvc/model');
7 |
8 | var convert = function(def){
9 | return function(num){
10 | return parseInt(num, 10) || def;
11 | };
12 | };
13 |
14 | var Paging = $model.extend({
15 | defaults : {
16 | //页码列表中页码的数量
17 | listSize : 5,
18 | //页码最小为1
19 | current : 1,
20 | //总数量
21 | total : 1,
22 | //分页数量
23 | size : 1,
24 | //第一页页码
25 | first : 1,
26 | //最后一页页码
27 | last : 1,
28 | //上一页页码
29 | prev : null,
30 | //下一页页码
31 | next : null,
32 | //中间页码列表
33 | list : []
34 | },
35 | events : {
36 | 'change:listSize' : 'compute',
37 | 'change:current' : 'compute',
38 | 'change:total' : 'compute',
39 | 'change:size' : 'compute'
40 | },
41 | processors : {
42 | total : {
43 | set : convert(1)
44 | },
45 | size : {
46 | set : convert(1)
47 | },
48 | current : {
49 | set : convert(1)
50 | },
51 | listSize : {
52 | set : convert(0)
53 | }
54 | },
55 | compute : function(){
56 | var total = this.get('total');
57 | var size = this.get('size');
58 | var current = this.get('current');
59 |
60 | var first = 1;
61 | var last = Math.ceil(total / size);
62 |
63 | current = Math.min(Math.max(1, current), last);
64 |
65 | var prev = current - 1;
66 | if(prev <= 0){
67 | prev = null;
68 | }
69 |
70 | var next = current + 1;
71 | if(next > last){
72 | next = null;
73 | }
74 |
75 | var listSize = this.get('listSize');
76 | var pages = (function(){
77 | var list = [];
78 | var step = 0;
79 | var item = current;
80 | var delta = 0;
81 |
82 | for(step = 0; step < last * 2; step++){
83 | delta = Math.ceil(step / 2);
84 | delta = (step % 2 === 0) ? 0 - delta : delta;
85 | item = current + delta;
86 | if(item > 0 && item <= last){
87 | if(delta >= 0){
88 | list.push(item);
89 | }else{
90 | list.unshift(item);
91 | }
92 | if(list.length >= listSize){
93 | break;
94 | }
95 | }
96 | }
97 |
98 | return list;
99 | })();
100 |
101 | this.set({
102 | total : total,
103 | size : size,
104 | current : current,
105 | first : first,
106 | last : last,
107 | prev : prev,
108 | next : next,
109 | list : pages
110 | });
111 |
112 | this.trigger('compute');
113 | }
114 | });
115 |
116 | module.exports = Paging;
117 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/model/paging.js:
--------------------------------------------------------------------------------
1 | /**
2 | 分页模型
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $model = require('../../lib/mvc/model');
7 |
8 | var convert = function(def){
9 | return function(num){
10 | return parseInt(num, 10) || def;
11 | };
12 | };
13 |
14 | var Paging = $model.extend({
15 | defaults : {
16 | //页码列表中页码的数量
17 | listSize : 5,
18 | //页码最小为1
19 | current : 1,
20 | //总数量
21 | total : 1,
22 | //分页数量
23 | size : 1,
24 | //第一页页码
25 | first : 1,
26 | //最后一页页码
27 | last : 1,
28 | //上一页页码
29 | prev : null,
30 | //下一页页码
31 | next : null,
32 | //中间页码列表
33 | list : []
34 | },
35 | events : {
36 | 'change:listSize' : 'compute',
37 | 'change:current' : 'compute',
38 | 'change:total' : 'compute',
39 | 'change:size' : 'compute'
40 | },
41 | processors : {
42 | total : {
43 | set : convert(1)
44 | },
45 | size : {
46 | set : convert(1)
47 | },
48 | current : {
49 | set : convert(1)
50 | },
51 | listSize : {
52 | set : convert(0)
53 | }
54 | },
55 | compute : function(){
56 | var total = this.get('total');
57 | var size = this.get('size');
58 | var current = this.get('current');
59 |
60 | var first = 1;
61 | var last = Math.ceil(total / size);
62 |
63 | current = Math.min(Math.max(1, current), last);
64 |
65 | var prev = current - 1;
66 | if(prev <= 0){
67 | prev = null;
68 | }
69 |
70 | var next = current + 1;
71 | if(next > last){
72 | next = null;
73 | }
74 |
75 | var listSize = this.get('listSize');
76 | var pages = (function(){
77 | var list = [];
78 | var step = 0;
79 | var item = current;
80 | var delta = 0;
81 |
82 | for(step = 0; step < last * 2; step++){
83 | delta = Math.ceil(step / 2);
84 | delta = (step % 2 === 0) ? 0 - delta : delta;
85 | item = current + delta;
86 | if(item > 0 && item <= last){
87 | if(delta >= 0){
88 | list.push(item);
89 | }else{
90 | list.unshift(item);
91 | }
92 | if(list.length >= listSize){
93 | break;
94 | }
95 | }
96 | }
97 |
98 | return list;
99 | })();
100 |
101 | this.set({
102 | total : total,
103 | size : size,
104 | current : current,
105 | first : first,
106 | last : last,
107 | prev : prev,
108 | next : next,
109 | list : pages
110 | });
111 |
112 | this.trigger('compute');
113 | }
114 | });
115 |
116 | module.exports = Paging;
117 |
--------------------------------------------------------------------------------
/generators/app/templates/js/mods/view/countDown.js:
--------------------------------------------------------------------------------
1 | /**
2 | 倒计时统一UI
3 |
4 | @example
5 | var $countDown = require('mods/view/countDown');
6 | var node = $('').prependTo(document.body);
7 |
8 | var cd = new $countDown({
9 | baseTime : '2016/12/01 12:00:00',
10 | target : '2016/12/01 12:00:10',
11 | node : node
12 | });
13 |
14 | cd.reset({
15 | baseTime : '2016/12/01 11:00:00',
16 | target : '2016/12/01 12:00:10'
17 | });
18 | **/
19 |
20 | var $ = require('../../lib');
21 | var $view = require('../../lib/mvc/view');
22 | var $countDown = require('../../lib/kit/time/countDown');
23 | var $timeSplit = require('../../lib/kit/time/split.js');
24 | var $substitute = require('../../lib/kit/str/substitute');
25 | var $fixTo = require('../../lib/kit/num/fixTo');
26 |
27 | var CountDown = $view.extend({
28 | defaults : {
29 | node : null,
30 | baseTime : $CONFIG.timeStamp,
31 | target : null,
32 | maxUnit : 'day',
33 | timeTemplate : '{{day}}天{{hour}}时{{minute}}分{{second}}秒'
34 | },
35 | build : function(){
36 | this.setCD();
37 | },
38 | formatTime : function(time){
39 | if($.type(time) === 'string'){
40 | time = time.replace(/-/g, '/');
41 | }
42 | return time;
43 | },
44 | setCD : function(){
45 | var self = this;
46 | var conf = self.conf;
47 | var root = self.role('root');
48 | var target = conf.target || root.attr('data-cd-target');
49 | var proxy = self.proxy();
50 | var baseTime = this.formatTime(conf.baseTime);
51 | target = this.formatTime(target);
52 | self.cd = $countDown({
53 | target : target,
54 | base : baseTime,
55 | onChange : proxy('update'),
56 | onStop : proxy('onStop')
57 | });
58 | },
59 | update : function(delta){
60 | var conf = this.conf;
61 | delta = Math.round(delta / 1000) * 1000;
62 | delta = Math.max(0, delta);
63 |
64 | var time = $timeSplit(delta, {
65 | maxUnit : conf.maxUnit
66 | });
67 | $.each(time, function(key, val){
68 | val = $fixTo(val, 2);
69 | time[key] = val;
70 | });
71 |
72 | var html = $substitute(conf.timeTemplate, time);
73 | this.role('root').html(html);
74 | },
75 | stop : function(){
76 | this.cd.stop();
77 | },
78 | reset : function(options){
79 | this.reseting = true;
80 | this.stop();
81 | this.reseting = false;
82 | $.extend(this.conf, options);
83 | this.setCD();
84 | },
85 | onStop : function(delta){
86 | this.update(delta);
87 | if(!this.reseting){
88 | this.trigger('stop');
89 | }
90 | }
91 | });
92 |
93 | module.exports = CountDown;
94 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/mods/view/countDown.js:
--------------------------------------------------------------------------------
1 | /**
2 | 倒计时统一UI
3 |
4 | @example
5 | var $countDown = require('mods/view/countDown');
6 | var node = $('').prependTo(document.body);
7 |
8 | var cd = new $countDown({
9 | baseTime : '2016/12/01 12:00:00',
10 | target : '2016/12/01 12:00:10',
11 | node : node
12 | });
13 |
14 | cd.reset({
15 | baseTime : '2016/12/01 11:00:00',
16 | target : '2016/12/01 12:00:10'
17 | });
18 | **/
19 |
20 | var $ = require('../../lib');
21 | var $view = require('../../lib/mvc/view');
22 | var $countDown = require('../../lib/kit/time/countDown');
23 | var $timeSplit = require('../../lib/kit/time/split.js');
24 | var $substitute = require('../../lib/kit/str/substitute');
25 | var $fixTo = require('../../lib/kit/num/fixTo');
26 |
27 | var CountDown = $view.extend({
28 | defaults : {
29 | node : null,
30 | baseTime : $CONFIG.timeStamp,
31 | target : null,
32 | maxUnit : 'day',
33 | timeTemplate : '{{day}}天{{hour}}时{{minute}}分{{second}}秒'
34 | },
35 | build : function(){
36 | this.setCD();
37 | },
38 | formatTime : function(time){
39 | if($.type(time) === 'string'){
40 | time = time.replace(/-/g, '/');
41 | }
42 | return time;
43 | },
44 | setCD : function(){
45 | var self = this;
46 | var conf = self.conf;
47 | var root = self.role('root');
48 | var target = conf.target || root.attr('data-cd-target');
49 | var proxy = self.proxy();
50 | var baseTime = this.formatTime(conf.baseTime);
51 | target = this.formatTime(target);
52 | self.cd = $countDown({
53 | target : target,
54 | base : baseTime,
55 | onChange : proxy('update'),
56 | onStop : proxy('onStop')
57 | });
58 | },
59 | update : function(delta){
60 | var conf = this.conf;
61 | delta = Math.round(delta / 1000) * 1000;
62 | delta = Math.max(0, delta);
63 |
64 | var time = $timeSplit(delta, {
65 | maxUnit : conf.maxUnit
66 | });
67 | $.each(time, function(key, val){
68 | val = $fixTo(val, 2);
69 | time[key] = val;
70 | });
71 |
72 | var html = $substitute(conf.timeTemplate, time);
73 | this.role('root').html(html);
74 | },
75 | stop : function(){
76 | this.cd.stop();
77 | },
78 | reset : function(options){
79 | this.reseting = true;
80 | this.stop();
81 | this.reseting = false;
82 | $.extend(this.conf, options);
83 | this.setCD();
84 | },
85 | onStop : function(delta){
86 | this.update(delta);
87 | if(!this.reseting){
88 | this.trigger('stop');
89 | }
90 | }
91 | });
92 |
93 | module.exports = CountDown;
94 |
--------------------------------------------------------------------------------
/generators/app/templates/js/mods/model/auctionInfo.js:
--------------------------------------------------------------------------------
1 | var $ = require('../../lib');
2 | var $model = require('../../lib/mvc/model');
3 | var $transApp = require('../trans/app');
4 | var $numerical = require('../../lib/kit/num/numerical');
5 |
6 | var STATUS = {
7 | before : 0,
8 | ongoing : 1,
9 | over : 2
10 | };
11 |
12 | //下面这些属性在设置时会自动转换为数字
13 | var numProps = {
14 | //最低加价
15 | minIncPrice : 0,
16 | //最高加价
17 | maxIncPrice : 0,
18 | //封顶价格
19 | ceilPrice : 0,
20 | //当前价格
21 | curPrice : 0,
22 | //活动状态
23 | actStatus : 0
24 | };
25 |
26 | var processors = {};
27 | $.each(numProps, function(key){
28 | processors[key] = {
29 | set : $numerical
30 | };
31 | });
32 |
33 | var AuctionInfo = $model.extend({
34 | defaults : $.extend({
35 | actId : '',
36 | info : null
37 | }, numProps),
38 | processors : $.extend({}, processors),
39 | events : {
40 | 'change:actStatus' : 'checkStatus',
41 | 'change:info' : 'checkUpdate'
42 | },
43 | build : function(){
44 | this.checkStatus();
45 | },
46 | checkStatus : function(){
47 | var actStatus = this.get('actStatus');
48 | //仅在竞拍中
49 | if(actStatus === STATUS.ongoing){
50 | this.startPolling();
51 | }else{
52 | this.stopPolling();
53 | }
54 | },
55 | startPolling : function(){
56 | var actId = this.get('actId');
57 | if(actId){
58 | this.requestInfo();
59 | this.timer = setInterval(this.proxy('requestInfo'), 5000);
60 | }
61 | },
62 | stopPolling : function(){
63 | clearInterval(this.timer);
64 | },
65 | checkUpdate : function(){
66 | var info = this.get('info');
67 | if(!info){return;}
68 | this.set('curPrice', info.cur_price);
69 | this.set('ceilPrice', info.ceil_price);
70 | },
71 | requestInfo : function(){
72 | var self = this;
73 | var curPrice = this.get('curPrice');
74 | var curStatus = this.get('actStatus');
75 | $transApp.request('actInfo', {
76 | data : {
77 | act_id : self.get('actId'),
78 | size : 20
79 | },
80 | onSuccess : function(rs){
81 | if(rs.ret !== 0){return;}
82 | if((curPrice !== rs.data.cur_price) || (curStatus !== rs.data.act_status)) {
83 | self.updateInfo(rs.data);
84 | }
85 | }
86 | });
87 | },
88 | //供其他组件调用
89 | updateInfo : function(info){
90 | this.set('info', info);
91 | }
92 | });
93 |
94 | var models = {};
95 | module.exports = function(actId){
96 | var obj = models[actId];
97 | if(!obj){
98 | obj = new AuctionInfo({
99 | actId : actId
100 | });
101 | models[actId] = obj;
102 | }
103 | return obj;
104 | };
105 |
--------------------------------------------------------------------------------
/generators/app/templates/webpack.config.js:
--------------------------------------------------------------------------------
1 | var $webpack = require('webpack');
2 | var $path = require('path');
3 | var $fs = require('fs');
4 |
5 | var CommonsChunkPlugin = $webpack.optimize.CommonsChunkPlugin;
6 |
7 | var entries = {};
8 | var includes = [];
9 |
10 | (function() {
11 |
12 | var isFile = function(path){
13 | return $fs.existsSync(path) && $fs.statSync(path).isFile();
14 | };
15 |
16 | var isDir = function(path){
17 | return $fs.existsSync(path) && $fs.statSync(path).isDirectory();
18 | };
19 |
20 | var walkSync = function(dirPath){
21 | var dirs = [];
22 | var output = [];
23 | dirs.push(dirPath);
24 |
25 | var walk = function(path){
26 | var files = $fs.readdirSync(path);
27 | files.forEach(function(file){
28 | var filePath = $path.resolve(path, file);
29 | if(isDir(filePath)){
30 | dirs.push(filePath);
31 | }else if(isFile(filePath)){
32 | output.push(filePath);
33 | }
34 | });
35 | };
36 |
37 | while(dirs.length){
38 | walk(dirs.pop());
39 | }
40 |
41 | return output;
42 | };
43 |
44 | var targetPath = $path.resolve(__dirname, './src/js/entry/');
45 | var files = walkSync(targetPath);
46 |
47 | var getEntryKey = function(path){
48 | var extname = $path.extname(path);
49 | var key = $path.relative(targetPath, path);
50 | key = key.replace(new RegExp(extname + '$'), '');
51 | key = key.replace(/\\+/g, '/');
52 | return key;
53 | };
54 |
55 | var getEntryVal = function(path){
56 | var extname = $path.extname(path);
57 | var val = $path.relative(__dirname, path);
58 | val = val.replace(new RegExp(extname + '$'), '');
59 | val = val.replace(/\\+/g, '/');
60 | return './' + val;
61 | };
62 |
63 | var getEntryType = function(path){
64 | var key = getEntryKey(path);
65 | var arr = key.split(/[\/\\]/);
66 | if(arr.length > 1){
67 | return arr[0];
68 | }else{
69 | return '';
70 | }
71 | };
72 |
73 | var includesTypes = ['module', 'page'];
74 | files.forEach(function(path){
75 | var key = getEntryKey(path);
76 | var val = getEntryVal(path);
77 | var type = getEntryType(path);
78 | if(!type){return;}
79 | if(includesTypes.indexOf(type) >= 0){
80 | includes.push(key);
81 | }
82 | entries[key] = val;
83 | });
84 |
85 | })();
86 |
87 | module.exports = {
88 | entry: entries,
89 | output: {
90 | filename: '[name].js'
91 | },
92 | devtool: 'source-map',
93 | module: {
94 | loaders: [{
95 | test: /\.tpl$/,
96 | loader: 'html'
97 | }]
98 | },
99 | plugins: [
100 | new CommonsChunkPlugin('global.js', includes)
101 | ]
102 | };
103 |
104 |
--------------------------------------------------------------------------------
/generators/app/templates/js/mods/layer/autoCloseTip.js:
--------------------------------------------------------------------------------
1 | /**
2 | 自动关闭的提示信息浮层
3 |
4 | @param {string} content 信息内容,为字符串或者HTML
5 | @param {object} options 选项
6 | @param {string} [options.title='提示'] 标题栏显示文字
7 | @param {string} [options.icon='right'] 浮层提示图标
8 | @param {number} [options.autoClose=1000] 自动关闭时间,单位为ms
9 | @param {function} [options.cancel=$.noop] 浮层隐藏的回调函数
10 |
11 | @example
12 |
13 | var $autoCloseTip = require('mods/layer/autoCloseTip');
14 |
15 | $autoCloseTip('恭喜您,出价成功
', {
16 | icon : 'right',
17 | cancel : function(){
18 | console.info('提示信息浮层隐藏了');
19 | }
20 | });
21 |
22 | $autoCloseTip([
23 | '很抱歉,出价失败
',
24 | '出价不能低于当前价(¥32200)
'
25 | ].join(''), {
26 | icon : 'error',
27 | cancel : function(){
28 | console.info('提示信息浮层隐藏了');
29 | }
30 | });
31 |
32 | **/
33 |
34 | var $ = require('../../lib');
35 | var $reuse = require('../../comp/ui/reuseDialog');
36 | var $tplAutoCloseTip = require('../tpl/autoCloseTip.tpl');
37 | var $countDown = require('../../lib/kit/time/countDown');
38 |
39 | var cache = $reuse({
40 | template : $tplAutoCloseTip,
41 | target : 'screen',
42 | parent : null,
43 | mask : true,
44 | styles : {
45 | 'z-index' : 10000,
46 | 'position' : 'absolute',
47 | 'display' : 'none'
48 | }
49 | });
50 |
51 | var ICONS = {
52 | 'error' : 'error',
53 | 'right' : 'right'
54 | };
55 |
56 | module.exports = function(content, options){
57 | if(!options && $.isPlainObject(content)){
58 | options = content;
59 | }else{
60 | options = options || {};
61 | options.content = content;
62 | }
63 |
64 | var conf = $.extend({
65 | title : '提示',
66 | icon : 'right',
67 | autoClose : 2000,
68 | cancel : $.noop
69 | }, options);
70 |
71 | var dialog = cache.get();
72 | dialog.role('title').html(conf.title);
73 | dialog.role('content').html(conf.content);
74 |
75 | var delay = parseInt(conf.autoClose / 1000, 10) || 0;
76 | dialog.role('delay').html(delay);
77 |
78 | var cd = null;
79 |
80 | if(conf.autoClose){
81 | cd = $countDown({
82 | target : Date.now() + conf.autoClose,
83 | onChange : function(delta){
84 | var second = Math.round(delta / 1000);
85 | dialog.role('delay').html(second);
86 | },
87 | onStop : function(){
88 | dialog.hide();
89 | }
90 | });
91 | }
92 |
93 | var icon = ICONS[conf.icon] || 'right';
94 | dialog.role('box').attr('class', 'bd ' + icon);
95 |
96 | dialog.on('hide', function(){
97 | if(cd && cd.stop){
98 | cd.stop();
99 | }
100 | });
101 |
102 | dialog.on('cancel', conf.cancel);
103 |
104 | //重用对话框时,清除了对话框自动绑定的自定义事件
105 | //所以这里需要重新绑定一次
106 | dialog.on('cancel', function(){
107 | dialog.hide();
108 | });
109 |
110 | dialog.show();
111 | };
112 |
--------------------------------------------------------------------------------
/generators/app/templates/js/comp/ui/mask.js:
--------------------------------------------------------------------------------
1 | /**
2 | 遮罩
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $position = require('../../lib/more/position');
7 | var $overlay = require('./overlay');
8 |
9 | var Mask = $overlay.extend({
10 | defaults : {
11 | template : '',
12 | target : 'screen',
13 | parent : null,
14 | bgColor : 'rgba(0,0,0,0.5)',
15 | fxInterval : 300,
16 | styles : {
17 | 'z-index' : 10,
18 | 'position' : 'absolute',
19 | 'background-color' : 'rgba(0,0,0,0)',
20 | 'display' : 'none'
21 | }
22 | },
23 | events : {
24 | 'touchstart' : 'preventDefault',
25 | 'touchmove' : 'preventDefault'
26 | },
27 | setEvents : function(action){
28 | this.supr(action);
29 | $(window)[action]('resize', this.proxy('onResize'));
30 | },
31 | preventDefault : function(evt){
32 | evt.preventDefault();
33 | },
34 | setStyles : function(styles){
35 | var conf = this.conf;
36 | styles = styles || {};
37 |
38 | if(conf.target === 'screen'){
39 | styles.position = 'fixed';
40 | styles.width = '100%';
41 | styles.height = '100%';
42 | }else{
43 | var target = this.getTarget();
44 | styles.position = 'absolute';
45 | styles.width = target.width() + 'px';
46 | styles.height = target.height() + 'px';
47 | }
48 | this.role('root').css(styles);
49 | },
50 | getTarget : function(){
51 | var conf = this.conf;
52 | if(conf.target === 'screen'){
53 | return $(window);
54 | }else{
55 | return $(conf.target);
56 | }
57 | },
58 | setPosition : function(){
59 | var conf = this.conf;
60 | var target = this.getTarget();
61 | $position.pin({
62 | element : this.role('root'),
63 | x : '0%',
64 | y : '0%'
65 | }, {
66 | element : conf.target === 'screen' ? $position.VIEWPORT : target,
67 | x : '0%',
68 | y : '0%'
69 | });
70 | },
71 | checkVisible : function(){
72 | var self = this;
73 | var conf = this.conf;
74 | var model = self.model;
75 | var root = self.role('root');
76 | var bgColor = conf.bgColor || 'rgba(0,0,0,0.5)';
77 | if(model.get('visible')){
78 | if(root.css('display') === 'none'){
79 | root.show();
80 | }
81 | this.trigger('show');
82 | setTimeout(function(){
83 | if(model.get('visible')){
84 | root.transit({
85 | 'background-color' : bgColor
86 | }, conf.fxInterval, 'ease-out');
87 | }
88 | });
89 | }else{
90 | root.transit({
91 | 'background-color' : 'rgba(0,0,0,0)'
92 | }, conf.fxInterval, 'ease-in', function(){
93 | if(!model.get('visible')){
94 | root.hide();
95 | }
96 | });
97 | this.trigger('hide');
98 | }
99 | },
100 | onResize : function(){
101 | this.update();
102 | }
103 | });
104 |
105 | module.exports = Mask;
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/generators/app/templates/src/js/comp/ui/mask.js:
--------------------------------------------------------------------------------
1 | /**
2 | 遮罩
3 | **/
4 |
5 | var $ = require('../../lib');
6 | var $position = require('../../lib/more/position');
7 | var $overlay = require('./overlay');
8 |
9 | var Mask = $overlay.extend({
10 | defaults : {
11 | template : '',
12 | target : 'screen',
13 | parent : null,
14 | bgColor : 'rgba(0,0,0,0.5)',
15 | fxInterval : 300,
16 | styles : {
17 | 'z-index' : 10,
18 | 'position' : 'absolute',
19 | 'background-color' : 'rgba(0,0,0,0)',
20 | 'display' : 'none'
21 | }
22 | },
23 | events : {
24 | 'touchstart' : 'preventDefault',
25 | 'touchmove' : 'preventDefault'
26 | },
27 | setEvents : function(action){
28 | this.supr(action);
29 | $(window)[action]('resize', this.proxy('onResize'));
30 | },
31 | preventDefault : function(evt){
32 | evt.preventDefault();
33 | },
34 | setStyles : function(styles){
35 | var conf = this.conf;
36 | styles = styles || {};
37 |
38 | if(conf.target === 'screen'){
39 | styles.position = 'fixed';
40 | styles.width = '100%';
41 | styles.height = '100%';
42 | }else{
43 | var target = this.getTarget();
44 | styles.position = 'absolute';
45 | styles.width = target.width() + 'px';
46 | styles.height = target.height() + 'px';
47 | }
48 | this.role('root').css(styles);
49 | },
50 | getTarget : function(){
51 | var conf = this.conf;
52 | if(conf.target === 'screen'){
53 | return $(window);
54 | }else{
55 | return $(conf.target);
56 | }
57 | },
58 | setPosition : function(){
59 | var conf = this.conf;
60 | var target = this.getTarget();
61 | $position.pin({
62 | element : this.role('root'),
63 | x : '0%',
64 | y : '0%'
65 | }, {
66 | element : conf.target === 'screen' ? $position.VIEWPORT : target,
67 | x : '0%',
68 | y : '0%'
69 | });
70 | },
71 | checkVisible : function(){
72 | var self = this;
73 | var conf = this.conf;
74 | var model = self.model;
75 | var root = self.role('root');
76 | var bgColor = conf.bgColor || 'rgba(0,0,0,0.5)';
77 | if(model.get('visible')){
78 | if(root.css('display') === 'none'){
79 | root.show();
80 | }
81 | this.trigger('show');
82 | setTimeout(function(){
83 | if(model.get('visible')){
84 | root.transit({
85 | 'background-color' : bgColor
86 | }, conf.fxInterval, 'ease-out');
87 | }
88 | });
89 | }else{
90 | root.transit({
91 | 'background-color' : 'rgba(0,0,0,0)'
92 | }, conf.fxInterval, 'ease-in', function(){
93 | if(!model.get('visible')){
94 | root.hide();
95 | }
96 | });
97 | this.trigger('hide');
98 | }
99 | },
100 | onResize : function(){
101 | this.update();
102 | }
103 | });
104 |
105 | module.exports = Mask;
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/generators/app/templates/js/mods/view/auctionState.js:
--------------------------------------------------------------------------------
1 | /**
2 | 订单状态监视
3 | **/
4 | var $ = require('../../lib');
5 | var $view = require('../../lib/mvc/view');
6 | var $countDown = require('./countDown');
7 |
8 | //订单状态class列表
9 | var STATE = {
10 | before: 'today_start',
11 | ongoing: 'buying',
12 | over: 'time_over'
13 | };
14 |
15 | var TPL = {
16 | cdStart: ' 距开始 {{hour}} : {{minute}} : {{second}}',
17 | cdStop: ' 距结束 {{hour}} : {{minute}} : {{second}}'
18 | };
19 |
20 | var AuctionState = $view.extend({
21 | defaults: {
22 | node: null,
23 | state: STATE,
24 | maxUnit: 'hour',
25 | tplCDStart: TPL.cdStart,
26 | tplCDStop: TPL.cdStop,
27 | role: {
28 | 'cd-box': '.TimeDetails'
29 | }
30 | },
31 | build: function() {
32 | var state = this.getState();
33 | switch (state) {
34 | case 'before':
35 | this.setStartCD();
36 | break;
37 |
38 | case 'ongoing':
39 | this.setStopCD();
40 | break;
41 |
42 | case 'over':
43 | this.setOver();
44 | break;
45 | }
46 | },
47 | getState: function() {
48 | var root = this.role('root');
49 | var state = '';
50 |
51 | $.each(this.conf.state, function(key, name) {
52 | if (root.hasClass(name)) {
53 | state = key;
54 | return false;
55 | }
56 | });
57 |
58 | return state;
59 | },
60 | setState: function(state) {
61 | var conf = this.conf;
62 | var root = this.role('root');
63 | var curState = this.getState();
64 | var curClassName = conf.state[curState] || '';
65 | var nextClassName = conf.state[state] || '';
66 | root.removeClass(curClassName)
67 | .addClass(nextClassName);
68 | },
69 | setStartCD: function() {
70 | var conf = this.conf;
71 | var root = this.role('root');
72 | var timeStart = root.attr('data-time-start');
73 | this.setState('before');
74 | if (!timeStart) {
75 | return;
76 | }
77 | var cd = new $countDown({
78 | target: timeStart,
79 | maxUnit: conf.maxUnit,
80 | node: this.role('cd-box'),
81 | timeTemplate: conf.tplCDStart
82 | });
83 | cd.on('stop', this.proxy('setStopCD'));
84 | },
85 | setStopCD: function() {
86 | var conf = this.conf;
87 | var root = this.role('root');
88 | var timeStop = root.attr('data-time-stop');
89 | this.setState('ongoing');
90 | if (!timeStop) {
91 | return;
92 | }
93 | var cd = new $countDown({
94 | target: timeStop,
95 | maxUnit: conf.maxUnit,
96 | node: this.role('cd-box'),
97 | timeTemplate: conf.tplCDStop
98 | });
99 | cd.on('stop', this.proxy('setOver'));
100 | },
101 | setOver: function() {
102 | this.role('cd-box').html('');
103 | this.setState('over');
104 | }
105 | });
106 |
107 | module.exports = AuctionState;
108 |
--------------------------------------------------------------------------------