Created
March 6, 2011 16:47
-
-
Save klaftertief/857392 to your computer and use it in GitHub Desktop.
Clickable utilities in the XSLT editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Clickable utilities in the XSLT editor | |
$('#utilities li').click(function(event) { | |
if ($(event.target).is('a')) return; | |
var editor = $('textarea.code'), | |
lines = editor.val().split('\n'), | |
statement = '<xsl:import href="../utilities/' + $(this).find('a').text() + '"/>', | |
regexp = '^' + statement.replace('/>', '').replace('../utilities/', '(?:\.\./utilities/)?'), | |
newLine = '\n', | |
numberOfNewLines = 1, | |
i; | |
if ($(this).hasClass('selected')) { | |
for (i = 0; i < lines.length; i++) { | |
if ($.trim(lines[i]).match(regexp) != null) { | |
(lines[i + 1] === '' && $.trim(lines[i - 1]).substring(0, 11) !== '<xsl:import') ? lines.splice(i, 2) : lines.splice(i, 1); | |
break; | |
} | |
} | |
editor.val(lines.join(newLine)); | |
$(this).removeClass('selected'); | |
} | |
else { | |
for (i = 0; i < lines.length; i++) { | |
if ($.trim(lines[i]).substring(0, 4) === '<!--' || $.trim(lines[i]).match('^<xsl:(?:import|variable|output|comment|template)')) { | |
numberOfNewLines = $.trim(lines[i]).substring(0, 11) === '<xsl:import' ? 1 : 2; | |
if (($('form:first').attr('action').indexOf('blueprints/pages') == -1)) { | |
// we are inside the page template editor | |
lines[i] = statement.replace('../utilities/', '') + Array(numberOfNewLines + 1).join(newLine) + lines[i]; | |
} | |
else { | |
lines[i] = statement + Array(numberOfNewLines + 1).join(newLine) + lines[i]; | |
} | |
break; | |
} | |
} | |
editor.val(lines.join(newLine)); | |
$(this).addClass('selected'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment