⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bs_wysiwygnew.class.js_

📁 在线电子表格SpreadSheet 在线电子表格SpreadSheet
💻 JS_
📖 第 1 页 / 共 5 页
字号:
			return;
		} else {
			switch (this.editareaOnPaste) {
				case 1:
					alert('Sorry, no pasting allowed.');
					//don't break!
				case 0:
					event.returnValue = false;
					return;
					break;
				case 5:
					event.returnValue = true;
					return;
					break;
				default: 
					//need to check if there are tags or not.
					//try {
					var clipValOrig  = window.clipboardData.getData("Text");
					var clipValStrip = bs_stripTags(clipValOrig);
					if ((clipValOrig == clipValStrip) || (this.editareaOnPaste == 2)) {
						//well no tags. or silent insert. that's easy.
						event.returnValue = true;
						return;
					} else {
						switch (this.editareaOnPaste) {
							case 3: //alert that tags are stripped
								alert("Formatting tags have been removed from the clipboard.");
								window.clipboardData.setData("Text", clipValStrip);
								event.returnValue = true;
								break;
							case 4: //ask what he wants:
								var status = confirm("The pasted content includes formatting tags. Click OK to paste your content with them. Click cancel to have them removed.");
								if (!status) window.clipboardData.setData("Text", clipValStrip);
								event.returnValue = true;
								break;
						}
						//now set the orig value back into the clipboard, the user may want to use it 
						//somewhere else. me, i'd get angry if my clipboard got overwritten.
						//window.clipboardData.setData("Text", clipValOrig);
					}
			}
		}
	}
	
	
	/**
	* creates/updates the link at the current position/for the current selection..
	* 
	* param paramObj: array or object that can have the fields 
	*   'href', 'target', 'name', 'title', 'id', 'class', 'style'
	* 
	* if 'href' is empty then no link will be added, and an existing link will be dropped.
	* 
	* @access public
	* @param  obj paramObj (see above)
	*/
	this.createLink = function(paramObj) {
		var propArr   = new Array('href', 'target', 'name', 'title', 'id', 'class', 'style');
		var tempRange = this.workingDoc.selection.createRange();
		
		if ((this.dataType == 'whtml') && !this._inHtmlMode) {
			if (bs_isEmpty(paramObj.href)) {
				tempRange.execCommand('UnLink', false, null);
				return;
			}
			
			var tempElm = findWrappingElement('A', tempRange);
			
			if (tempElm == false) {
				if (bs_isEmpty(paramObj['value'])) { //got no value from the user.
					if (tempRange.htmlText == '') {
						tempRange.expand('word'); //expand it
					}
					//if the last selected char is a space, we remove it from the selection.
					//because expand() likes to select the space after a word too. very stupid.
					var htmlText = tempRange.htmlText;
					if (typeof(htmlText) == 'string') { //could be an object.
						if (htmlText.substr(htmlText.length -1) == ' ') {
							tempRange.moveEnd('character', -1)
						}
					}
					paramObj['value'] = tempRange.htmlText;
				}
				
				tempRange.execCommand('CreateLink', false, paramObj.href); 
				tempElm = findWrappingElement('A', tempRange);
			}
			
			if (tempElm == false) {
				if (bs_isEmpty(paramObj['value'])) { //got no value from the user.
					if (tempRange.htmlText == '') {
						tempRange.expand('word'); //expand it
					}
					//if the last selected char is a space, we remove it from the selection.
					//because expand() likes to select the space after a word too. very stupid.
					var htmlText = tempRange.htmlText;
					if (typeof(htmlText) == 'string') { //could be an object.
						if (htmlText.substr(htmlText.length -1) == ' ') {
							tempRange.moveEnd('character', -1)
						}
					}
					paramObj['value'] = tempRange.htmlText;
				}
				
				var code = '<a';
				for (var i=0; i<propArr.length; i++) {
					if (!bs_isEmpty(paramObj[propArr[i]])) code += ' ' + propArr[i] + '="' + paramObj[propArr[i]] + '"';
				}
				code += '>' + paramObj['value'] + '</a>';
				tempRange.pasteHTML(code);
				tempRange.select(); //does not work somehow.
			} else {
				for (var i=0; i<propArr.length; i++) {
					if (!bs_isEmpty(paramObj[propArr[i]])) tempElm.setAttribute(propArr[i], paramObj[propArr[i]]);
				}
				if (!bs_isEmpty(paramObj['value'])) tempElm.innerHTML = paramObj['value'];
			}
		} else {
			var r2 = expandSelectionToSimpleTag(tempRange, 'a');
			if (r2.text != tempRange.text) tempRange = r2;
			
			if (bs_isEmpty(paramObj.href)) {
				var code = ''; //remove link.
			} else {
				var code = '<a';
				for (var i=0; i<propArr.length; i++) {
					if (!bs_isEmpty(paramObj[propArr[i]])) code += ' ' + propArr[i] + '="' + paramObj[propArr[i]] + '"';
				}
				code += '>';
			}
			tempRange.text = code;
			tempRange.select(); //does not work somehow.
		}
	}
	
	
	/**
	* inserts an image, or, if an image is currently selected, updates it.
	* 
	* param paramObj can have the keys:
	*   'src', 'alt', 'width', 'height', 'hspace', 'vspace', 'border', 'align', 
	*   'name', 'title', 'id', 'class', 'style'
	* 
	* @access public
	* @param  object paramObj
	* @return void
	*/
	this.createImage = function(paramObj) {
		var propArr   = new Array('src', 'alt', 'width', 'height', 'hspace', 'vspace', 'border', 'align', 'name', 'title', 'id', 'class', 'style');
		var tempRange = this.workingDoc.selection.createRange();
		
		if ((this.dataType == 'whtml') && !this._inHtmlMode) {
			if (this.workingDoc.selection.type == "Control") {
		  } else {
				tempRange.execCommand('InsertImage', false, paramObj.src);
				var tempRange = this.workingDoc.selection.createRange();
			}
			
			tempElm = tempRange(0);
			
			if (tempElm != false) {
				for (var i=0; i<propArr.length; i++) {
					if (!bs_isEmpty(paramObj[propArr[i]])) tempElm.setAttribute(propArr[i], paramObj[propArr[i]]);
				}
			}
		} else {
			var r2 = expandSelectionToSimpleTag(tempRange, 'img');
			if (r2.text != tempRange.text) tempRange = r2;
			
			var code = '<img';
			for (var i=0; i<propArr.length; i++) {
				if (!bs_isEmpty(paramObj[propArr[i]])) code += ' ' + propArr[i] + '="' + paramObj[propArr[i]] + '"';
			}
			code += '>';
			tempRange.text = code;
			tempRange.select(); //does not work somehow.
		}
	}
	
	/**
	* @access public
	* @param  string hexCode (6 digit hex code)
	* @return void
	*/
	this.setFgColor = function(hexCode) {
		this.workingDoc.execCommand('ForeColor', false, hexCode);
	}
	
	
	/**
	* 
	* param option: these are allowed
	*   'Underline'
	*   'StrikeThrough'
	*   'SuperScript'
	*   'SubScript'
	* 
	* @access public
	* @param  string option (see above)
	* @param  bool b
	* @return void
	*/
	this.setFontOption = function(option, b) {
		var current = this.workingDoc.queryCommandValue(option);
		if (current && !b) {
			this.workingDoc.execCommand(option, false, false);
		} else if (!current && b) {
			this.workingDoc.execCommand(option, false, true);
		}
	}
	
	/**
	* @access public
	* @param  object paramObj
	* @return void
	*/
	this.setFont = function(paramObj) {
		if (!bs_isEmpty(paramObj.fontFace)) this.workingDoc.execCommand('FontName', false, paramObj.fontFace);
		if (!bs_isEmpty(paramObj.fontSize)) this.workingDoc.execCommand('FontSize', false, paramObj.fontSize);
		this.setFontOption('Bold',          (paramObj.fontStyle.indexOf('Bold')   != -1));
		this.setFontOption('Italic',        (paramObj.fontStyle.indexOf('Italic') != -1));
		this.setFontOption('Underline',     paramObj.underline);
		this.setFontOption('StrikeThrough', paramObj.strikeThrough);
		this.setFontOption('SuperScript',   paramObj.superScript);
		this.setFontOption('SubScript',     paramObj.subScript);
		//paramObj.upperCase;
	}
	
	/**
	* called from the windowHref, telling us that it's loaded.
	* @access public (you don't need that)
	* @return void
	*/
	this.callbackWindowHref = function() {
		var paramObj  = new Object;
		var tempRange = this.workingDoc.selection.createRange();
		if ((this.dataType == 'html') || this._inHtmlMode) {
			var r2 = expandSelectionToSimpleTag(tempRange, 'a');
			if ((r2.text != tempRange.text) && !bs_isEmpty(r2.text)) {
				r2.select();
				paramObj = bs_parseSimpleTagProps(r2.text);
				paramObj['value'] = 'ggg';
			}
		} else {
			var tempElm = findWrappingElement('A', tempRange);
			if (tempElm != false) {
				paramObj.href     = (!bs_isEmpty(tempElm.getAttribute('href')))   ? tempElm.getAttribute('href')   : '';
				paramObj.target   = (!bs_isEmpty(tempElm.getAttribute('target'))) ? tempElm.getAttribute('target') : '';
				paramObj.name     = (!bs_isEmpty(tempElm.getAttribute('name')))   ? tempElm.getAttribute('name')   : '';
				paramObj.title    = (!bs_isEmpty(tempElm.getAttribute('title')))  ? tempElm.getAttribute('title')  : '';
				paramObj.id       = (!bs_isEmpty(tempElm.getAttribute('id')))     ? tempElm.getAttribute('id')     : '';
				paramObj['class'] = (!bs_isEmpty(tempElm.getAttribute('class')))  ? tempElm.getAttribute('class')  : '';
				paramObj.style    = (!bs_isEmpty(tempElm.getAttribute('style')))  ? tempElm.getAttribute('style')  : '';
				paramObj['value'] = tempElm.innerHTML;
			} else {
				if (typeof(tempRange.text) == 'undefined') { //control range
					paramObj['value'] = tempRange.item(0).outerHTML;
				} else { //text range
					paramObj['value'] = tempRange.text;
				}
			}
		}
		return paramObj;
	}
	
	/**
	* called from the windowImage, telling us that it's loaded.
	* @access public (you don't need that)
	* @return void
	*/
	this.callbackWindowImage = function() {
		var paramObj = new Object;
		
		//try {
			var tempRange = this.workingDoc.selection.createRange();
			if (typeof(tempRange.text) == 'undefined') { //control range
				var tempElm = tempRange(0);
				if (tempElm != false) {
					paramObj.src      = (!bs_isEmpty(tempElm.getAttribute('src')))       ? tempElm.getAttribute('src')    : '';
					paramObj.alt      = (!bs_isEmpty(tempElm.getAttribute('alt')))       ? tempElm.getAttribute('alt')    : '';
					paramObj.width    = (!bs_isEmpty(tempElm.getAttribute('width')))     ? tempElm.getAttribute('width')  : '';
					paramObj.height   = (!bs_isEmpty(tempElm.getAttribute('height')))    ? tempElm.getAttribute('height') : '';
					paramObj.hspace   = (!bs_isEmpty(tempElm.getAttribute('hspace')))    ? tempElm.getAttribute('hspace') : '';
					paramObj.vspace   = (!bs_isEmpty(tempElm.getAttribute('vspace')))    ? tempElm.getAttribute('vspace') : '';
					paramObj.border   = (!bs_isEmpty(tempElm.getAttribute('border')))    ? tempElm.getAttribute('border') : '';
					paramObj.align    = (!bs_isEmpty(tempElm.getAttribute('align')))     ? tempElm.getAttribute('align')  : '';
					paramObj.name     = (!bs_isEmpty(tempElm.getAttribute('name')))      ? tempElm.getAttribute('name')   : '';
					paramObj.title    = (!bs_isEmpty(tempElm.getAttribute('title')))     ? tempElm.getAttribute('title')  : '';
					paramObj.id       = (!bs_isEmpty(tempElm.getAttribute('id')))        ? tempElm.getAttribute('id')     : '';
					paramObj['class'] = (!bs_isEmpty(tempElm.getAttribute('class')))     ? tempElm.getAttribute('class')  : '';
					paramObj.style    = (!bs_isEmpty(tempElm.getAttribute('style')))     ? tempElm.getAttribute('style')  : '';
					//style_Str
				}
			} else { //text range
				if ((this.dataType == 'html') || this._inHtmlMode) {
					var r2 = expandSelectionToSimpleTag(tempRange, 'img');
					if ((r2.text != tempRange.text) && !bs_isEmpty(r2.text)) {
						paramObj = bs_parseSimpleTagProps(r2.text);
						r2.select();
					}
				}
			}
		//} catch (e) {
		//}
		
		if (typeof(this.imageSelector[3]) != 'undefined') {
			paramObj.imageBrowser = this.imageSelector[3];
		}
		
		return paramObj;
	}
	
	/**
	* called from the windowColor, telling us that it's loaded.
	* @access public (you don't need that)
	* @return void
	*/
	this.callbackWindowColor = function() {
		var currentColor = this.workingDoc.queryCommandValue('ForeColor');
		//leading zeros are missing.
		currentColor = currentColor.toString(16);
		for (var i=6-currentColor.length; i>0; i--) {
			currentColor = '0' + '' + currentColor;
		}
		var paramObj = new Object;
		paramObj.color = currentColor;
		return paramObj;
	}
	
	/**
	* called from the windowFont, telling us that it's loaded.
	* @access public (you don't need that)
	* @return void
	*/
	this.callbackWindowFont = function() {
		var paramObj = new Object;
		paramObj.fontFace      = this.workingDoc.queryCommandValue('FontName');
		var fontStyle = new Array;
		if (this.workingDoc.queryCommandValue('Bold'))   fontStyle[fontStyle.length] = 'Bold';
		if (this.workingDoc.queryCommandValue('Italic')) fontStyle[fontStyle.length] = 'Italic';
		paramObj.fontStyle     = fontStyle.join(' ');
		paramObj.fontSize      = this.workingDoc.queryCommandValue('FontSize');
		paramObj.underline     = this.workingDoc.queryCommandValue('Underline');
		paramObj.strikeThrough = this.workingDoc.queryCommandValue('StrikeThrough');
		paramObj.superScript   = this.workingDoc.queryCommandValue('Superscript');
		paramObj.subScript     = this.workingDoc.queryCommandValue('Subscript');
		//paramObj.upperCase     = document.myForm.elements['upperCase'].checked;
		
		try {
			if (this.lastSelection.text == '') {
				this.lastSelection.expand('word'); //if the user did not select a range, only has the cursor somewhere, we expand it.
			}
			paramObj.previewText = this.lastSelection.text;
		} catch (e) {
			//doesn't matter. just nice to have.
		}
		
		return paramObj;
	}
	
	/**
	* @access public (you don't need that)
	* @param  obj btnObj (an instance of Bs_Button)
	* @return void
	*/
	this.toolbarButtonClicked = function(btnObj) {
		try {
			if (moz) {
				this.workingElm.contentWindow.focus();
			} else {
				this.workingElm.focus();
			}
		} catch (e) {
			//ugh.
		}
		
		
		switch (btnObj.action) {
      case 'Bold':
      case 'Italic':
      case 'Underline':
      case 'Undo':
      case 'Redo':
      case 'Cut':
      case 'Copy':

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -