/** * 百度应用 * @file * @since 1.2.6.1 */ /** * 插入百度应用 * @command webapp * @method execCommand * @remind 需要百度APPKey * @remind 百度应用主页: http://app.baidu.com/ * @param { Object } appOptions 应用所需的参数项, 支持的key有: title=>应用标题, width=>应用容器宽度, * height=>应用容器高度,logo=>应用logo,url=>应用地址 * @example * ```javascript * //editor是编辑器实例 * //在编辑器里插入一个“植物大战僵尸”的APP * editor.execCommand( 'webapp' , { * title: '植物大战僵尸', * width: 560, * height: 465, * logo: '应用展示的图片', * url: '百度应用的地址' * } ); * ``` */ //UE.plugins['webapp'] = function () { // var me = this; // function createInsertStr( obj, toIframe, addParagraph ) { // return !toIframe ? // (addParagraph ? '
' : '') + '
' +
// (addParagraph ? '
"
: '';
}
return {
outputRule: function(root) {
utils.each(root.getNodesByTagName("img"), function(node) {
var html;
if (node.getAttr("class") == "edui-faked-webapp") {
html = createInsertStr(
{
title: node.getAttr("title"),
width: node.getAttr("width"),
height: node.getAttr("height"),
align: node.getAttr("align"),
cssfloat: node.getStyle("float"),
url: node.getAttr("_url"),
logo: node.getAttr("_logo_url")
},
true
);
var embed = UE.uNode.createElement(html);
node.parentNode.replaceChild(embed, node);
}
});
},
inputRule: function(root) {
utils.each(root.getNodesByTagName("iframe"), function(node) {
if (node.getAttr("class") == "edui-faked-webapp") {
var img = UE.uNode.createElement(
createInsertStr({
title: node.getAttr("title"),
width: node.getAttr("width"),
height: node.getAttr("height"),
align: node.getAttr("align"),
cssfloat: node.getStyle("float"),
url: node.getAttr("src"),
logo: node.getAttr("logo_url")
})
);
node.parentNode.replaceChild(img, node);
}
});
},
commands: {
/**
* 插入百度应用
* @command webapp
* @method execCommand
* @remind 需要百度APPKey
* @remind 百度应用主页: http://app.baidu.com/
* @param { Object } appOptions 应用所需的参数项, 支持的key有: title=>应用标题, width=>应用容器宽度,
* height=>应用容器高度,logo=>应用logo,url=>应用地址
* @example
* ```javascript
* //editor是编辑器实例
* //在编辑器里插入一个“植物大战僵尸”的APP
* editor.execCommand( 'webapp' , {
* title: '植物大战僵尸',
* width: 560,
* height: 465,
* logo: '应用展示的图片',
* url: '百度应用的地址'
* } );
* ```
*/
webapp: {
execCommand: function(cmd, obj) {
var me = this,
str = createInsertStr(
utils.extend(obj, {
align: "none"
}),
false
);
me.execCommand("inserthtml", str);
},
queryCommandState: function() {
var me = this,
img = me.selection.getRange().getClosedNode(),
flag = img && img.className == "edui-faked-webapp";
return flag ? 1 : 0;
}
}
}
};
});