RichText_wev8.js 2.28 KB
if(typeof(MEC_NS) == 'undefined'){
	MEC_NS = {};
}

MEC_NS.RichText = function(type, id, mecJson){
	this.type = type;
	if(!id){
		id = new UUID().toString();
	}
	this.id = id;
	if(!mecJson){
		mecJson = {};
	}
	this.ckeditor = {};
	this.mecJson = mecJson;
	var that = this;
	require(['mec'], function(mec){
		that.remark = function(){
			return mec.remark(that.mecJson.text);
        };
	});
}

/*获取id。 必需的方法*/
MEC_NS.RichText.prototype.getID = function(){
	return this.id;
};

/*获取设计的html, 页面上怎么显示控件完全依赖于此方法。 必需的方法*/
MEC_NS.RichText.prototype.getDesignHtml = function(){
	return getDesignHtml(this);
};

/*获取构建属性编辑窗体的html,添加和单击控件后会调用此方法,由此方法去构建属性编辑窗体。 必需的方法*/
MEC_NS.RichText.prototype.getAttrDlgHtml = function(){
	var theId = this.id;
	
	var htm = "<div id=\"MADH_"+theId+"\" style=\"height: inherit;\">";
		htm += "<div id=\"text_"+theId+"\" class=\"content editor\" style=\"display: none;\"></div>";
		htm += "</div>";
	
	return htm;
};


/*构建属性编辑窗体完成后调用此方法,主要用于一些必须要使用js对页面进行后置操作时,无需要此方法可至空。 不必需的方法,有此方法系统自动调用*/
MEC_NS.RichText.prototype.afterAttrDlgBuild = function(){
	var that = this,
		theId = this.id;
	var mecHandler = MECHandlerPool.getHandler(theId);
	
	require(['ckEditor'], function(CKEDITOR) {
	    if(_userLanguage == '8'){
	    	CKEDITOR.config.language = 'en';
		} else if(_userLanguage == '9'){
	    	CKEDITOR.config.language = 'zh';
		} else {
	    	CKEDITOR.config.language = 'zh-cn';
		}
        var editorElement = CKEDITOR.document.getById( 'text_' + theId );
        editorElement.setHtml(that.mecJson.text || '');
        that.ckeditor = CKEDITOR.replace( 'text_' + theId );
        that.ckeditor.on('change', function(){
        	mecHandler.autobind.update();
		});
	});
};

/*获取JSON*/
MEC_NS.RichText.prototype.getMecJson = function(){
	var theId = this.id;
	
	this.mecJson["id"] = theId;
	this.mecJson["mectype"] = this.type;
	
	var $attrContainer = $("#MADH_"+theId);
	if($attrContainer.length > 0){
		this.ckeditor.getData && (this.mecJson["text"] = this.ckeditor.getData());
	}
	return this.mecJson;
};