<commit_before>sb.include('forms.textarea');
sb.include('cookies');
sb.include('flashGate');
/**
@Name: sb.widget.editor
@Author: <NAME> v1.01 11/03/07 12/15/08
@Description: The surebert widget creates a live text editor.  It replaces all iframes passed to the constructor with real text editors.  if they cannot be built it replaces them with empty textareas.  The textareas have setContent and getContent methods just like real sb.widget.editor instances so that you can set and get the data in the same way.
@Param: string id The id of the iframe to replace with an editor
@Param: function onload A function which is run after the editor is created.  The 'this' in the function is the editor.
@Example:
<div id="info">
<iframe id="myEditor" ></iframe>
</div>
<script type="text/javascript">

sb.dom.onReady({
	id : '#myEditor',
	onReady : function(){
		myEditor1 = new sb.widget.editor('#myEditor', function(){
			this.dataIn('hello world');
		});
	}
});

</script>
*/

sb.widget.editor = function(id, onload){
	
	this.box = sb.$(id);
	this.box.className ='editor';
	
	this.box.frameBorder=0; //ie bug not working
	this.box.style.backgroundColor='white'; //ff needs bgcolor
	
	this.document = this.getReference(this.box.id);
	
	var toolbar = this.makeToolBar();
	
	this.editor = {
		
		numRules : 1,
		keyup : [],
		document :this.document,
		id : this.box.id,
		box : this.box,
		iframe : document.getElementById(this.box.id).contentWindow,
		dataOut : this.dataOut,
		dataIn : this.dataIn,
		basicOnly : 0,
		textarea :  this.createTextArea(),
		//textarea :  this.createTextArea(),
		toolbar : toolbar,
		getSelection : function(){
			var selection ='';
			if(this.document.selection){
				var range = this.document.selection.createRange();
				 selection= range.text;
			} else if(this.document.getSelection){
				selection =  this.document.getSelection();
			} 
			return selection;
		},
		addTags : function(beginTag, endTag){
			var selection;
			if(this.document.selection){
				var range = this.document.selection.createRange();
				 selection= range.text;
				 range.pasteHTML(beginTag+selection+endTag);
			} else if(this.document.getSelection){
				selection = this.document.getSelection();
				this.document.execCommand('inserthtml', false, beginTag+selection+endTag);
			} 
		},
		replaceSelection : function(newText){
			var selection;
			if(this.document.selection){
				var range = this.document.selection.createRange();
				 selection= range.text;
				 range.pasteHTML(newText);
			} else if(this.document.getSelection){
				selection = this.document.getSelection();
				this.document.execCommand('inserthtml', false, newText);
			} 
		}
		
	};
	
	var editor = this.editor;
	this.makeEditable();

	//set up the stylesheets for the editor and import any global ones defined in sb.widget.editor.styleSheets array
	var styleSheets = '@import "/css/sb_editor.css";';
	sb.widget.editor.styleSheets.forEach(function(v){
		styleSheets +="\n"+'@import "'+v+'";';
	});
	
	this.editor.document.open();
	this.editor.document.write('<html><head><style type="text/css">'+styleSheets+'</style></head><body></body></html>');
	this.editor.document.close();
	
	sb.events.add(this.document, 'keyup', function(){
	
		editor.keyup.forEach(function(v){
			if(typeof v=='function'){
				v.call(editor);
			}
		});
		 sb.cookies.set(editor.id, this.body.innerHTML);
	});
	
	/*
	var t=this;
	sb.events.add(this.document, 'keydown', function(e){
	
		e = e || editor.iframe.event;
		
		if(typeof t.onkeydown == 'function'){
			t.onkeydown.call(editor, e);
		}

	});
	*/
	this.editor.textarea.appendBefore(this.box);
	
	if(typeof onload== 'function'){
		onload.call(this);
	}
};

sb.widget.editor.styleSheets = [];
sb.widget.editor.plugins =[];

/**
@Name: sb.widget.editor.buttons
@Description: These booleen values toggle the editor buttons on or off on a global scope e.g. all editors on the page
*/
sb.widget.editor.buttons = {
	bold : 1,
	italic : 1,
	underline : 1,
	superscript : 1,
	subscript : 1,
	strikethrough : 1,
	horizontalRule : 1,
	link : 1,
	unorderedList : 1,
	orderedList : 1,
	redo : 1,
	undo : 1,
	clearFormat : 1,
	viewSource : 1,
	restore :1
};

/**
@Name: sb.widget.editor.prototype
@Description: THese are the properties associated with every sb.widget.editor instance
*/
sb.widget.editor.prototype = {
	typeOf : function(){
		return 'sb.widget.editor';
	},
	
	basicOnly : function(){
		this.editor.basicOnly =1;	
	},
	
	dataIn : function(str){
		
		if(typeof this.value !='undefined'){
			this.value = str;
		} else if(typeof this.document.body !='undefined'){
			var t=this;
			//changed this part to make it pass validation may have caused problem
			var interval = window.setInterval(function(){
				try{
					t.document.body.innerHTML = str;
				} catch(e){
					return;
				}
				window.clearInterval(interval);
			}, 10);
		
			
		}
	},
	
	dataOut : function(){
		var str ='';
		if(typeof this.value !='undefined'){
			str= this.value;
		} else if(typeof this.document.body.innerHTML !='undefined'){
		
			 str= this.document.body.innerHTML;
		}
		
		return str.parseHTML(this.basicOnly);
	},
	
	getReference : function(id){
		if (document.getElementById(id).contentDocument){
			return document.getElementById(id).contentDocument;
		} else {
			return document.frames[id].document;
		}
	},
	<commit_msg>returning editor after it is created<commit_after>sb.include('forms.textarea');
sb.include('cookies');
sb.include('flashGate');
/**
@Name: sb.widget.editor
@Author: <NAME> v1.01 11/03/07 12/15/08
@Description: The surebert widget creates a live text editor.  It replaces all iframes passed to the constructor with real text editors.  if they cannot be built it replaces them with empty textareas.  The textareas have setContent and getContent methods just like real sb.widget.editor instances so that you can set and get the data in the same way.
@Param: string id The id of the iframe to replace with an editor
@Param: function onload A function which is run after the editor is created.  The 'this' in the function is the editor.
@Example:
<div id="info">
<iframe id="myEditor" ></iframe>
</div>
<script type="text/javascript">

sb.dom.onReady({
	id : '#myEditor',
	onReady : function(){
		myEditor1 = new sb.widget.editor('#myEditor', function(){
			this.dataIn('hello world');
		});
	}
});

</script>
*/

sb.widget.editor = function(id, onload){
	
	this.box = sb.$(id);
	this.box.className ='editor';
	
	this.box.frameBorder=0; //ie bug not working
	this.box.style.backgroundColor='white'; //ff needs bgcolor
	
	this.document = this.getReference(this.box.id);
	
	var toolbar = this.makeToolBar();
	
	this.editor = {
		
		numRules : 1,
		keyup : [],
		document :this.document,
		id : this.box.id,
		box : this.box,
		iframe : document.getElementById(this.box.id).contentWindow,
		dataOut : this.dataOut,
		dataIn : this.dataIn,
		basicOnly : 0,
		textarea :  this.createTextArea(),
		//textarea :  this.createTextArea(),
		toolbar : toolbar,
		getSelection : function(){
			var selection ='';
			if(this.document.selection){
				var range = this.document.selection.createRange();
				 selection= range.text;
			} else if(this.document.getSelection){
				selection =  this.document.getSelection();
			} 
			return selection;
		},
		addTags : function(beginTag, endTag){
			var selection;
			if(this.document.selection){
				var range = this.document.selection.createRange();
				 selection= range.text;
				 range.pasteHTML(beginTag+selection+endTag);
			} else if(this.document.getSelection){
				selection = this.document.getSelection();
				this.document.execCommand('inserthtml', false, beginTag+selection+endTag);
			} 
		},
		replaceSelection : function(newText){
			var selection;
			if(this.document.selection){
				var range = this.document.selection.createRange();
				 selection= range.text;
				 range.pasteHTML(newText);
			} else if(this.document.getSelection){
				selection = this.document.getSelection();
				this.document.execCommand('inserthtml', false, newText);
			} 
		}
		
	};
	
	var editor = this.editor;
	this.makeEditable();

	//set up the stylesheets for the editor and import any global ones defined in sb.widget.editor.styleSheets array
	var styleSheets = '@import "/css/sb_editor.css";';
	sb.widget.editor.styleSheets.forEach(function(v){
		styleSheets +="\n"+'@import "'+v+'";';
	});
	
	this.editor.document.open();
	this.editor.document.write('<html><head><style type="text/css">'+styleSheets+'</style></head><body></body></html>');
	this.editor.document.close();
	
	sb.events.add(this.document, 'keyup', function(){
	
		editor.keyup.forEach(function(v){
			if(typeof v=='function'){
				v.call(editor);
			}
		});
		 sb.cookies.set(editor.id, this.body.innerHTML);
	});
	
	/*
	var t=this;
	sb.events.add(this.document, 'keydown', function(e){
	
		e = e || editor.iframe.event;
		
		if(typeof t.onkeydown == 'function'){
			t.onkeydown.call(editor, e);
		}

	});
	*/
	this.editor.textarea.appendBefore(this.box);
	
	if(typeof onload== 'function'){
		onload.call(this);
	}
	
	return this;
};

sb.widget.editor.styleSheets = [];
sb.widget.editor.plugins =[];

/**
@Name: sb.widget.editor.buttons
@Description: These booleen values toggle the editor buttons on or off on a global scope e.g. all editors on the page
*/
sb.widget.editor.buttons = {
	bold : 1,
	italic : 1,
	underline : 1,
	superscript : 1,
	subscript : 1,
	strikethrough : 1,
	horizontalRule : 1,
	link : 1,
	unorderedList : 1,
	orderedList : 1,
	redo : 1,
	undo : 1,
	clearFormat : 1,
	viewSource : 1,
	restore :1
};

/**
@Name: sb.widget.editor.prototype
@Description: THese are the properties associated with every sb.widget.editor instance
*/
sb.widget.editor.prototype = {
	typeOf : function(){
		return 'sb.widget.editor';
	},
	
	basicOnly : function(){
		this.editor.basicOnly =1;	
	},
	
	dataIn : function(str){
		
		if(typeof this.value !='undefined'){
			this.value = str;
		} else if(typeof this.document.body !='undefined'){
			var t=this;
			//changed this part to make it pass validation may have caused problem
			var interval = window.setInterval(function(){
				try{
					t.document.body.innerHTML = str;
				} catch(e){
					return;
				}
				window.clearInterval(interval);
			}, 10);
		
			
		}
	},
	dataOut : function(){
		var str ='';
		if(typeof this.value !='undefined'){
			str= this.value;
		} else if(typeof this.document.body.innerHTML !='undefined'){
		
			 str= this.document.body.innerHTML;
		}
		
		return str.parseHTML(this.basicOnly);
	},
	
	getReference : function(id){
		if (document.getElementById(id).contentDocument){
			return document.getElementById(id).contentDocument;
		} else {
			return document.frames[id].document;
		}
	},
	
{'fraction_non_alphanumeric': 0.14851855313580709, 'fraction_numerical': 0.006916534255537901, 'mean_word_length': 3.749223257878384, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '608017', 'n_tokens_mistral': 3988, 'n_tokens_neox': 3454, 'n_words': 843}