目录

Z-BlogPHP JavaScript Framework

介绍

这是一个旨在规范Z-BlogPHP前端代码接口而推出的框架,用于处理之前前端代码无序的局面。

代码示例:https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/ZBPJFExample/zbpjfexample.js

函数说明

get

zbp.cookie.get(CookieKey)
根据Key得到Cookie的值

set

zbp.cookie.set(sCookieName, sCookieValue, iExpireDays)

2. comment

get

zbp.comment.get(文章ID, 评论页数)
触发事件,获得指定的评论列表

reply

zbp.comment.rely(评论ID)
触发回复评论事件

post

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}
             */

3. userinfo

output

save

saveFromHtml

懒得写了……

4. plugin

on

zbp.plugin.on(bind / addListener)(接口名, 插件ID, 回调函数(错误, 待发送数据))

用于创建一个监听器,监听事件的发生

unbind

zbp.plugin.unbind(removeListener)(插件ID)

用于解绑一个监听器

emit

zbp.plugin.emit(接口名, 内容)

用于传递内容到监听器

自带事件接口列表

请阅读示例: https://github.com/zblogcn/zblogphp/blob/0ee32c1f425c50c261c0e7ccddef6ebd8e20cd63/zb_users/plugin/ZBPJFExample/zbpjfexample.js

模块化调用

AMD

<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>

CMD

<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);
});

CommonJS

var ZBP = require("zbp");

ES6 Import

import * as ZBP from 'zbp';