shipfi@thinkpad

AllProjects

Showing 54 changed files with 2458 additions and 0 deletions
1 +# ECMAScript 6 语法
2 +
3 +### 1.let 命令
4 +
5 +##### 代码作用域
6 +ES6新增 **let** 命令,用来声明变量,用法类似于 **var**
7 +但其声明的变量,只在let命令所在的代码块有效。
8 +
9 +```
10 +{
11 + let a = 10;
12 + var b = 1;
13 +}
14 +
15 +a // ReferenceError: a is not defined.
16 +b // 1
17 +```
18 +
19 +for循环的计数器,就很合适使用let命令。
20 +
21 +```
22 +for (let i = 0; i < arr.length; i++) {}
23 +console.log(i); //ReferenceError: i is not defined
24 +```
25 +
26 +
27 +##### 不存在变量提升
28 +
29 +let不像var那样会发生“变量提升”现象。所以,变量一定要在声明后使用,否则报错。
30 +
31 +```
32 +console.log(foo); // 输出undefined
33 +console.log(bar); // 报错ReferenceError
34 +var foo = 2;
35 +let bar = 2;
36 +```
37 +
38 +##### 不允许重复声明
39 +
40 +let不允许在相同作用域内,重复声明同一个变量。
41 +
42 +```
43 +// 报错
44 +function () {
45 + let a = 10;
46 + var a = 1;
47 +}
48 +```
49 +
50 +
51 +---
52 +
53 +### 2.const命令
54 +
55 +const 声明一个只读的常量。一旦声明,常量的值就不能改变。
56 +
57 +```
58 +'use strict';
59 +const PI = 3.1415;
60 +PI // 3.1415
61 +PI = 3; // TypeError: "PI" is read-only
62 +```
63 +
64 +---
65 +
66 +### 3.数组解构赋值
67 +
68 + [参考链接](http://es6.ruanyifeng.com/#docs/destructuring)
69 +
70 +ES6允许以下方式赋值变量
71 + `var [a, b, c] = [1, 2, 3];`
72 +
73 +##### 嵌套解构
74 +下面是一些使用嵌套数组进行解构的例子。
75 +
76 +```
77 +let [foo, [[bar], baz]] = [1, [[2], 3]];
78 +let [ , , third] = ["foo", "bar", "baz"];
79 +let [x, , y] = [1, 2, 3];
80 +x // 1
81 +y // 3
82 +let [head, ...tail] = [1, 2, 3, 4];
83 +head // 1
84 +tail // [2, 3, 4]
85 +```
86 +
87 +##### 解析缺少
88 +
89 +如果解构不成功,变量的值就等于undefined。
90 +
91 +```
92 +var [foo] = [];
93 +var [bar, foo] = [1];
94 +// 以上两种情况都属于解构不成功,foo的值都会等于undefined。
95 +```
96 +
97 +
98 +##### 不完全解析
99 +等号左边的模式,只匹配一部分的等号右边的数组。这种情况下,解构依然可以成功。
100 +
101 +```
102 +let [x, y] = [1, 2, 3];
103 +x // 1
104 +y // 2
105 +
106 +let [a, [b], d] = [1, [2, 3], 4];
107 +a // 1
108 +b // 2
109 +d // 4
110 +```
111 +
112 +---
113 +
114 +
115 +### 4. 对象的解构赋值
116 +
117 + 解构不仅可以用于数组,还可以用于对象。
118 +
119 +```
120 +var { foo, bar } = { foo: "aaa", bar: "bbb" };
121 +foo // "aaa" ; bar // "bbb"
122 +```
123 +
124 +对象的解构与数组有一个重要的不同。数组的元素是按次序排列的,变量的取值由它的位置决定;而 **对象的属性没有次序,变量必须与属性同名**,才能取到正确的值。
125 +
126 +```
127 +var { bar, foo } = { foo: "aaa", bar: "bbb" };
128 +foo // "aaa"
129 +bar // "bbb"
130 +```
131 +
132 +如果变量名与属性名不一致,必须写成下面这样。
133 +
134 +```
135 +var { foo: baz } = { foo: "aaa", bar: "bbb" };
136 +baz // "aaa"
137 +```
138 +
139 +这实际上说明, **对象的解构赋值是下面形式的简写**
140 +对象的解构赋值的内部机制,是先找到同名属性,然后再赋给对应的变量。真正被赋值的是后者,而不是前者。
141 + `var { foo: foo, bar: bar } = { foo: "aaa", bar: "bbb" };`
142 +
143 +
144 +---
145 +
146 +### 5. 字符串的解构赋值
147 +
148 +字符串也可以解构赋值。这是因为此时,字符串被转换成了一个类似数组的对象。
149 +
150 +```
151 +const [a, b, c, d, e] = 'hello';
152 +a // "h"
153 +b // "e"
154 +c // "l"
155 +d // "l"
156 +e // "o"
157 +```
1 +# NPM 使用帮助
2 +
3 +### 1.使用npm其它源
4 +
5 + 可以使用nrm工具,具体链接参考:
6 + [nrm](https://github.com/Pana/nrm)
7 +
8 +```
9 + npm install -g nrm
10 + nrm use rednpm
11 +```
12 +
13 +
14 +### 2.npm 安装库到devDependencies和dependencies
15 +devDependencies是开发时所需要用的库
16 +dependencies 是开发和运行都需要运行的库
17 +
18 +> devDependencies
19 +
20 + `npm i npm_module -D || npm install npm_module --save-dev`
21 +
22 +> dependencies
23 +
24 + `npm i npm_module -S || npm install npm_module --save`
25 +
26 +
27 +### 3. 查看npm配置
28 +
29 +`$ npm config list -l`
30 +
31 +### 4. 设置环境变量。
32 +
33 +```
34 +$ npm set init-author-name 'Your name'
35 +$ npm set init-author-email 'Your email'
36 +$ npm set init-author-url 'http://yourdomain.com'
37 +$ npm set init-license 'MIT'
38 +```
39 +
40 +### 5. 查看已安装模块
41 +
42 +> 列出当前项目安装的所有模块及全局模块
43 + `npm list | npm list --global`
...\ No newline at end of file ...\ No newline at end of file
1 +# 前端组件化的一些学习资料
2 +
3 +### 前端整体
4 +
5 +>[Vue+ES6+Jade+Scss+Webpack+Gulp 编程](https://segmentfault.com/a/1190000005115926)
6 +
7 +>[2016年后Web 开发趋势是什么](http://yafeilee.me/blogs/86)
8 +
9 +>[AlloyTeam腾讯全端Blog](http://www.alloyteam.com/)
10 +
11 +>[前端开发者手册](https://dwqs.gitbooks.io/frontenddevhandbook/content/)
12 +
13 +>[CommonJS规范](http://www.feeldesignstudio.com/2013/09/javascript-module-pattern-commonjs/)
14 +
15 +>[浅淡Javascript模块化编程](https://segmentfault.com/a/1190000000492678)
16 +
17 +---
18 +
19 +## ECMAScript6
20 +
21 +>[-- ES6初探](https://github.com/shipfi/es6features)
22 +
23 +>[-- ES6相关学习资源](https://segmentfault.com/a/1190000003739409)
24 +
25 +>[-- ECMAScript6入门-阮一峰](http://es6.ruanyifeng.com/#docs/intro)
26 +
27 +>[-- ECMAScript6入门-木头人](http://www.hubwiz.com/course/5594e91ac086935f4a6fb8ef/)
28 +
29 +>[-- ES6 in depth](https://hacks.mozilla.org/category/es6-in-depth/)
30 +
31 ++
32 +
33 +----
34 +
35 +### Webpackt篇
36 +
37 ++ 说明:
38 +
39 +>[-- Webpack Doc中文](https://github.com/liunian/webpack-doc/blob/master/SUMMARY.md)
40 +
41 +>[-- Webpack入门指南](http://www.cnblogs.com/vajoy/p/4650467.html#!/follow)
42 +
43 +>[-- Webpack入门指南2](https://segmentfault.com/a/1190000002551952)
44 +
45 +>[-- Webpack怎么用](https://segmentfault.com/a/1190000002552008)
46 +
47 +>[-- webpack中文指南](http://zhaoda.net/webpack-handbook/index.html)
48 +
49 +>[-- webpack傻瓜式指南****](https://github.com/vikingmute/webpack-for-fools)
50 +
51 +>[-- webpack loader](http://guowenfh.github.io/2016/03/24/vue-webpack-02-deploy/)
52 +
53 +>[-- webpack 使用](http://fakefish.github.io/react-webpack-cookbook/index.html)
54 +
55 +
56 ++ Webpack 套件 (可通过npm安装)
57 +
58 +>[-- 一个webpack插件,用于打包css资源文件](https://github.com/webpack/extract-text-webpack-plugin)
59 +
60 +>[-- css-loader,style-loader](https://github.com/liunian/webpack-doc/blob/master/tutorials/getting-started/index.md)
61 +
62 +```
63 +css-loader 是处理css文件中的url()等
64 +style-loader 将css插入到页面的style标签
65 +less-loader 是将less文件编译成css
66 +sass-loader 是将sass文件编译成css
67 +```
68 +
69 ++ 示例:
70 +
71 +>[-- webpack_JS_CSS数据打包及对生产环境html模板的生成](https://github.com/qianjiahao/webpack-babel-react-development-tools)
72 +
73 +>[-- webpack Samples](https://github.com/ruanyf/webpack-demos)
74 +
75 +>[-- Webpack+React+ES6开发模式入门](http://www.cnblogs.com/skylar/p/React-Webpack-ES6.html)
76 +
77 +---
78 +
79 +### Vue篇
80 +
81 ++ 实践
82 +
83 +>[-- Vue组件化开放实践](http://gold.xitu.io/entry/55f77eb460b28e6a6f0f4f86)
84 +
85 +>[-- Webpack + vue-loader入坑之旅](https://segmentfault.com/a/1190000004690338)
86 +
87 +>[-- Vue + webpack 项目实践](http://ju.outofmemory.cn/entry/195573)
88 +
89 +
90 ++ 组件篇
91 +
92 +> [Vue-Router](https://github.com/vuejs/vue-router)
93 +> 官方Vue Router
94 +> [flatiron/director](https://github.com/flatiron/director)
95 +> a tiny and isomorphic URL router for JavaScript
96 +> [vuejs/vue-resource](https://github.com/vuejs/vue-resource)
97 +> 网络请求库
98 +> [vuejs/vue-validator](https://github.com/vuejs/vue-validator)
99 +> 表单验证库
100 +> [vuejs/vue-touch] (https://github.com/vuejs/vue-touch)
101 +> 事件模拟
102 +
103 ++ Github示例
104 +
105 +>[-- vuejs/vue-webpack-example](https://github.com/vuejs/vue-webpack-example/blob/master/package.json)
106 +
107 +
108 +>[-- Vue官方Examples](https://github.com/vuejs/vue/tree/dev/examples)
109 +
110 +>[-- Vuewjs-templates/webpack](https://github.com/vuejs-templates/webpack/tree/dist/template)
111 +
112 +>A full-featured Webpack + vue-loader setup with hot reload, linting, testing & css extraction.
113 +
114 +>[-- Just Vue](https://github.com/JustClear/just-vue)
115 +
116 +> A quick starter for Vue and Webpack
117 +
118 +
119 +
120 +---
121 +
122 +### Gulp篇
123 +
124 +
125 +---
126 +
127 +### Jade篇
128 +
129 +>[Jade —— 源于 Node.js 的 HTML 模板引擎](https://segmentfault.com/a/1190000000357534)
130 +
131 +>[Jade Document](http://naltatis.github.io/jade-syntax-docs/)
132 +
133 +---
134 +
135 +### 其它工具篇
136 +
137 +>[-- Mobile Web Developer Tool:AlloyLever](http://www.alloyteam.com/2016/05/mobile-web-development-debugging-tools-alloylever-introduced/)
138 +
139 +
140 +
141 +---
142 +
143 +### Javascript 语言篇
144 +
145 +>[-- 从作用域链谈闭包](http://www.ido321.com/1641.html)
146 +
147 + 闭包是指有权访问另外一个函数作用域中的变量的函数
148 +
149 +---
150 +
151 +
152 +### Nodejs篇
153 +
154 +>[Nodejs资源汇总](https://www.douban.com/group/topic/35067110/)
155 +>[Nodejs手册文档](http://nodeapi.ucdok.com/#/api/)
156 +
157 +##### QA
158 +>[nodejs中exports与module.exports的区别](http://www.cnblogs.com/pigtail/archive/2013/01/14/2859555.html)
159 +
160 +### NPM
161 +
162 +> [npm源](https://github.com/Pana/nrm)
163 +> 使用nrm工具来切换npm源
164 +
1 +# Webpack QA
2 +
3 +### ReferenceError: webpackJsonp is not defined #606
4 +
5 +[Linke](https://github.com/webpack/webpack/issues/606)
6 +
7 +### Webpack 使用Bower
8 +
9 +[Link](http://webpack.github.io/docs/usage-with-bower.html)
...\ No newline at end of file ...\ No newline at end of file
1 +# Laravel中的User模型
2 +
3 +分析在laravel中的User Model,会发现一些很有意思的事情
4 +
5 ++ **User模型**
6 +
7 +```
8 +use Illuminate\Auth\Authenticatable;
9 +use Illuminate\Database\Eloquent\Model;
10 +use Illuminate\Auth\Passwords\CanResetPassword;
11 +use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
12 +use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
13 +
14 +// 实现了AuthenticatableContract,CanResetPasswordContract
15 +// 但是在模型类中不实现,只是
16 +// 通过trait class = (Authenticatable,CanResetPassword)实现。
17 +
18 +class User extends Model
19 + implements AuthenticatableContract, CanResetPasswordContract
20 +{
21 +
22 + use Authenticatable, CanResetPassword;
23 +
24 + /**
25 + * The database table used by the model.
26 + *
27 + * @var string
28 + */
29 + protected $table = 'users';
30 +
31 + /**
32 + * The attributes that are mass assignable.
33 + *
34 + * @var array
35 + */
36 + protected $fillable = ['name', 'email', 'password'];
37 +
38 + /**
39 + * The attributes excluded from the model's JSON form.
40 + *
41 + * @var array
42 + */
43 + protected $hidden = ['password', 'remember_token'];
44 +
45 +}
46 +```
47 +
48 ++ **AuthenticatableContract接口定义**
49 +
50 +```
51 +namespace Illuminate\Contracts\Auth;
52 +
53 +// 约定,namespace带有Contracts的,表示接口
54 +
55 +interface Authenticatable {
56 +
57 + /**
58 + * Get the unique identifier for the user.
59 + *
60 + * @return mixed
61 + */
62 + public function getAuthIdentifier();
63 +
64 + /**
65 + * Get the password for the user.
66 + *
67 + * @return string
68 + */
69 + public function getAuthPassword();
70 +
71 + /**
72 + * Get the token value for the "remember me" session.
73 + *
74 + * @return string
75 + */
76 + public function getRememberToken();
77 +
78 + /**
79 + * Set the token value for the "remember me" session.
80 + *
81 + * @param string $value
82 + * @return void
83 + */
84 + public function setRememberToken($value);
85 +
86 + /**
87 + * Get the column name for the "remember me" token.
88 + *
89 + * @return string
90 + */
91 + public function getRememberTokenName();
92 +
93 +}
94 +```
95 +
96 ++ **Authenticatable的实现**
97 +
98 +```
99 +namespace Illuminate\Auth;
100 +
101 +trait Authenticatable {
102 +
103 + /**
104 + * Get the unique identifier for the user.
105 + *
106 + * @return mixed
107 + */
108 + public function getAuthIdentifier()
109 + {
110 + return $this->getKey();
111 + }
112 +
113 + /**
114 + * Get the password for the user.
115 + *
116 + * @return string
117 + */
118 + public function getAuthPassword()
119 + {
120 + return $this->password;
121 + }
122 +
123 + /**
124 + * Get the token value for the "remember me" session.
125 + *
126 + * @return string
127 + */
128 + public function getRememberToken()
129 + {
130 + return $this->{$this->getRememberTokenName()};
131 + }
132 +
133 + /**
134 + * Set the token value for the "remember me" session.
135 + *
136 + * @param string $value
137 + * @return void
138 + */
139 + public function setRememberToken($value)
140 + {
141 + // 用这样的方式很灵活....
142 + $this->{$this->getRememberTokenName()} = $value;
143 + }
144 +
145 + /**
146 + * Get the column name for the "remember me" token.
147 + *
148 + * @return string
149 + */
150 + public function getRememberTokenName()
151 + {
152 + return 'remember_token';
153 + }
154 +
155 +}
156 +```
...\ No newline at end of file ...\ No newline at end of file
1 +# Laravel & Lumen 中整体配置的说明
2 +
3 +### 1. Lumen使用自定义的配置文件
4 +在laravel当中,默认是存在config文件夹,按照规则,相应的库需要配置文件,都是在config中以独立的一个php config文件存在的。
5 +而在Lumen当中,是没有config文件夹,配置文件统一放到.env文件中。
6 +
7 +- 以下是Laravel中使用的结构文件:
8 +![Alt text](../imgs/laravel_st1.png)
9 +
10 +- 以下是Lumen中使用的文件结构
11 +![Alt text](../imgs/lumen_st1.png)
12 +
13 +如果在Lumen当中需要启用config文件夹,并且按库去设定相应的配置文件。那么就需要以下两个步骤:
14 +
15 +1. 在项目根目录中,建立config文件夹
16 +2. 创建相应的.php配置文件,这些配置文件返回的是一个key=>value组成的数组结构
17 +3. 在bootstrap/app.php中指定使用相应的配置文件,但是有一个config/database.php配置文件不需要configure指定,就可以默认加载。
18 +
19 +
20 +```
21 +$app->configure('api');
22 +$app->configure('jwt');
23 +$app->configure('auth');
24 +```
25 +
26 +---
27 +
28 +### 2. 入口文件、启动文件和配置文件
29 +[参考链接](https://segmentfault.com/a/1190000002902055)
30 +
31 +应用程序的入口文件是:
32 + /index.php ==> /public/index.php ==> /bootstrap/app.php
33 +
34 +应用程序最基本的启动是:
35 +
36 +- public/index.php
37 + `$app = require(bootstrap/app.php)`
38 +- bootstrap/app.php
39 +```
40 +Dotenv\Dotenv(__DIR__.'/../'))->load(); // load env
41 +$app = new Laravel/Lumen/Application();
42 +// 如果是Laravel,则是 new Illuminate/Foundation/Application
43 +
44 +// Register Singleton Container Bindings
45 +$app->singleton(...);
46 +
47 +// Register Middleware
48 +$app->middleware(...);
49 +$app->routeMiddleware(...);
50 +
51 +// Register Service Provider
52 +$app->register(...);
53 +
54 +// 加载路由
55 +require app/Http/routes.php
56 +```
57 +- router定义
58 +```
59 +$app->get('/', function () use ($app) {
60 + return $app->version();
61 +});
62 +```
63 +- 程序运行(public/index.php)
64 +`$app->run();`
65 +
66 +
67 +Lumen的配置文件是根目录下的.env文件,.env文件的载入是bootstrap/app.php中的一行代码:
68 +`new Dotenv\Dotenv(__DIR__.'/../'))->load()`
69 +
70 +---
71 +
72 +### 3. Facades
73 +
74 +>Facades 提供一个静态接口给在应用程序的服务容器中可以取用的类
75 +
76 +在配置文件中,有一个`$app->withFacades();`是表示启用Facades.
77 +启用和不启用的区域在于:
78 +
79 +- 启用前:
80 +```
81 +use Illuminate\Support\Facades\Cache;
82 +use Illuminate\Support\Facades\DB;
83 +
84 +Cache::put('key', 'value', $minutes);
85 +DB::getQueryLog();
86 +```
87 +- 启用后
88 +```
89 +use Cache;
90 +use DB;
91 +Cache::put('key', 'value', $minutes);
92 +DB::getQueryLog();
93 +```
94 +
95 +通过查看withFacades,可以看出玄机:
96 +```
97 +public function withFacades()
98 +{
99 + Facade::setFacadeApplication($this);
100 +
101 + if (! static::$aliasesRegistered) {
102 + static::$aliasesRegistered = true;
103 +
104 + class_alias('Illuminate\Support\Facades\App', 'App');
105 + class_alias('Illuminate\Support\Facades\Auth', 'Auth');
106 + class_alias('Illuminate\Support\Facades\Bus', 'Bus');
107 + class_alias('Illuminate\Support\Facades\DB', 'DB');
108 + class_alias('Illuminate\Support\Facades\Cache', 'Cache');
109 + class_alias('Illuminate\Support\Facades\Cookie', 'Cookie');
110 + class_alias('Illuminate\Support\Facades\Crypt', 'Crypt');
111 + class_alias('Illuminate\Support\Facades\Event', 'Event');
112 + class_alias('Illuminate\Support\Facades\Hash', 'Hash');
113 + class_alias('Illuminate\Support\Facades\Log', 'Log');
114 + class_alias('Illuminate\Support\Facades\Mail', 'Mail');
115 + class_alias('Illuminate\Support\Facades\Queue', 'Queue');
116 + class_alias('Illuminate\Support\Facades\Request', 'Request');
117 + class_alias('Illuminate\Support\Facades\Schema', 'Schema');
118 + class_alias('Illuminate\Support\Facades\Session', 'Session');
119 + class_alias('Illuminate\Support\Facades\Storage', 'Storage');
120 + class_alias('Illuminate\Support\Facades\Validator', 'Validator');
121 + }
122 +}
123 +```
124 +
125 +---
126 +
127 +### 4. Session
128 +Session 默认未开启。
129 +开启方式:去掉 bootstrap/app.php 中 $app->middleware(); 的 StartSession中间件的注释。
130 +
131 +在 .env 文件中,Session 的默认驱动是:memcached。
132 +目前支持的驱动有:file、cookie、database、memcached、redis、array
133 +
134 +[Session参考](http://lumen.laravel-china.org/docs/session#session-drivers)
135 +
136 +
137 +### 5. Laravel的一些package
138 +[参考](https://segmentfault.com/a/1190000002889864)
139 +
1 +# Laravel
...\ No newline at end of file ...\ No newline at end of file
1 +# 一些Laravel中的代码说明
2 +
3 +### 1.在Controller中函数参数使用Request
4 +首先需要引用Illuminate\Http\Request命名空间,才能使用$request变量
5 +
6 +```
7 +use Illuminate\Http\Request
8 +use dump;
9 +class ProjectController extends Controller
10 +{
11 + public function index(Request $request) {
12 + dump($request);
13 + }
14 +}
15 +```
16 +
17 +也可以在bootstrap/app.php中使用class_alias将Illuminate\Http\Request定义为Request.
18 +
19 +```
20 +// in bootstrap/app.php
21 +class_alias('Illuminate\Http\Request','Request');
22 +
23 +// in controller.php
24 +use Request;
25 +public function index(Request $request) {...}
26 +```
27 +
28 +---
29 +
30 +### 2.Request操作
31 +
32 +>[参考链接](http://laravel-china.org/docs/5.1/requests)
33 +
34 ++ 验证
35 +
36 +```
37 + $this->validate($request, [
38 + 'email' => 'required|email|max:255',
39 + 'password' => 'required',
40 + ]);
41 +```
42 +
43 ++ 获得请求字段
44 +
45 +```
46 +- 方式1:
47 + $order_state = Request::input('order_state');
48 + $evaluation_state = Request::input('evaluation_state');
49 + $orderId = $request->input('order_id',1);
50 +
51 +- 方式2:
52 + $request->only('email', 'password');
53 +```
54 +
55 +---
56 +
57 +### 3.Response操作
58 +
59 +Response默认使用的类为 `Illuminate\Http\Response`
60 +当然,也可以实现一个自定义的Response,作为ServiceProvider,注册到容器中。
61 +具体自定义Response,可以查看Lumen-Api这本书。
62 +
63 +>[Response文档](http://laravel-china.org/docs/5.1/responses)
64 +>[Response详细API](http://laravel-china.org/api/master/Illuminate/Http/Response.html)
65 +
66 +
67 ++ **基本响应**
68 +
69 +```
70 +return (new Response($content, $status))
71 + ->header('Content-Type', $value);
72 +
73 +return response($content, $status)
74 + ->header('Content-Type', $value);
75 +```
76 +
77 ++ **标头定义响应**
78 +
79 +```
80 +return response($content)
81 + ->header('Content-Type', $type)
82 + ->header('X-Header-One', 'Header Value')
83 + ->header('X-Header-Two', 'Header Value');
84 +```
85 +
86 ++ **附加Cookies**
87 +
88 +```
89 +return response($content)->header('Content-Type', $type)
90 + ->withCookie('name', 'value');
91 +
92 +- Cookie的可定义属性
93 +->withCookie($name, $value, $minutes, $path, $domain, $secure, $httpOnly)
94 +```
95 +
96 ++ **视图响应**
97 +
98 +```
99 +return response()->view('hello', $data)->header('Content-Type', $type);
100 +```
101 +
102 +
103 ++ **JSON响应**
104 +
105 +```
106 +return response()->json(['name' => 'Abigail', 'state' => 'CA']);
107 +
108 +- JSONP 响应
109 +return response()->json(['name' => 'Abigail', 'state' => 'CA'])
110 + ->setCallback($request->input('callback'));
111 +```
112 +
113 ++ **文件下载**
114 +
115 +```
116 +return response()->download($pathToFile);
117 +return response()->download($pathToFile, $name, $headers);
118 +```
119 +
120 ++ **重定向**
121 +
122 +```
123 +return redirect('home/dashboard');
124 +// 重定向到某个位置
125 +return back()->withInput();
126 +// 重定向至命名路由
127 +return redirect()->route('login');
128 +// 重定向至路由,路由带有参数
129 +return redirect()->route('profile', [1]);
130 +return redirect()->route('profile', [$user]);
131 +// 重定向至控制器行为
132 +return redirect()->action('HomeController@index');
133 +return redirect()->action('UserController@profile', [1]);
134 +```
135 +
136 +
137 +### 4.注册中间件(Middleware)
138 +中间件的注册,在laravel和Lumen中的方式是不一样的。
139 +
140 ++ 在Laravel中,通过app/Http/Kernal.php进行注册
141 +
142 +```
143 +protected $middleware = [
144 + 'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
145 + 'Illuminate\Cookie\Middleware\EncryptCookies',
146 + 'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
147 + 'Illuminate\Session\Middleware\StartSession',
148 + 'Illuminate\View\Middleware\ShareErrorsFromSession',
149 + 'App\Http\Middleware\VerifyCsrfToken',
150 + ];
151 +protected $routeMiddleware = [
152 + 'auth' => 'App\Http\Middleware\Authenticate',
153 + 'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
154 + 'guest' => 'App\Http\Middleware\RedirectIfAuthenticated',
155 + ];
156 +```
157 +
158 +
159 ++ 而在Lumen中,则是通过bootstrap/app.php注册
160 +
161 +```
162 +$app->middleware([
163 + App\Http\Middleware\ExampleMiddleware::class
164 + ]);
165 +
166 + $app->routeMiddleware([
167 + 'auth' => App\Http\Middleware\Authenticate::class,
168 + 'jwt.auth' => Tymon\JWTAuth\Middleware\GetUserFromToken::class,
169 + 'jwt.refresh' => Tymon\JWTAuth\Middleware\RefreshToken::class,
170 + ]);
171 +```
172 +
173 +---
174 +
175 +### 5. 服务提供者和服务容器
176 +应用程序通过 bootstrap/app.php 文件中所生成的 Laravel 应用程序实例。
177 +通过调用以下代码,创建应用程序Application的实例app,app中创建了服务容器(loadedProviders).
178 +
179 +```
180 +-- in bootstrap/app.php
181 +$app = new Laravel\Lumen\Application()
182 +
183 +-- in Application.php
184 +protected $serviceProviders = array();
185 +protected $loadedProviders = array();
186 +protected $deferredServices = array();
187 +...
188 +$this->registerBaseBindings();
189 +$this->registerBaseServiceProviders();
190 +$this->registerCoreContainerAliases();
191 +...
192 +```
193 +
194 +### 6.服务的注册(ServiceProvider)
195 +ServiceProvider的注册,在Laravel和Lumen中情况不一样。
196 +
197 ++ Laravel
198 +
199 +> Laravel中的服务提供是,都在config/app.php配置文件的providers数组
200 +
201 +```
202 +'providers' => [
203 +
204 + /*
205 + * Laravel Framework Service Providers...
206 + */
207 + 'Illuminate\Foundation\Providers\ArtisanServiceProvider',
208 + 'Illuminate\Auth\AuthServiceProvider',
209 + 'Illuminate\Bus\BusServiceProvider',
210 + 'Illuminate\Cache\CacheServiceProvider',
211 + 'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
212 + 'Illuminate\Routing\ControllerServiceProvider',
213 + 'App\Providers\AppServiceProvider',
214 + 'App\Providers\BusServiceProvider',
215 + 'App\Providers\ConfigServiceProvider',
216 + ...
217 +];
218 +```
219 +
220 ++ Luemn
221 +
222 +> Lumen中直接使用register进行注册
223 +
224 +```
225 +$app->register(Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class);
226 +// Dingo API Register
227 +$app->register(Dingo\Api\Provider\LumenServiceProvider::class);
228 +// $app->register(App\Providers\AuthServiceProvider::class);
229 +$app->register(App\Providers\EventServiceProvider::class);
230 +```
231 +
232 +
This diff is collapsed. Click to expand it.
1 +# 一些Laravel站点
2 +
3 +帮助参考学习用:
4 +
5 ++ [基本文档](http://laravel-china.org/)
6 ++ [Laravel不权威导航](https://segmentfault.com/a/1190000004086565)
7 ++ [Laravel学院](http://laravelacademy.org/)
8 ++ [Laravel函数和命令](http://cheats.jesse-obrien.ca/)
...\ No newline at end of file ...\ No newline at end of file
1 +# Introduction
2 +
3 +<div style="color:#333">本知识库为 <strong>青鸽攻城狮</strong> 在项目中的点滴技术分享、工作积累、学习成果合集!</div>
4 +
5 +<p></p>
6 +
7 +>众奇开放文档知识库
8 +> **## 开放.分享.学习 ##**
9 +>祝学习愉快 !!!
10 +
11 +---
12 +
13 +**众奇信息技术有限公司 &copy; Qingger Team**
...\ No newline at end of file ...\ No newline at end of file
1 +# Summary
2 +
3 +- [README](.\README.md)
4 +- Thinkphp
5 + - Controller
6 + - [evshop_controller](Thinkphp\Controller\evshop_controller.md)
7 + - DB
8 + - [db_sqls](Thinkphp\DB\db_sqls.md)
9 + - Others
10 + - [functions](Thinkphp\Others\functions.md)
11 + - [UsefulCodes](Thinkphp\Others\UsefulCodes.md)
12 + - Structure
13 + - [evshop_structure](Thinkphp\Structure\evshop_structure.md)
14 + - View
15 + - [evshop_view](Thinkphp\View\evshop_view.md)
16 + - Javascript
17 + - [evshop_dialog](Thinkphp\Javascript\evshop_dialog.md)
18 + - [evshop_js](Thinkphp\Javascript\evshop_js.md)
1 +# Summary
2 +
3 +- [简介](.\README.md)
4 +- Thinkphp
5 + - Structure
6 + - [EVShop框架结构图](Thinkphp\Structure\evshop_structure.md)
7 + - Controller
8 + - [EVShop之Controller篇](Thinkphp\Controller\evshop_controller.md)
9 + - View
10 + - [EVShop之View篇](Thinkphp\View\evshop_view.md)
11 + - Javascript
12 + - [EVShop之Dialog篇](Thinkphp\Javascript\evshop_dialog.md)
13 + - [EVShop之Javascript篇](Thinkphp\Javascript\evshop_js.md)
14 + - DB
15 + - [Thinkphp中SQL的写法](Thinkphp\DB\db_sqls.md)
16 + - Others
17 + - [Thinkphp中常用功能](Thinkphp\Others\functions.md)
18 + - [EVShop中备用代码片段](Thinkphp\Others\UsefulCodes.md)
19 +- Laravel
20 + - 其它
21 + - [artisan命令行](Laravel\Others\artisan.md)
22 + - [laraval学习站点](Laravel\Others\laravel_sites.md)
23 + - 配置
24 + - [整体配置说明](Laravel\Configs\configs.md)
25 +- Javascript
26 + - 学习
27 + - [前端各工具集学习链接](Javascript\Learn\webfront.md)
28 + - [NPM使用](Javascript\Learn\npm_cmd.md)
29 + - [ES6学习](Javascript\Learn\ES6.md)
...\ No newline at end of file ...\ No newline at end of file
1 +# EVShop编程规则之Controller篇
2 +
3 +### 1. Controller中成功和错误的处理
4 +不涉及对话框处理,只在Controller页面跳转的情况下,针对错误处理和成功处理规则如下:
5 +
6 +1. 错误和异常情况下,使用 `$this->error(message);`
7 +2. 成功的情况下,使用 `$this->success(message);`
8 +
9 +而具体error,success函数调用后所显示的画面的样式,可以在conf/config.php中进行定义
10 +```
11 +//默认错误跳转对应的模板文件(View/Public/error.html)
12 +'TMPL_ACTION_ERROR' => 'Public:error',
13 +//默认成功跳转对应的模板文件' (View/Public/success.html)
14 +'TMPL_ACTION_SUCCESS' => 'Public:success',
15 +```
16 +
17 +
18 +---
19 +
20 +
21 +### 2. Controller中成功或者失败返回JSON数据格式
22 +Controller返回JSON数据,一般用于前端JS异步调用Controller方法的场合。
23 +返回JSON,为了后期扩展,统一使用以下函数生成json返回
24 +
25 +1. 成功的场合:
26 +
27 + json_return_success('successMessage');
28 + // will return { 'errCode':0, 'info':'successMessage'}
29 +
30 +2. 失败的场合:
31 +
32 + json_return_error('errorMessage');
33 + // will return {'errCode':1, 'info':'errorMessage'}
34 +
35 +3. 需要自定义errorCode的场合:
36 +
37 + json_return_err_code(4001,'errorMessage');
38 + // will return {'errCode':4001, 'info':'errorMessage'}
39 +
40 +4. 需要自定义多个数据字段的场合:
41 +
42 + json_return_customer([
43 + 'errCode'=>4002,
44 + 'Message'=>'Customer Message',
45 + 'OtherInfo'=>'Other Infomation'
46 + ]);
47 +
48 +5. 对于微页面(weipage),有其自定义的JSON定义,在微页面编辑中,涉及到的JSON返回一般使用:
49 +
50 + json_return_for_weipage($err_code,$err_msg='',$err_dom='');
51 +
52 +
53 +---
54 +
55 +### 3. 页面中分页显示的设置
56 +设置数据的分页需要以下步骤:
57 +
58 ++ 在Controller中导入以下命名空间
59 +`use Library\MyPage;`
60 ++ 在对应的Controller方法中,调用MyPage类
61 +```php
62 +public function album_pic_list() {
63 + $where_condition = Array('aclass_id'=>$_GET['id'],'app_id'=>$this->app_id); // 查询条件
64 + $pic_count = M('album_pic')->where($where_condition)->count(); // 获得显示的总数目
65 + $pic_page = new MyPage($pic_count,6); // 创建MyPage类,参数1表示显示的总数,参数2表示一页中显示的数目
66 + $pic_list = M('album_pic')->where($where_condition)
67 + ->order('create_timedesc')
68 + ->limit($pic_page->firstRow.','.$pic_page->listRows)
69 + ->select(); // 查询时注意加入limit进行限定
70 + $this->assign('pic_list',$pic_list);// 向页面赋值列表
71 + $pagebar = $pic_page->show();
72 + $this->assign('show_page',$pagebar); // 向页面赋值pagebar元素
73 + $this->display('gp02_goods_album_pic_list'); // 视图显示
74 +}
75 +```
76 ++ 在视图中,通过以下代码显示Pager导航
77 +`<div class="pagination"><?php echo $show_page; ?></div>`
78 +
79 +---
80 +
1 +# Thinkphp中复杂SQL的写法
2 +
3 +### 1. SQL 多表联接的写法:
4 +```
5 +$spc_common_default = D("spc_common_default");
6 +$filter['S.spc_common_id'] = array('eq',71);
7 +$model_list  = $spc_common_default->table('__SPC_COMMON_DEFAULT__ S')
8 + ->join('LEFT JOIN __SPC_PGROUP_DEFAULT__ U ON S.spc_common_id = U.spc_common_id')
9 + ->field('S.*')
10 + ->where($map)
11 + ->select();
12 +```
13 +以上代码相当于以下SQL语句:
14 +```
15 +SELECT S.* FROM ev_spc_common_default as S
16 +LEFT JOIN ev_spc_group_default as U
17 +ON S.spc_common_id=U.spc_common_id
18 +WHERE s.spc_common_id=71
19 +```
20 +
21 +### 2. SQL Group 写法:
22 +```
23 +$model_list = $this->table('__ALBUM_CLASS__ A')->join('LEFT JOIN __ALBUM_PIC__ B ON A.aclass_id=B.aclass_id')
24 + ->field('A.aclass_id,A.app_id,A.aclass_name,A.aclass_des,A.aclass_conver,A.aclass_dic,A.is_default,A.create_time,count(B.aclass_id) as ClassCount')
25 + ->where($condition)
26 + ->group('A.aclass_id')
27 + ->order('A.create_time')
28 + ->select();
29 +```
30 +
31 +
32 +### 3. 统计查询(count,sum...)
33 +```
34 +$model->table('__ALBUM_CLASS__')->where($condition)->count();
35 +$model->table('__ALBUM_CLASS__')->count('columnName');
36 +$sumScore = $User->sum('score');
37 +```
...\ No newline at end of file ...\ No newline at end of file
1 +# EVShop编程规则之Dialog篇
2 +
3 +> 在Evshop中,对话框是使用artDialog控件,关于artDialog的使用方式,可以参考:
4 +> [artDialog文档](http://aui.github.io/artDialog/doc/index.html)
5 +> 我们在artDialog基础上,做了一些基础的封装,封装参考代码:
6 +> `/data/application/common/myDialog.js`
7 +> 对话框的基本使用示例,参考:
8 +> `/data/application/shop/sample_list.js`
9 +
10 +### 对话框(myDialog)的使用
11 +
12 ++ 要使用对话框,需要在前端js中引入:
13 +`var myDialog = require("myDialog");`
14 +
15 ++ 使用基本的 **Success/Error/Info** 对话框:
16 +```
17 +myDialog.showSucc("Success");
18 +myDialog.showError("Failed");
19 +myDialog.showInfo("title","你好啊");
20 +```
21 +
22 ++ 对话框中显示本页面中元素内的内容:
23 +```
24 +$("#opelem").bind("click",function(){
25 + var dialog= myDialog.showMoreDialog(this,{
26 + width:400,
27 + height:$("#dlg_element").height+200,
28 + title:$(this).attr("dialog_title"),
29 + content:$("#dlg_element").html(),
30 + },true);
31 +});
32 +```
33 +
34 ++ 显示自定义confirm对话框
35 +```
36 +myDialog.showConfirm("提示信息","删除相册?注意:相册内的图片将转移到默认相册",function(){
37 + $(this).ajaxSubmit({
38 + data: {"id":album_id},
39 + dataType:'json',
40 + type:'get',
41 + url:process_uri,
42 + success:function(responseText,stsText,xhr){
43 + commonFunc.showAjaxProcessInfo(responseText);
44 + },
45 + error:function(error) {
46 + myDialog.showError(error);
47 + }
48 + });
49 + //alert('xxx');
50 +});
51 +```
52 +
53 +
54 ++ 对话框中显示指定URL的内容
55 +```
56 + $("#opelurl2").bind('click',function(){
57 + // support param: width,
58 + var dialog = myDialog.showFormDialog(this,{
59 + width:500,
60 + title:"Open Dialog",
61 + url:$(this).attr("dialog_url"),
62 + okValue : "确定", // 确定按钮文件,如果不设定,则默认为"确定"
63 + extraSubmitData : {"param1":"1","param2":"2"},
64 + success: function(dialogObj,responseText) {
65 + console.log(responseText); // responsetext后端返回的JSON对象
66 + myDialog.showSucc("Success");
67 + //dialogObj.close().remove();
68 + },
69 + error: function(dialogObj,errorText) {
70 + console.log(errorText);
71 + myDialog.showError(errorText);
72 + //dialogObj.close().remove();
73 + }
74 + });
75 + });
76 +```
77 +
78 + > 注:一般来说,指定URL内容包含的是FORM表单,表单提交的Button不需要在页面中定义,
79 + > 而是使用对话框提供的OK/Cancel按钮
80 +
81 +
82 ++ 对话框URL方式打开后,支持对话框内元素事件的监听
83 +在myDialog.showFormDialog函数内,
84 +可以使用eventListeners来监听对话框内元素的事件监听。方式如下:
85 +```
86 +$("#opelurl2").bind('click',function(){
87 + // support param: width,
88 + var dialog = myDialog.showFormDialog(this,{
89 + width:500,
90 + title:"Open Dialog",
91 + url:$(this).attr("dialog_url"),
92 + eventListeners : [{
93 + selector:'input[type="text"]', // Dialog中事件绑定的选择器
94 + eventName:'change', // Dialog中需要监测的事件
95 + eventFunction : function($sender,$dlgDocument) { // 事件产生后所回调的函数
96 + // $sender是触发此事件的jquery对象,$document是页面中document的jquery对象
97 + console.log($sender.attr("name"));
98 + //console.log($dlgDocument);
99 + }
100 + }],
101 + okValue : "确定", // 确定按钮文件,如果不设定,则默认为"确定"
102 + ...
103 +}
104 +```
1 +# EVShop编程规则之Javascript篇
2 +
3 +### 1. HTML中添加sevent/saction/sparams 对元素进行事件的绑定
4 +
5 + > 事件绑定是通过jquery的on方法,绑定在document元素上,基于事件的冒泡实现的。
6 +
7 ++ 在视图html中,可以通过以下方式进行事件的绑定动作:
8 +
9 +```
10 +<a href="JavaScript:void(0);" class="ncsc-btn-mini" sevent="click" saction="picAction" stype="multiDel" sparams="1,2" ></a>
11 +<a href="JavaScript:void(1);" class="ncsc-btn-mini" id="img_move" sevent="click" saction="picAction" stype="multiMov" sparms="3,4"></a>
12 +```
13 +
14 ++ 在此视图对应的js文件中,只需要定义以下事件:
15 +```
16 +PageModel.prototype.picAction = function(sender,param1,param2) {
17 + if($(sender).attr("stype")==="multiDel") {
18 + //具体事件的动作
19 + }
20 +}
21 +```
22 +
23 +在绑定的过程中,支持的事件行为(sevent)有:
24 +
25 + "click", "change", "blur", "dbclick", "focus", "hover", "resize"
26 +
27 +---
28 +
29 +### 2. JSON.Parse函数的参数存在特殊字符的处理
30 +
31 +> JSON.Parse()函数,使用的参数是一个字符串,
32 +> 该字符串中存在"\"时,函数转换就会出错,出错提示为:
33 +> `JSON.parse: expected ',' or '}' after property value in object`
34 +> 所以,需要将字符串进行转换,为"\"符号进行转义
35 +
36 +__具体实现__:
37 +
38 +1. 在PHP中,针对字符串,使用addslashes函数:
39 + `$this->assign('customField', addslashes(json_encode($customField)));`
40 +2. 在JS中,使用replace将"\"转换成"\\"格式
41 +
42 +---
43 +
44 +### 3. 使用jquery-form 进行异步提交
45 +
46 +> jquery-form是一种js的异步提交,提交时,除了把指定的form数据进行提交,
47 +> 还支持额外自定义数据的提交
48 +
49 +实现方式:
50 +```
51 +var jquery_form = require("jquery-form");
52 +$(selector).ajaxSubmit({
53 + data:[extraSubmitdata]
54 + dataType:'json',
55 + type:'post',
56 + timeout:5000,
57 + success:function(responseText,stsText,xhr,element) {
58 +
59 + },
60 + error:function(error) {
61 +
62 + }
63 +});
64 +```
65 +
1 +# EVShop中备用代码片段
2 +
3 +> 此文件记录了Evshop实现过程中的一些经常被使用到的代码。
4 +> 记录于此,需要时以备查询。
5 +
1 +# Thinkphp中一些常用功能
2 +
3 +### 1. 加入验证码功能
4 +Think\Verify类可以支持验证码的生成和验证功能。
5 +
6 +> 参考:[Thinkphp验证码](http://document.thinkphp.cn/manual_3_2.html#verify)
7 +
8 +下面是最简单的方式生成验证码:
9 +```
10 +$Verify = new \Think\Verify();
11 +$Verify->entry();
12 +```
13 +
14 +---
15 +
16 +### 2. 文件上传(后台)
17 +```
18 +use Library\UploadFile;
19 +if (!empty($_FILES['group_logo']['name'])){
20 + $upload = new UploadFile();
21 + $upload->set('default_dir',ATTACH_COMMON);
22 + $upload->set('file_name','category-pic-'.$newClassId.'.jpg');
23 + $upload->set('ifremove',false);
24 + $upload->set('fprefix','fprefix');
25 + $upload->set('ext','ext');
26 + if ($result){
27 + $this->success("上传图片成功");
28 + }else {
29 + $this->error("上传图片失败");
30 + }
31 +}
32 +```
33 +
34 +---
35 +
36 +### 3. 图像处理
37 +Todo : write here
38 +
39 +---
40 +
41 +### 4. IP获取
42 +内置了get_client_ip方法用于获取客户端的IP地址
43 +
44 ++ 获取IP示例:
45 +`$ip = get_client_ip();`
46 ++ IP定位示例:
47 +```
48 +$Ip = new \Org\Net\IpLocation('UTFWry.dat'); // 实例化类 参数表示IP地址库文件
49 +$area = $Ip->getlocation('203.34.5.66'); // 获取某个IP地址所在的位置
50 +```
51 +
52 +---
53 +
54 +### 5. 字符转换成二维码
55 +
56 +生成带有LOGO的二维码,可以参考:
57 +
58 +> 参考: [带有LOGO二维码]( http://www.cnblogs.com/txw1958/p/phpqrcode.html)
59 +
60 +二维码转换实现:
61 +```
62 +use Library\QRcode;
63 +include_once '/app/Library/phpqrcode.php';
64 +
65 +$test="http://www.evate-soft.com/";
66 +$filename = "baidu.png";
67 +$level='L';
68 +$size = '6';
69 +$margin=4;
70 +QRcode::png($test, false, $level, $size, $margin);
71 +```
...\ No newline at end of file ...\ No newline at end of file
1 +# EVShop程序框架整体结构图
2 +
3 +> 待完成
...\ No newline at end of file ...\ No newline at end of file
1 +# EVShop编程规则之View篇
2 +
3 +### 1. 系统变量和配置变量
4 +系统变量的输出通常以$Think 打头,比如:
5 +```
6 +1. {$Think.server.script_name} // 输出$_SERVER['SCRIPT_NAME']变量
7 +2. {$Think.session.user_id} // 输出$_SESSION['user_id']变量
8 +3. {$Think.get.pageNumber} // 输出$_GET['pageNumber']变量
9 +4. {$Think.cookie.name} // 输出$_COOKIE['name']变量
10 +5. {$Think.const.MODULE_NAME} 输出常量
11 +6. {$Think.config.url_model} // 配置参数(在config.php)中设定
12 +7. {$Think.MODULE_NAME} // 模块名称
13 +```
14 +
15 +---
16 +
17 +
18 +### 2. View中将php变量值传递到前端JS文件
19 +需要两个步骤:
20 +
21 +1. View中定义pageParam字面量对象
22 +```
23 +<script>
24 + var pageParam = {
25 + s:"page1",
26 + };
27 +</script>
28 +```
29 +2. 在js的initialize()函数中直接使用options.pageParam属性
30 +```
31 +var PageModel = function (options) {
32 + this.pageName = options.page;
33 + this.module = options.module;
34 + this.pageParam = options.pageParam;
35 + this.languageData = new LanguageData("member_group_index");
36 +}
37 +```
38 +
39 +如果需要将变量转换成JSON传递到前端js中:
40 +```
41 +<script>
42 + var pageParam = {
43 + language: <?php echo json_encode($lang) ?>,
44 + };
45 +</script>
46 +```
...\ No newline at end of file ...\ No newline at end of file
1 +# Summary
2 +
3 +- [README](.\README.md)
4 +- Thinkphp
5 + - Controller
6 + - [evshop_controller](Thinkphp\Controller\evshop_controller.md)
7 + - DB
8 + - [db_sqls](Thinkphp\DB\db_sqls.md)
9 + - Others
10 + - [functions](Thinkphp\Others\functions.md)
11 + - [UsefulCodes](Thinkphp\Others\UsefulCodes.md)
12 + - Structure
13 + - [evshop_structure](Thinkphp\Structure\evshop_structure.md)
14 + - View
15 + - [evshop_view](Thinkphp\View\evshop_view.md)
16 + - Javascript
17 + - [evshop_dialog](Thinkphp\Javascript\evshop_dialog.md)
18 + - [evshop_js](Thinkphp\Javascript\evshop_js.md)
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
1 +require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
2 + var fontState;
3 +
4 + var THEMES = {
5 + "white": 0,
6 + "sepia": 1,
7 + "night": 2
8 + };
9 +
10 + var FAMILY = {
11 + "serif": 0,
12 + "sans": 1
13 + };
14 +
15 + // Save current font settings
16 + function saveFontSettings() {
17 + gitbook.storage.set("fontState", fontState);
18 + update();
19 + }
20 +
21 + // Increase font size
22 + function enlargeFontSize(e) {
23 + e.preventDefault();
24 + if (fontState.size >= 4) return;
25 +
26 + fontState.size++;
27 + saveFontSettings();
28 + };
29 +
30 + // Decrease font size
31 + function reduceFontSize(e) {
32 + e.preventDefault();
33 + if (fontState.size <= 0) return;
34 +
35 + fontState.size--;
36 + saveFontSettings();
37 + };
38 +
39 + // Change font family
40 + function changeFontFamily(index, e) {
41 + e.preventDefault();
42 +
43 + fontState.family = index;
44 + saveFontSettings();
45 + };
46 +
47 + // Change type of color
48 + function changeColorTheme(index, e) {
49 + e.preventDefault();
50 +
51 + var $book = $(".book");
52 +
53 + if (fontState.theme !== 0)
54 + $book.removeClass("color-theme-"+fontState.theme);
55 +
56 + fontState.theme = index;
57 + if (fontState.theme !== 0)
58 + $book.addClass("color-theme-"+fontState.theme);
59 +
60 + saveFontSettings();
61 + };
62 +
63 + function update() {
64 + var $book = gitbook.state.$book;
65 +
66 + $(".font-settings .font-family-list li").removeClass("active");
67 + $(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")").addClass("active");
68 +
69 + $book[0].className = $book[0].className.replace(/\bfont-\S+/g, '');
70 + $book.addClass("font-size-"+fontState.size);
71 + $book.addClass("font-family-"+fontState.family);
72 +
73 + if(fontState.theme !== 0) {
74 + $book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, '');
75 + $book.addClass("color-theme-"+fontState.theme);
76 + }
77 + };
78 +
79 + function init(config) {
80 + var $bookBody, $book;
81 +
82 + //Find DOM elements.
83 + $book = gitbook.state.$book;
84 + $bookBody = $book.find(".book-body");
85 +
86 + // Instantiate font state object
87 + fontState = gitbook.storage.get("fontState", {
88 + size: config.size || 2,
89 + family: FAMILY[config.family || "sans"],
90 + theme: THEMES[config.theme || "white"]
91 + });
92 +
93 + update();
94 + };
95 +
96 +
97 + gitbook.events.bind("start", function(e, config) {
98 + var opts = config.fontsettings;
99 +
100 + // Create buttons in toolbar
101 + gitbook.toolbar.createButton({
102 + icon: 'fa fa-font',
103 + label: 'Font Settings',
104 + className: 'font-settings',
105 + dropdown: [
106 + [
107 + {
108 + text: 'A',
109 + className: 'font-reduce',
110 + onClick: reduceFontSize
111 + },
112 + {
113 + text: 'A',
114 + className: 'font-enlarge',
115 + onClick: enlargeFontSize
116 + }
117 + ],
118 + [
119 + {
120 + text: 'Serif',
121 + onClick: _.partial(changeFontFamily, 0)
122 + },
123 + {
124 + text: 'Sans',
125 + onClick: _.partial(changeFontFamily, 1)
126 + }
127 + ],
128 + [
129 + {
130 + text: 'White',
131 + onClick: _.partial(changeColorTheme, 0)
132 + },
133 + {
134 + text: 'Sepia',
135 + onClick: _.partial(changeColorTheme, 1)
136 + },
137 + {
138 + text: 'Night',
139 + onClick: _.partial(changeColorTheme, 2)
140 + }
141 + ]
142 + ]
143 + });
144 +
145 +
146 + // Init current settings
147 + init(opts);
148 + });
149 +});
150 +
151 +
1 +/*
2 + * Theme 1
3 + */
4 +.color-theme-1 .dropdown-menu {
5 + background-color: #111111;
6 + border-color: #7e888b;
7 +}
8 +.color-theme-1 .dropdown-menu .dropdown-caret .caret-inner {
9 + border-bottom: 9px solid #111111;
10 +}
11 +.color-theme-1 .dropdown-menu .buttons {
12 + border-color: #7e888b;
13 +}
14 +.color-theme-1 .dropdown-menu .button {
15 + color: #afa790;
16 +}
17 +.color-theme-1 .dropdown-menu .button:hover {
18 + color: #73553c;
19 +}
20 +/*
21 + * Theme 2
22 + */
23 +.color-theme-2 .dropdown-menu {
24 + background-color: #2d3143;
25 + border-color: #272a3a;
26 +}
27 +.color-theme-2 .dropdown-menu .dropdown-caret .caret-inner {
28 + border-bottom: 9px solid #2d3143;
29 +}
30 +.color-theme-2 .dropdown-menu .buttons {
31 + border-color: #272a3a;
32 +}
33 +.color-theme-2 .dropdown-menu .button {
34 + color: #62677f;
35 +}
36 +.color-theme-2 .dropdown-menu .button:hover {
37 + color: #f4f4f5;
38 +}
39 +.book .book-header .font-settings .font-enlarge {
40 + line-height: 30px;
41 + font-size: 1.4em;
42 +}
43 +.book .book-header .font-settings .font-reduce {
44 + line-height: 30px;
45 + font-size: 1em;
46 +}
47 +.book.color-theme-1 .book-body {
48 + color: #704214;
49 + background: #f3eacb;
50 +}
51 +.book.color-theme-1 .book-body .page-wrapper .page-inner section {
52 + background: #f3eacb;
53 +}
54 +.book.color-theme-2 .book-body {
55 + color: #bdcadb;
56 + background: #1c1f2b;
57 +}
58 +.book.color-theme-2 .book-body .page-wrapper .page-inner section {
59 + background: #1c1f2b;
60 +}
61 +.book.font-size-0 .book-body .page-inner section {
62 + font-size: 1.2rem;
63 +}
64 +.book.font-size-1 .book-body .page-inner section {
65 + font-size: 1.4rem;
66 +}
67 +.book.font-size-2 .book-body .page-inner section {
68 + font-size: 1.6rem;
69 +}
70 +.book.font-size-3 .book-body .page-inner section {
71 + font-size: 2.2rem;
72 +}
73 +.book.font-size-4 .book-body .page-inner section {
74 + font-size: 4rem;
75 +}
76 +.book.font-family-0 {
77 + font-family: Georgia, serif;
78 +}
79 +.book.font-family-1 {
80 + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
81 +}
82 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal {
83 + color: #704214;
84 +}
85 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal a {
86 + color: inherit;
87 +}
88 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h1,
89 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h2,
90 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h3,
91 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h4,
92 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h5,
93 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h6 {
94 + color: inherit;
95 +}
96 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h1,
97 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h2 {
98 + border-color: inherit;
99 +}
100 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h6 {
101 + color: inherit;
102 +}
103 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal hr {
104 + background-color: inherit;
105 +}
106 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal blockquote {
107 + border-color: inherit;
108 +}
109 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal pre,
110 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal code {
111 + background: #fdf6e3;
112 + color: #657b83;
113 + border-color: #f8df9c;
114 +}
115 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal .highlight {
116 + background-color: inherit;
117 +}
118 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table th,
119 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table td {
120 + border-color: #f5d06c;
121 +}
122 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table tr {
123 + color: inherit;
124 + background-color: #fdf6e3;
125 + border-color: #444444;
126 +}
127 +.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n) {
128 + background-color: #fbeecb;
129 +}
130 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal {
131 + color: #bdcadb;
132 +}
133 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal a {
134 + color: #3eb1d0;
135 +}
136 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h1,
137 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h2,
138 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h3,
139 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h4,
140 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h5,
141 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h6 {
142 + color: #fffffa;
143 +}
144 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h1,
145 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h2 {
146 + border-color: #373b4e;
147 +}
148 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h6 {
149 + color: #373b4e;
150 +}
151 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal hr {
152 + background-color: #373b4e;
153 +}
154 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal blockquote {
155 + border-color: #373b4e;
156 +}
157 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal pre,
158 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal code {
159 + color: #9dbed8;
160 + background: #2d3143;
161 + border-color: #2d3143;
162 +}
163 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal .highlight {
164 + background-color: #282a39;
165 +}
166 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table th,
167 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table td {
168 + border-color: #3b3f54;
169 +}
170 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table tr {
171 + color: #b6c2d2;
172 + background-color: #2d3143;
173 + border-color: #3b3f54;
174 +}
175 +.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n) {
176 + background-color: #35394b;
177 +}
178 +.book.color-theme-1 .book-header {
179 + color: #afa790;
180 + background: transparent;
181 +}
182 +.book.color-theme-1 .book-header .btn {
183 + color: #afa790;
184 +}
185 +.book.color-theme-1 .book-header .btn:hover {
186 + color: #73553c;
187 + background: none;
188 +}
189 +.book.color-theme-1 .book-header h1 {
190 + color: #704214;
191 +}
192 +.book.color-theme-2 .book-header {
193 + color: #7e888b;
194 + background: transparent;
195 +}
196 +.book.color-theme-2 .book-header .btn {
197 + color: #3b3f54;
198 +}
199 +.book.color-theme-2 .book-header .btn:hover {
200 + color: #fffff5;
201 + background: none;
202 +}
203 +.book.color-theme-2 .book-header h1 {
204 + color: #bdcadb;
205 +}
206 +.book.color-theme-1 .book-body .navigation {
207 + color: #afa790;
208 +}
209 +.book.color-theme-1 .book-body .navigation:hover {
210 + color: #73553c;
211 +}
212 +.book.color-theme-2 .book-body .navigation {
213 + color: #383f52;
214 +}
215 +.book.color-theme-2 .book-body .navigation:hover {
216 + color: #fffff5;
217 +}
218 +/*
219 + * Theme 1
220 + */
221 +.book.color-theme-1 .book-summary {
222 + color: #afa790;
223 + background: #111111;
224 + border-right: 1px solid rgba(0, 0, 0, 0.07);
225 +}
226 +.book.color-theme-1 .book-summary .book-search {
227 + background: transparent;
228 +}
229 +.book.color-theme-1 .book-summary .book-search input,
230 +.book.color-theme-1 .book-summary .book-search input:focus {
231 + border: 1px solid transparent;
232 +}
233 +.book.color-theme-1 .book-summary ul.summary li.divider {
234 + background: #7e888b;
235 + box-shadow: none;
236 +}
237 +.book.color-theme-1 .book-summary ul.summary li i.fa-check {
238 + color: #33cc33;
239 +}
240 +.book.color-theme-1 .book-summary ul.summary li.done > a {
241 + color: #877f6a;
242 +}
243 +.book.color-theme-1 .book-summary ul.summary li a,
244 +.book.color-theme-1 .book-summary ul.summary li span {
245 + color: #877f6a;
246 + background: transparent;
247 + font-weight: normal;
248 +}
249 +.book.color-theme-1 .book-summary ul.summary li.active > a,
250 +.book.color-theme-1 .book-summary ul.summary li a:hover {
251 + color: #704214;
252 + background: transparent;
253 + font-weight: normal;
254 +}
255 +/*
256 + * Theme 2
257 + */
258 +.book.color-theme-2 .book-summary {
259 + color: #bcc1d2;
260 + background: #2d3143;
261 + border-right: none;
262 +}
263 +.book.color-theme-2 .book-summary .book-search {
264 + background: transparent;
265 +}
266 +.book.color-theme-2 .book-summary .book-search input,
267 +.book.color-theme-2 .book-summary .book-search input:focus {
268 + border: 1px solid transparent;
269 +}
270 +.book.color-theme-2 .book-summary ul.summary li.divider {
271 + background: #272a3a;
272 + box-shadow: none;
273 +}
274 +.book.color-theme-2 .book-summary ul.summary li i.fa-check {
275 + color: #33cc33;
276 +}
277 +.book.color-theme-2 .book-summary ul.summary li.done > a {
278 + color: #62687f;
279 +}
280 +.book.color-theme-2 .book-summary ul.summary li a,
281 +.book.color-theme-2 .book-summary ul.summary li span {
282 + color: #c1c6d7;
283 + background: transparent;
284 + font-weight: 600;
285 +}
286 +.book.color-theme-2 .book-summary ul.summary li.active > a,
287 +.book.color-theme-2 .book-summary ul.summary li a:hover {
288 + color: #f4f4f5;
289 + background: #252737;
290 + font-weight: 600;
291 +}
1 +pre,
2 +code {
3 + /* http://jmblog.github.io/color-themes-for-highlightjs */
4 + /* Tomorrow Comment */
5 + /* Tomorrow Red */
6 + /* Tomorrow Orange */
7 + /* Tomorrow Yellow */
8 + /* Tomorrow Green */
9 + /* Tomorrow Aqua */
10 + /* Tomorrow Blue */
11 + /* Tomorrow Purple */
12 +}
13 +pre .hljs-comment,
14 +code .hljs-comment,
15 +pre .hljs-title,
16 +code .hljs-title {
17 + color: #8e908c;
18 +}
19 +pre .hljs-variable,
20 +code .hljs-variable,
21 +pre .hljs-attribute,
22 +code .hljs-attribute,
23 +pre .hljs-tag,
24 +code .hljs-tag,
25 +pre .hljs-regexp,
26 +code .hljs-regexp,
27 +pre .ruby .hljs-constant,
28 +code .ruby .hljs-constant,
29 +pre .xml .hljs-tag .hljs-title,
30 +code .xml .hljs-tag .hljs-title,
31 +pre .xml .hljs-pi,
32 +code .xml .hljs-pi,
33 +pre .xml .hljs-doctype,
34 +code .xml .hljs-doctype,
35 +pre .html .hljs-doctype,
36 +code .html .hljs-doctype,
37 +pre .css .hljs-id,
38 +code .css .hljs-id,
39 +pre .css .hljs-class,
40 +code .css .hljs-class,
41 +pre .css .hljs-pseudo,
42 +code .css .hljs-pseudo {
43 + color: #c82829;
44 +}
45 +pre .hljs-number,
46 +code .hljs-number,
47 +pre .hljs-preprocessor,
48 +code .hljs-preprocessor,
49 +pre .hljs-pragma,
50 +code .hljs-pragma,
51 +pre .hljs-built_in,
52 +code .hljs-built_in,
53 +pre .hljs-literal,
54 +code .hljs-literal,
55 +pre .hljs-params,
56 +code .hljs-params,
57 +pre .hljs-constant,
58 +code .hljs-constant {
59 + color: #f5871f;
60 +}
61 +pre .ruby .hljs-class .hljs-title,
62 +code .ruby .hljs-class .hljs-title,
63 +pre .css .hljs-rules .hljs-attribute,
64 +code .css .hljs-rules .hljs-attribute {
65 + color: #eab700;
66 +}
67 +pre .hljs-string,
68 +code .hljs-string,
69 +pre .hljs-value,
70 +code .hljs-value,
71 +pre .hljs-inheritance,
72 +code .hljs-inheritance,
73 +pre .hljs-header,
74 +code .hljs-header,
75 +pre .ruby .hljs-symbol,
76 +code .ruby .hljs-symbol,
77 +pre .xml .hljs-cdata,
78 +code .xml .hljs-cdata {
79 + color: #718c00;
80 +}
81 +pre .css .hljs-hexcolor,
82 +code .css .hljs-hexcolor {
83 + color: #3e999f;
84 +}
85 +pre .hljs-function,
86 +code .hljs-function,
87 +pre .python .hljs-decorator,
88 +code .python .hljs-decorator,
89 +pre .python .hljs-title,
90 +code .python .hljs-title,
91 +pre .ruby .hljs-function .hljs-title,
92 +code .ruby .hljs-function .hljs-title,
93 +pre .ruby .hljs-title .hljs-keyword,
94 +code .ruby .hljs-title .hljs-keyword,
95 +pre .perl .hljs-sub,
96 +code .perl .hljs-sub,
97 +pre .javascript .hljs-title,
98 +code .javascript .hljs-title,
99 +pre .coffeescript .hljs-title,
100 +code .coffeescript .hljs-title {
101 + color: #4271ae;
102 +}
103 +pre .hljs-keyword,
104 +code .hljs-keyword,
105 +pre .javascript .hljs-function,
106 +code .javascript .hljs-function {
107 + color: #8959a8;
108 +}
109 +pre .hljs,
110 +code .hljs {
111 + display: block;
112 + background: white;
113 + color: #4d4d4c;
114 + padding: 0.5em;
115 +}
116 +pre .coffeescript .javascript,
117 +code .coffeescript .javascript,
118 +pre .javascript .xml,
119 +code .javascript .xml,
120 +pre .tex .hljs-formula,
121 +code .tex .hljs-formula,
122 +pre .xml .javascript,
123 +code .xml .javascript,
124 +pre .xml .vbscript,
125 +code .xml .vbscript,
126 +pre .xml .css,
127 +code .xml .css,
128 +pre .xml .hljs-cdata,
129 +code .xml .hljs-cdata {
130 + opacity: 0.5;
131 +}
1 +.book .book-summary .book-search {
2 + padding: 6px;
3 + background: transparent;
4 + position: absolute;
5 + top: -50px;
6 + left: 0px;
7 + right: 0px;
8 + transition: top 0.5s ease;
9 +}
10 +.book .book-summary .book-search input,
11 +.book .book-summary .book-search input:focus,
12 +.book .book-summary .book-search input:hover {
13 + width: 100%;
14 + background: transparent;
15 + border: 1px solid transparent;
16 + box-shadow: none;
17 + outline: none;
18 + line-height: 22px;
19 + padding: 7px 4px;
20 + color: inherit;
21 +}
22 +.book.with-search .book-summary .book-search {
23 + top: 0px;
24 +}
25 +.book.with-search .book-summary ul.summary {
26 + top: 50px;
27 +}
1 +require([
2 + "gitbook",
3 + "lodash"
4 +], function(gitbook, _) {
5 + var index = null;
6 + var $searchInput, $searchForm;
7 +
8 + // Use a specific index
9 + function loadIndex(data) {
10 + index = lunr.Index.load(data);
11 + }
12 +
13 + // Fetch the search index
14 + function fetchIndex() {
15 + $.getJSON(gitbook.state.basePath+"/search_index.json")
16 + .then(loadIndex);
17 + }
18 +
19 + // Search for a term and return results
20 + function search(q) {
21 + if (!index) return;
22 +
23 + var results = _.chain(index.search(q))
24 + .map(function(result) {
25 + var parts = result.ref.split("#")
26 + return {
27 + path: parts[0],
28 + hash: parts[1]
29 + }
30 + })
31 + .value();
32 +
33 + return results;
34 + }
35 +
36 + // Create search form
37 + function createForm(value) {
38 + if ($searchForm) $searchForm.remove();
39 +
40 + $searchForm = $('<div>', {
41 + 'class': 'book-search',
42 + 'role': 'search'
43 + });
44 +
45 + $searchInput = $('<input>', {
46 + 'type': 'text',
47 + 'class': 'form-control',
48 + 'val': value,
49 + 'placeholder': 'Type to search'
50 + });
51 +
52 + $searchInput.appendTo($searchForm);
53 + $searchForm.prependTo(gitbook.state.$book.find('.book-summary'));
54 + }
55 +
56 + // Return true if search is open
57 + function isSearchOpen() {
58 + return gitbook.state.$book.hasClass("with-search");
59 + }
60 +
61 + // Toggle the search
62 + function toggleSearch(_state) {
63 + if (isSearchOpen() === _state) return;
64 +
65 + gitbook.state.$book.toggleClass("with-search", _state);
66 +
67 + // If search bar is open: focus input
68 + if (isSearchOpen()) {
69 + gitbook.sidebar.toggle(true);
70 + $searchInput.focus();
71 + } else {
72 + $searchInput.blur();
73 + $searchInput.val("");
74 + gitbook.sidebar.filter(null);
75 + }
76 + }
77 +
78 + // Recover current search when page changed
79 + function recoverSearch() {
80 + var keyword = gitbook.storage.get("keyword", "");
81 +
82 + createForm(keyword);
83 +
84 + if (keyword.length > 0) {
85 + if(!isSearchOpen()) {
86 + toggleSearch();
87 + }
88 + gitbook.sidebar.filter(_.pluck(search(keyword), "path"));
89 + }
90 + };
91 +
92 +
93 + gitbook.events.bind("start", function(config) {
94 + // Pre-fetch search index and create the form
95 + fetchIndex();
96 + createForm();
97 +
98 + // Type in search bar
99 + $(document).on("keyup", ".book-search input", function(e) {
100 + var key = (e.keyCode ? e.keyCode : e.which);
101 + var q = $(this).val();
102 +
103 + if (key == 27) {
104 + e.preventDefault();
105 + toggleSearch(false);
106 + return;
107 + }
108 + if (q.length == 0) {
109 + gitbook.sidebar.filter(null);
110 + gitbook.storage.remove("keyword");
111 + } else {
112 + var results = search(q);
113 + gitbook.sidebar.filter(
114 + _.pluck(results, "path")
115 + );
116 + gitbook.storage.set("keyword", q);
117 + }
118 + });
119 +
120 + // Create the toggle search button
121 + gitbook.toolbar.createButton({
122 + icon: 'fa fa-search',
123 + label: 'Search',
124 + position: 'left',
125 + onClick: toggleSearch
126 + });
127 +
128 + // Bind keyboard to toggle search
129 + gitbook.keyboard.bind(['f'], toggleSearch)
130 + });
131 +
132 + gitbook.events.bind("page.change", recoverSearch);
133 +});
134 +
135 +
1 +require(["gitbook", "lodash"], function(gitbook, _) {
2 + var SITES = {
3 + 'facebook': {
4 + 'label': 'Facebook',
5 + 'icon': 'fa fa-facebook',
6 + 'onClick': function(e) {
7 + e.preventDefault();
8 + window.open("http://www.facebook.com/sharer/sharer.php?s=100&p[url]="+encodeURIComponent(location.href));
9 + }
10 + },
11 + 'twitter': {
12 + 'label': 'Twitter',
13 + 'icon': 'fa fa-twitter',
14 + 'onClick': function(e) {
15 + e.preventDefault();
16 + window.open("http://twitter.com/home?status="+encodeURIComponent(document.title+" "+location.href));
17 + }
18 + },
19 + 'google': {
20 + 'label': 'Google+',
21 + 'icon': 'fa fa-google-plus',
22 + 'onClick': function(e) {
23 + e.preventDefault();
24 + window.open("https://plus.google.com/share?url="+encodeURIComponent(location.href));
25 + }
26 + },
27 + 'weibo': {
28 + 'label': 'Weibo',
29 + 'icon': 'fa fa-weibo',
30 + 'onClick': function(e) {
31 + e.preventDefault();
32 + window.open("http://service.weibo.com/share/share.php?content=utf-8&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title));
33 + }
34 + },
35 + 'instapaper': {
36 + 'label': 'Instapaper',
37 + 'icon': 'fa fa-instapaper',
38 + 'onClick': function(e) {
39 + e.preventDefault();
40 + window.open("http://www.instapaper.com/text?u="+encodeURIComponent(location.href));
41 + }
42 + },
43 + 'vk': {
44 + 'label': 'VK',
45 + 'icon': 'fa fa-vk',
46 + 'onClick': function(e) {
47 + e.preventDefault();
48 + window.open("http://vkontakte.ru/share.php?url="+encodeURIComponent(location.href));
49 + }
50 + }
51 + };
52 +
53 +
54 +
55 + gitbook.events.bind("start", function(e, config) {
56 + var opts = config.sharing;
57 +
58 + // Create dropdown menu
59 + var menu = _.chain(opts.all)
60 + .map(function(id) {
61 + var site = SITES[id];
62 +
63 + return {
64 + text: site.label,
65 + onClick: site.onClick
66 + };
67 + })
68 + .compact()
69 + .value();
70 +
71 + // Create main button with dropdown
72 + if (menu.length > 0) {
73 + gitbook.toolbar.createButton({
74 + icon: 'fa fa-share-alt',
75 + label: 'Share',
76 + position: 'right',
77 + dropdown: [menu]
78 + });
79 + }
80 +
81 + // Direct actions to share
82 + _.each(SITES, function(site, sideId) {
83 + if (!opts[sideId]) return;
84 +
85 + gitbook.toolbar.createButton({
86 + icon: site.icon,
87 + label: site.text,
88 + position: 'right',
89 + onClick: site.onClick
90 + });
91 + });
92 + });
93 +});
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
1 +### 1. Markdown: Syntax
2 +* [MarkDown中文网](http://www.markdown.cn/ "MarkDown中文网")
3 +
4 +### 2. 解决ios设备页面滚动条卡顿 ###
5 +* CSS
6 +
7 + overflow: auto;
8 + -webkit-overflow-scrolling: touch;
9 +### 3. 单行文本溢出显示省略号(...) ###
10 +* CSS
11 +
12 + overflow: hidden;
13 + text-overflow: ellipsis;// 显示省略符号来代表被修剪的文本。
14 + white-space: nowrap;// 文本不会换行, 在同一行上继续,直到遇到 <br> 标签为止。
15 +### 4. 多行文本溢出显示省略号(...) ###
16 +* CSS
17 +
18 + overflow : hidden;
19 + text-overflow: ellipsis;
20 + -webkit-line-clamp: 2; // 限制文本行数2行(webkit私有属性)
21 + display: -webkit-box;
22 + -webkit-box-orient: vertical;
23 +### 5. 手机软键盘遮挡input ###
24 +1. 方案一
25 + * JS
26 +
27 + $('INPUT').focus(function () {
28 + var SCROLLY = 100;
29 + var TIMER_NAME = 500; // focus事件中500ms后进行判断
30 + var MAX_SCROLL = 9999; // 越大越好
31 + setTimeout(function () {
32 + if (window.scrollY < SCROLLY) {
33 + window.scrollTo(0, MAX_SCROLL);
34 + }
35 + }, TIMER_NAME)
36 + })
37 +
38 +
39 +2. 方案二
40 + * JS
41 +
42 + var setScroll = function(obj){
43 + var ua = navigator.userAgent;
44 + if(ua.match(/(iPhone|iPod|iPad|iPhone\s+Simulator)/i)){
45 + setTimeout(function () {
46 + obj.scrollIntoViewIfNeeded(); //obj指元素本身
47 + }, 500)
48 + }
49 + };
50 + //只在当前元素在视窗的可见范围内不可见的情况下,才滚动浏览器窗口或容器元素,最终让当前元素可见。如果当前元素在视窗中可见,这个方法不做任何处理。如果将可选参数alignCenter设置为true,则表示尽量将元素显示在视窗中部(垂直方向)------Safari、Chrome实现了这个方法
51 +
52 + * 扩展
53 +
54 + scrollIntoView(alignWithTop);// 滚动浏览器窗口或容器元素,以便在当前视窗的可见范围看见当前元素。如果alignWithTop为true,或者省略它,窗口会尽可能滚动到自身顶部与元素顶部平齐。-------目前各浏览器均支持
55 +
56 + scrollByLines(lineCount);// 将元素的内容滚动指定的行数的高度,lineCount的值可以为正值或是负值。---Safari、Chrome实现了这个方法
57 +
58 + scrollByPages(pageCount);// 将元素的内容滚动指定的页面的高度,具体高度由元素的高度决定。---Safari、Chrome实现了这个方法
59 +### 6. 禁止移动端页面的拷贝功能 ###
60 +* CSS
61 +
62 + *{
63 + -webkit-touch-callout:none; /*系统默认菜单被禁用*/
64 + -webkit-user-select:none; /*webkit浏览器*/
65 + -khtml-user-select:none; /*早期浏览器*/
66 + -moz-user-select:none;/*火狐*/
67 + -ms-user-select:none; /*IE10*/
68 + user-select:none;
69 + }
70 +
71 + * *IE6-9不支持user-select:none属性,但支持使用标签属性 onselectstart="return false";*
72 + * *在添加完上述代码后,在IOS 上会有问题的,input 框无法正常输入了内容了,添加如下样式*
73 +
74 + input {
75 + -webkit-user-select:auto; /*webkit浏览器*/
76 + }
77 +### 7. css模拟'<' '>'符号 ###
78 +* HTML && CSS
79 +
80 + <span style='display: inline-block;width: 10px;height: 10px;border-top: 2px solid #ddd;border-left: 2px solid #ddd;transform: rotate(-45deg);'></span>
81 +### 8. css模拟三角
82 +* HTML && CSS
83 +
84 + <div style="width: 0;height: 0;border: 10px solid transparent;top: 5px;border-left-color: #ddd"></div>
85 +### 9. 根据设备宽度,设置页面字体大小
86 +* JS
87 +
88 + (function (doc, win) {
89 + var docEl = doc.documentElement,
90 + resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
91 + recalc = function () {
92 + var clientWidth = docEl.clientWidth;
93 + if (!clientWidth) return;
94 + docEl.style.fontSize = 10 * (clientWidth / 320) + 'px';
95 + };
96 + if (!doc.addEventListener) return;
97 + win.addEventListener(resizeEvt, recalc, false);
98 + doc.addEventListener('DOMContentLoaded', recalc, false);
99 + })(document, window);
100 +### 10. 各类元标签
101 +* 设置编码信息 
102 +
103 + <meta http-equiv="Content-Type" Content="text/html; Charset=utf-8" /> 
104 +* 设置语言 
105 +
106 + <meta http-equiv="Content-Language" Content="zh-CN" /> 
107 +* 设置重定向
108 +
109 + <meta http-equiv="Refresh" Content="15; Url=http://www.baidu.com" /> 
110 +* 设置缓存时间 
111 +
112 + <meta http-equiv="Expires" Content="Web, 26 Jun 2015 18:21:57 GMT" /> 
113 +* 不使用缓存 
114 +
115 + <meta http-equiv="Pragma" Content="No-cach" /> 
116 +* 设置关键字 
117 +
118 + <meta name="Keywords" Content="key1,key2,..." /> 
119 +* 设置描述信息 
120 +
121 + <meta name="Description" Content="description abc" /> 
122 +* 设置对搜索引擎抓取 
123 +
124 + <meta name="Robots" Content="All|None|Index|Noindex|Follow|Nofollow" />
125 +* 设置可视区域 
126 +
127 + <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />  
128 +* 针对浏览器使用
129 +
130 + * 国产浏览器内核选择
131 +
132 + <meta name="renderer" content="webkit|ie-comp|ie-stand"> 
133 + * 使用最新版的ie浏览器,或者chrome
134 +
135 + <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
136 + * 针对手持设备优化,主要是针对一些老的不识别viewport的浏览器,比如黑莓
137 +
138 + <meta name="HandheldFriendly" content="true">
139 + * 微软的老式浏览器
140 +
141 + <meta name="MobileOptimized" content="320"> 
142 + * uc强制竖屏
143 +
144 + <meta name="screen-orientation" content="portrait"> 
145 + * QQ强制竖屏
146 +
147 + <meta name="x5-orientation" content="portrait"> 
148 + * UC强制全屏
149 +
150 + <meta name="full-screen" content="yes"> 
151 + * QQ强制全屏
152 +
153 + <meta name="x5-fullscreen" content="true">
154 + * UC应用模式
155 +
156 + <meta name="browsermode" content="application"> 
157 + * QQ应用模式
158 +
159 + <meta name="x5-page-mode" content="app"> 
160 + * windows phone 点击无高光
161 +
162 + <meta name="msapplication-tap-highlight" content="no"> 
163 + * 禁止转码
164 +
165 + <meta http-equiv="Cache-Control" content="no-siteapp" /> 
166 + * 禁止数字自动识别为电话号码 
167 +
168 + <meta name="format-detection" content="telephone=no" />
169 + * 禁止识别邮箱 
170 +
171 + <meta name="format-detection" content="email=no" />
172 +### 11. 金额格式化: '12345678' --> '12,345,678'
173 + var numStr = '12345678';
174 + console.log(numStr.split('').reverse().join('').replace(/(\d{3})/g,'$1,').replace(/,$/,'').split('').reverse().join(''));
175 +### 12. 移动端拖拽demo
176 +* HTML
177 +
178 + <body>
179 + <img src='homepage.svg' onclick='window.location.href="http://example.com/"' id="link">
180 + </body>
181 +* CSS
182 +
183 + html,body { height:100%; }
184 + #link { width:50px;height:50px;position: absolute;left: 0;top: 0; }
185 +* JS
186 +
187 + <script>
188 + window.onload = function(){
189 + drag('link')
190 + };
191 + function drag(obj){
192 + var block = document.getElementById(obj);
193 + var oW,oH;
194 + // 绑定touchstart事件
195 + block.addEventListener("touchstart", function(e) {
196 + var touches = e.touches[0];
197 + oW = touches.clientX - block.offsetLeft;
198 + oH = touches.clientY - block.offsetTop;
199 + //阻止页面的滑动默认事件
200 + document.addEventListener("touchmove",defaultEvent,false);
201 + },false)
202 +
203 + block.addEventListener("touchmove", function(e) {
204 + var touches = e.touches[0];
205 + var oLeft = touches.clientX - oW;
206 + var oTop = touches.clientY - oH;
207 + if(oLeft < 0) {
208 + oLeft = 0;
209 + }else if(oLeft > document.documentElement.clientWidth - block.offsetWidth) {
210 + oLeft = (document.documentElement.clientWidth - block.offsetWidth);
211 + }
212 + block.style.left = oLeft + "px";
213 + block.style.top = oTop + "px";
214 + },false);
215 + block.addEventListener("touchend",function() {
216 + document.removeEventListener("touchmove",defaultEvent,false);
217 + },false);
218 + function defaultEvent(e) {
219 + e.preventDefault();
220 + }
221 + }
222 +
223 +### 13.判断是否为苹果手机
224 + var ua = navigator.userAgent;
225 + if(ua.match(/(iPhone|iPod|iPad|iPhone\s+Simulator)/i)){
226 + alert("是iphone!")
227 + }
228 +### 14. img标签的 alt 属性和 onerror 事件
229 +* onerror 事件会在文档或图像加载过程中发生错误时被触发
230 +
231 + <img src="pic.gif" onerror="javascript:this.src='/noPic.gif';" alt="pic" />
232 +* alt属性,如果无法显示图像,浏览器将显示替代文本