Cotonti / Open Source PHP Content Management FrameworkContent Management Framework

Pastebin / elRTE SyntaxHighlighter button

// SyntaxHighligher code button
(function($) {
elRTE.prototype.ui.prototype.buttons.code = function(rte, name) {
	this.constructor.prototype.constructor.call(this, rte, name);
	var self = this;
	var opts = {
		tpl      : '<pre class="brush:%val">%label</span>',
		select   : function(v) { self.set(v); },
		src      : {
			'code':		'Code',
			'as3':		'ActionScript 3',
			'bash':		'Bash',
			'cpp':		'C++',
			'csharp':	'C#',
			'css':		'CSS',
			'delphi':	'Delphi',
			'diff':		'Diff',
			'erlang':	'Erlang',
			'groovy':	'Groovy',
			'java':		'Java',
			'javafx':	'JavaFX',
			'jscript':	'JavaScript',
			'perl':		'Perl',
			'php':		'PHP',
			'plain':	'Plain text',
			'python':	'Python',
			'ruby':		'Ruby',
			'scala':	'Scala',
			'vb':		'VB',
			'xml':		'XML'
		}
	}
	
	this.select = this.domElem.elSelect(opts);
	
	this.command = function() {
	}
	
	this.set = function(brush) {
		this.rte.history.add();
		var nodes = this.rte.selection.selected({filter : 'textContainsNodes'});
		//nodes.wrapAll('<pre class="brush:'+brush+'" />');
		//nodes.wrap('<pre class="brush:'+brush+'" />');
		$.each(nodes, function() {
			//$this = /^(THEAD|TFOOT|TBODY|COL|COLGROUP|TR)$/.test(this.nodeName) ? $(this).find('td,th') : $(this);
			if (brush == 'code') {
				if ($(this).parent().is('pre')) {
					$(this).unwrap();
				}
			} else {
				$(this).wrap('<pre class="brush:'+brush+'"/>');
			}
		});
		this.rte.ui.update();
	}
	
	this.update = function() {
		this.domElem.removeClass('disabled'); 
		var n = this.rte.selection.getNode();
		if (n.nodeType != 1) {
			n = n.parentNode;
		}
		var v = $(n).attr('class');
		var m = /brush:(\w+)/gi.match(v);
		v = m[1];
		this.select.val(opts.src[v] ? v : '');
	}
}
})(jQuery);
elRTE.prototype.options.buttons.code = 'Code';

Tags:

No tags