Skip to content

Commit

Permalink
Merge branch 'master' of github.com:fex-team/fis3
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop committed Dec 28, 2015
2 parents 0507ffd + 088497d commit d6f2b6e
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 4 deletions.
19 changes: 17 additions & 2 deletions doc/docs/api/config-glob.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FIS3 中支持的 glob 规则,FIS3 使用 [node-glob](https://github.com/isaac

这里把常用的一些用法做说明。

- `*` 匹配多个除了 `/` 以外的字符
- `*` 匹配0或多个除了 `/` 以外的字符
- `?` 匹配单个除了 `/` 以外的字符
- `**` 匹配多个字符**包括 `/`**
- `{}` 可以让多个规则用 `,` 逗号分隔,起到`或者`的作用
Expand All @@ -22,7 +22,6 @@ FIS3 中支持的 glob 规则,FIS3 使用 [node-glob](https://github.com/isaac
`/foo/**/*.js` 是命中所有子目录以及其子目录下面的所有 js 文件,不包含当前目录下面的 js 文件。
如果需要命中 `foo` 目录下面以及所有其子目录下面的 js 文件,请使用 `/foo/**.js`


### 扩展的规则

1. 假设匹配 `widget` 目录下以及其子目录下的所有 js 文件,使用 `node-glob` 需要这么写
Expand Down Expand Up @@ -53,6 +52,22 @@ FIS3 中支持的 glob 规则,FIS3 使用 [node-glob](https://github.com/isaac
release: '/b/$1'
});
```
### 捕获分组
使用 `node-glob` 捕获的分组,可以用于其他属性的设定,如 `release`, `url`, `id` 等。使用的方式与正则替换类似,我们可以用 $1, $2, $3 来代表响应的捕获分组。其中 $0 代表的是 match 到的整个字符串。
```js
fis.match('/a/(**.js)', {
release: '/b/$1' // $1 代表 (**.js) 匹配的内容
});
```
```js
fis.match('/a/(**.js)', {
release: '/b/$0' // $0 代表 /a/(**.js) 匹配的内容
});
```
### 特殊用法(类 css 伪类)
Expand Down
6 changes: 5 additions & 1 deletion doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,15 @@ <h3 class="text-c"><a href="#">灵活控制资源加载</a></h3>
<link rel="import" href="/widget/tongji.html?__inline">

<script type="text/javascript" src="./static/js/jquery.min.js"></script>
<script type="text/javascript" src="./static/js/jquery.cookie.js"></script>
<script type="text/javascript" src="./static/js/slider.js"></script>
<script type="text/javascript">
$(function() {
$('#slider').cbpContentSlider();
if ($.cookie("isInternal") === "1") {
$(".nav-left").append($("<a></a>").attr("href", "baidu://message?appid=wJUNQ3gXdlgOsRPajPapUQ").addClass("nav-link").text("在线客服"));
}
});
</script>
</body>
</html>
</html>
6 changes: 6 additions & 0 deletions doc/page/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<![endif]-->

<script src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/jquery.cookie.js"></script>
<script src="/static/js/scrollspy.js"></script>
</head>

Expand Down Expand Up @@ -158,6 +159,11 @@
}
lastScrollTop = st;
});


if ($.cookie("isInternal") === "1") {
$(".nav-left").append($("<a></a>").attr("href", "baidu://message?appid=wJUNQ3gXdlgOsRPajPapUQ").addClass("nav-link").text("在线客服"));
}
}());
</script>
<link rel="import" href="/widget/tongji.html?__inline">
Expand Down
117 changes: 117 additions & 0 deletions doc/static/js/jquery.cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*!
* jQuery Cookie Plugin v1.4.1
* https://github.com/carhartl/jquery-cookie
*
* Copyright 2013 Klaus Hartl
* Released under the MIT license
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// CommonJS
factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {

var pluses = /\+/g;

function encode(s) {
return config.raw ? s : encodeURIComponent(s);
}

function decode(s) {
return config.raw ? s : decodeURIComponent(s);
}

function stringifyCookieValue(value) {
return encode(config.json ? JSON.stringify(value) : String(value));
}

function parseCookieValue(s) {
if (s.indexOf('"') === 0) {
// This is a quoted cookie as according to RFC2068, unescape...
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
}

try {
// Replace server-side written pluses with spaces.
// If we can't decode the cookie, ignore it, it's unusable.
// If we can't parse the cookie, ignore it, it's unusable.
s = decodeURIComponent(s.replace(pluses, ' '));
return config.json ? JSON.parse(s) : s;
} catch(e) {}
}

function read(s, converter) {
var value = config.raw ? s : parseCookieValue(s);
return $.isFunction(converter) ? converter(value) : value;
}

var config = $.cookie = function (key, value, options) {

// Write

if (value !== undefined && !$.isFunction(value)) {
options = $.extend({}, config.defaults, options);

if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setTime(+t + days * 864e+5);
}

return (document.cookie = [
encode(key), '=', stringifyCookieValue(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}

// Read

var result = key ? undefined : {};

// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all. Also prevents odd result when
// calling $.cookie().
var cookies = document.cookie ? document.cookie.split('; ') : [];

for (var i = 0, l = cookies.length; i < l; i++) {
var parts = cookies[i].split('=');
var name = decode(parts.shift());
var cookie = parts.join('=');

if (key && key === name) {
// If second argument (value) is a function it's a converter...
result = read(cookie, value);
break;
}

// Prevent storing a cookie that we couldn't decode.
if (!key && (cookie = read(cookie)) !== undefined) {
result[name] = cookie;
}
}

return result;
};

config.defaults = {};

$.removeCookie = function (key, options) {
if ($.cookie(key) === undefined) {
return false;
}

// Must not alter options, thus extending a fresh object...
$.cookie(key, '', $.extend({}, options, { expires: -1 }));
return !$.cookie(key);
};

}));
6 changes: 5 additions & 1 deletion test/install/common/page/layout.tpl
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
<title>{%$title%}</title>
{%block name="block_head_static"%}{%/block%}
{%/head%}
{%* 使用body插件替换body标签,主要为可控制加载JS资
{%* 使用body插件替换body标签,主要为可控制加载JS资源 *%}
{%body%}
{%block name="content"%}{%/block%}
{%/body%}
{%/html%}

0 comments on commit d6f2b6e

Please sign in to comment.