+ initCallback: function(editor) {
+
+ function createXSLT(xsl) {
+ var p = new XSLTProcessor();
+ p.importStylesheet(xsl);
+ return p;
+ }
+
+ function transform() {
+ $.ajax({
+ url: '/static/xsl/wl2html_client.xsl',
+ dataType: 'xml',
+ success: function(data) {
+ var doc = null;
+ var parser = new DOMParser();
+ var serializer = new XMLSerializer();
+ var htmlXSL = createXSLT(data);
+
+ doc = editor.getCode().replace(/\/\s+/g, '<br />');
+ doc = parser.parseFromString(doc, 'text/xml');
+ console.log('xml', doc);
+ doc = htmlXSL.transformToFragment(doc, document);
+ console.log('after transform', doc);
+ $('#html-view').html(doc.firstChild);
+ },
+ error: function() {alert('Error loading XSL!')}
+ });
+ };
+
+ function reverseTransform () {
+ $.ajax({
+ url: '/static/xsl/html2wl_client.xsl',
+ dataType: 'xml',
+ success: function(data) {
+ var doc = null;
+ var parser = new DOMParser();
+ var serializer = new XMLSerializer();
+ var xsl = createXSLT(data);
+
+ doc = serializer.serializeToString($('#html-view div').get(0))
+ doc = parser.parseFromString(doc, 'text/xml');
+ console.log('xml',doc, doc.documentElement);
+ // TODO: Sprawdzenie błędów
+ doc = xsl.transformToDocument(doc);
+ console.log('after transform', doc, doc.documentElement);
+ doc = serialize(doc.documentElement).join('');
+ // doc = serializer.serializeToString(doc.documentElement)
+ editor.setCode(doc);
+ },
+ error: function() {alert('Error loading XSL!')}
+ });
+ };
+
+ $('#save-button').click(function(event) {
+ event.preventDefault();
+ console.log(editor.getCode(), $('form input[name=text]').get(0));
+ $('form textarea[name=text]').val(editor.getCode());
+ $('form').ajaxSubmit(function() {
+ alert('Udało się!');
+ });
+ });
+
+ $('#simple-view-tab').click(function() {
+ if ($(this).hasClass('active')) {
+ return;
+ }
+ $(this).addClass('active');
+ $('#source-view-tab').removeClass('active');
+ $('#source-editor').hide();
+ $('#simple-editor').show();
+ transform();
+ });
+
+ $('#source-view-tab').click(function() {
+ if ($(this).hasClass('active')) {
+ return;
+ }
+ $(this).addClass('active');
+ $('#simple-view-tab').removeClass('active');
+ $('#simple-editor').hide();
+ $('#source-editor').show();
+ reverseTransform();
+ });
+
+ $('.toolbar button').click(function(event) {
+ event.preventDefault();
+ var params = eval("(" + $(this).attr('ui:action-params') + ")");
+ scriptletCenter.scriptlets[$(this).attr('ui:action')](editor, params);
+ });
+
+ $('.toolbar select').change(function() {
+ var slug = $(this).val();
+
+ $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show();
+ $(window).resize();
+ });
+
+ $('.toolbar-buttons-container').hide();
+ $('.toolbar select').change();
+
+ var button = $('<button class="edit-button">Edytuj</button>');
+ $('#html-view').bind('mousemove', function(event) {
+ var editable = $(event.target).closest('*[x-editable]');
+ $('#html-view .active[x-editable]').not(editable).removeClass('active').children('.edit-button').remove();
+ if (!editable.hasClass('active')) {
+ editable.addClass('active').append(button);
+ }
+ });
+
+ $('.motyw').live('click', function() {
+ selectTheme($(this).attr('theme-class'));
+ });
+
+ $('#simple-view-tab').click();
+
+ }