<commit_before>/**
 * editor_plugin_src.js
 *
 * Copyright 2009, Moxiecode Systems AB
 * Released under LGPL License.
 *
 * License: http://tinymce.moxiecode.com/license
 * Contributing: http://tinymce.moxiecode.com/contributing
 */

/* Macgirvin Aug-2010 changed from punbb to dfrn dialect */

(function() {
	tinymce.create('tinymce.plugins.BBCodePlugin', {
		init : function(ed, url) {
			var t = this, dialect = ed.getParam('bbcode_dialect', 'dfrn').toLowerCase();

			ed.onBeforeSetContent.add(function(ed, o) {
				o.content = t['_' + dialect + '_bbcode2html'](o.content);
			});

			ed.onPostProcess.add(function(ed, o) {
				if (o.set)
					o.content = t['_' + dialect + '_bbcode2html'](o.content);

				if (o.get)
					o.content = t['_' + dialect + '_html2bbcode'](o.content);
			});
		},

		getInfo : function() {
			return {
				longname : 'BBCode Plugin',
				author : 'Moxiecode Systems AB',
				authorurl : 'http://tinymce.moxiecode.com',
				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',
				version : tinymce.majorVersion + "." + tinymce.minorVersion
			};
		},

		// Private methods

		// HTML -> BBCode in DFRN dialect
		_dfrn_html2bbcode : function(s) {
			s = tinymce.trim(s);

			function rep(re, str) {

				//modify code to keep stuff intact within [code][/code] blocks
				//Waitman Gobble NO WARRANTY


				var o = new Array();
				var x = s.split("[code]");
				var i = 0;

				var si = "";
				si = x.shift();
				si = si.replace(re,str);
				o.push(si);

				for (i = 0; i < x.length; i++) {
					var no = new Array();
					var j = x.shift();
					var g = j.split("[/code]");
					no.push(g.shift());
					si = g.shift();
					si = si.replace(re,str);
					no.push(si);
					o.push(no.join("[/code]"));
				}

				s = o.join("[code]");

			};




			/* oembed */
			function _h2b_cb(match) {
				function s_h2b(data) {
						match = data;
				}
				$.ajax({
					type:"POST",
					url: 'oembed/h2b',
					data: {text: match},
					async: false,
					success: s_h2b,
					dataType: 'html'
				});
				return match;
			}
			if (s.indexOf('class="oembed')>=0){
				//alert("request oembed html2bbcode");
				s = _h2b_cb(s);
			}
			
			/* /oembed */<commit_msg>In HTML2BBCode: fetch the URL of [EMBED] using JavaScript instead of an ajax-call to a php-script. Once there actually is embedded Code in the HTML, this function is called after every single keypress. Not only is making an ajax-call every keypress bandith intensive - it also made typing hard / slow. Making a lot of JavaScript-RegExp-Computation every keypress isn't exactly great either, but still performs better.<commit_after>/**
 * editor_plugin_src.js
 *
 * Copyright 2009, Moxiecode Systems AB
 * Released under LGPL License.
 *
 * License: http://tinymce.moxiecode.com/license
 * Contributing: http://tinymce.moxiecode.com/contributing
 */

/* Macgirvin Aug-2010 changed from punbb to dfrn dialect */

(function() {
	tinymce.create('tinymce.plugins.BBCodePlugin', {
		init : function(ed, url) {
			var t = this, dialect = ed.getParam('bbcode_dialect', 'dfrn').toLowerCase();

			ed.onBeforeSetContent.add(function(ed, o) {
				o.content = t['_' + dialect + '_bbcode2html'](o.content);
			});

			ed.onPostProcess.add(function(ed, o) {
				if (o.set)
					o.content = t['_' + dialect + '_bbcode2html'](o.content);

				if (o.get)
					o.content = t['_' + dialect + '_html2bbcode'](o.content);
			});
		},

		getInfo : function() {
			return {
				longname : 'BBCode Plugin',
				author : 'Moxiecode Systems AB',
				authorurl : 'http://tinymce.moxiecode.com',
				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',
				version : tinymce.majorVersion + "." + tinymce.minorVersion
			};
		},

		// Private methods

		// HTML -> BBCode in DFRN dialect
		_dfrn_html2bbcode : function(s) {
			s = tinymce.trim(s);

			function rep(re, str) {

				//modify code to keep stuff intact within [code][/code] blocks
				//Waitman Gobble NO WARRANTY


				var o = new Array();
				var x = s.split("[code]");
				var i = 0;

				var si = "";
				si = x.shift();
				si = si.replace(re,str);
				o.push(si);

				for (i = 0; i < x.length; i++) {
					var no = new Array();
					var j = x.shift();
					var g = j.split("[/code]");
					no.push(g.shift());
					si = g.shift();
					si = si.replace(re,str);
					no.push(si);
					o.push(no.join("[/code]"));
				}

				s = o.join("[code]");

			};




			/* oembed */
			function _h2b_cb(match) {
				/*
				function s_h2b(data) {
						match = data;
				}
				$.ajax({
					type:"POST",
					url: 'oembed/h2b',
					data: {text: match},
					async: false,
					success: s_h2b,
					dataType: 'html'
				});
				*/
				
				var f, g, tof = [], tor = [];
				var find_spanc = /<span [^>]*class *= *[\"'](?:[^\"']* )*oembed(?: [^\"']*)*[\"'][^>]*>(.*?(?:<span[^>]*>(.*?)<\/span *>)*.*?)<\/span *>/ig;
				while (f = find_spanc.exec(match)) {
					var find_a = /<a([^>]* rel=[\"']oembed[\"'][^>]*)>.*?<\/a *>/ig;
					if (g = find_a.exec(f[1])) {
						var find_href = /href=[\"']([^\"']*)[\"']/ig;
						var m2 = find_href.exec(g[1]);
						if (m2[1]) {
							tof.push(f[0]);
							tor.push("[EMBED]" + m2[1] + "[/EMBED]");
						}
					}
				}
				for (var i = 0; i < tof.length; i++) match = match.replace(tof[i], tor[i]);
				
				return match;
			}
			if (s.indexOf('class="oembed')>=0){
				//alert("request oembed html2bbcode");
				s = _h2b_cb(s);
			}
			
			/* /oembed */
{'fraction_non_alphanumeric': 0.1915673693858845, 'fraction_numerical': 0.009532538955087076, 'mean_word_length': 2.58005249343832, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 18, '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': '4941035', 'n_tokens_mistral': 2582, 'n_tokens_neox': 2057, 'n_words': 449}