layui扩展第三方模块_模块化前端框架的Layui使用(二)之引进第三方jQuery插件作为layui扩展模块...

其实模块化前端框架的Layui使用(一)之初步入门的扩展一个Layui模块部分已经讲到相关内容。现在的话,我们具体来看看究竟怎样配置。就拿jquery.cookie.js作为例子吧,因为刚好那时我项目需要用到cookie这个js库,但我又不想说另外又引用jquery.cookie.js,想尽量就是风格一致,统一采用layui这种的模块化的使用。

首先我先把query.cookie.js下载下来。

query.cookie.js的源码

/*!

* 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) : v

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值