这是一个旨在规范Z-BlogPHP前端代码接口而推出的框架,用于处理之前前端代码无序的局面。
代码示例:https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/ZBPJFExample/zbpjfexample.js
zbp.cookie.get(CookieKey)根据Key得到Cookie的值
zbp.cookie.set(sCookieName, sCookieValue, iExpireDays)
zbp.comment.get(文章ID, 评论页数)触发事件,获得指定的评论列表
zbp.comment.rely(评论ID)触发回复评论事件
zbp.comment.post(发送内容)触发发送评论事件。发送内容要求为Object,参数如下:
/**
* Form Data
* @name POSTFORMDATA
* @typedef {Object} PostData
* @memberOf COMMENT
* @property {string} action - Post Url
* @property {string} postid - Article ID
* @property {string} verify - Verify code
* @property {string} name - Comment user name
* @property {string} email - Comment user E-mail
* @property {string} content - Comment content
* @property {string} homepage - Comment user Website
* @property {string} replyid - Comment Parent ID
* @property {string} isajax - Return Ajax String
* @type {object}
*/
懒得写了……
zbp.plugin.on(bind / addListener)(接口名, 插件ID, 回调函数(错误, 待发送数据))
用于创建一个监听器,监听事件的发生
zbp.plugin.unbind(removeListener)(插件ID)
用于解绑一个监听器
zbp.plugin.emit(接口名, 内容)
用于传递内容到监听器
<script src="{$host}zb_system/script/require.js" type="text/javascript"></script> <script> require.config({ baseUrl: '{$host}', paths: { jquery: 'zb_system/script/jquery.min', zbp: 'zb_system/script/zblogphp' } }); require(["zbp", "jquery"], function (ZBP, jQuery) { var zbp = new ZBP({ bloghost: "{$host}", ajaxurl: "{$zbp.ajaxurl}", cookiepath: "{$zbp.cookiespath}?>", lang: { error: { 72: "{$lang['error']['72']}", 29: "{$lang['error']['29']}", 46: "{$lang['error']['46']}" } } }, jQuery); console.log(zbp); }); </script>
<script src="{$host}zb_system/script/sea.js" type="text/javascript"></script> <script> seajs.config({ base: '{$host}', alias: { jquery: 'zb_system/script/jquery.min', zbp: 'zb_system/script/zblogphp' }, debug: true }); seajs.use(["zbp", "jquery"], function (ZBP, jQuery) { var zbp = new ZBP({ bloghost: "{$host}", ajaxurl: "{php}echo $zbp->ajaxurl;{/php}", cookiepath: "{php}echo $zbp->cookiespath;{/php}?>", lang: { error: { 72: "{php}echo $lang['error']['72'];{/php}", 29: "{php}echo $lang['error']['29'];{/php}", 46: "{php}echo $lang['error']['46'];{/php}" } } }, jQuery); console.log(zbp); });
在模块中调用
define(function(require, exports, module) { var jquery = require("jquery"); var ZBP = require("zbp"); var zbp = new ZBP({ // Params... }, jquery); console.log(zbp); });
var ZBP = require("zbp");
import * as ZBP from 'zbp';