PageSourceSearch

https://stadtkapelle-oehringen.de/assets/js/editor.js

js stadtkapelle-oehringen.de collected 2026-10-06 22:05:44 UTC 9,448 bytes, 207 lines download raw bytes

1
2(function ($) {
3    'use strict';
4
5    var defaultOptions = {
6    };
7
8    $.extend(true, $.trumbowyg, {
9        langs: {
10            en: {
11                save: 'Save',
12                visible: 'Visibility'
13            },
14            de: {
15                save: 'Speichern',
16                visible: 'Sichtbarkeit'
17            }
18        },
19        // Add plugin to Trumbowyg registred plugins
20        plugins: {
21            save: {
22                init: function (trumbowyg) {
23                    // Fill current Trumbowyg instance with plugin's default options
24                    trumbowyg.o.plugins.save = $.extend(true, {},
25                        defaultOptions,
26                        trumbowyg.o.plugins.save || {}
27                    );
28
29                    trumbowyg.addBtnDef('save', {
30                        hasIcon: false, // TODO: switch to materialicons
31                        fn: function () {
32                            var isNews = window.location.pathname.includes('news');
33                            if (isNews) {
34                                saveNewsEntry(trumbowyg.$ed);
35                            } else {
36                                saveContentEntry(trumbowyg.$ed);
37                            }
38                        }
39                    });
40                    trumbowyg.addBtnDef('visible', {
41                        hasIcon: false, // TODO: switch to materialicons
42                        fn: function () {
43                            if (trumbowyg.$ed.parent().parent().parent().data('visible')) {
44                                showToast('Beitrag wird jetzt nicht mehr angezeigt.');
45                                trumbowyg.$ed.parent().parent().parent().data('visible', false);
46                                trumbowyg.$ed.parent().parent().parent().css('opacity', .5);
47                                setTimeout(function () {
48                                    trumbowyg.$ed.parent().parent().parent().css('opacity', 1);
49                                }, 500);
50                            } else {
51                                showToast('Beitrag wird jetzt wieder angezeigt.');
52                                trumbowyg.$ed.parent().parent().parent().data('visible', true);
53                            }
54                        }
55                    });
56                }
57            }
58        }
59    })
60})(jQuery);
61
62$(function () {
63    $.trumbowyg.svgPath = '/assets/static/svg/icons.svg';
64    $.trumbowyg.defaultOptions.autogrow = true;
65    $.trumbowyg.defaultOptions.lang = 'de';
66
67    // FIXME:  Currently bugged with sematic false: https://github.com/Alex-D/Trumbowyg/issues/843
68    $.trumbowyg.defaultOptions.btns = [
69        ['save'],
70        ['undo', 'redo'],
71        ['bold', 'italic', 'underline', 'strikethrough'],
72        ['link'],
73        ['removeformat'],
74        ['fullscreen']
75    ];
76    $.trumbowyg.defaultOptions.btnsNews = [
77        ['save'],
78        ['visible'],
79        ['undo', 'redo'],
80        ['bold', 'italic', 'underline', 'strikethrough'],
81        ['link'],
82        ['removeformat'],
83        ['fullscreen']
84    ];
85    $.trumbowyg.defaultOptions.semantic = false;
86
87    $.trumbowyg.defaultOptions.removeformatPasted = true; // only paste raw text (TODO: Change to false after paste get's sanatized)
88});
89
90function destroyEditor(article, data = null) {
91    if (article[0].tagName === 'TEXT') { // handle pages without article element
92        article.parent().parent().data('edit', false);
93        article.trumbowyg('destroy');
94        if (!data) article.html(article.parent().data('text'));
95        else article.html(data.content);
96        $('fab').children('i').html('edit');
97        $('fab').children('tooltip').html('Inhalt editieren');
98    } else {
99        let isNews = window.location.pathname.includes('news');
100
101        article.data('edit', false);
102        article.children('article-content').children('div.trumbowyg-box').children('text').trumbowyg('destroy');
103        article.children('article-actions').children().first().html('Editieren');
104        article.children('article-image').children('img').unbind('click');
105        article.children('article-content').children('article-title').attr('contenteditable', false);
106
107        if (isNews) {
108            article.children('article-image').children('img').attr('src', article.children('article-image').children('img').data('src'));
109            article.children('article-content').children('article-title').html(article.data('title'));
110            article.children('article-content').children('text').html(article.data('text'));
111            clampArticle(article);
112
113            if (article.data('visible')) {
114                article.css('opacity', 1);
115            } else {
116                article.css('opacity', .5);
117            }
118        } else if (!!data) {
119            article.children('article-image').children('img').attr('src', data.image);
120            article.children('article-content').children('article-title').html(data.title);
121            article.children('article-content').children('text').html(data.content);
122        } else {
123            data = article.data('text');
124            article.children('article-image').children('img').attr('src', data.image);
125            article.children('article-content').children('article-title').html(data.title);
126            article.children('article-content').children('text').html(data.content);
127        }
128
129        if (!!article.data('new')) {
130            article.remove();
131        }
132    }
133}
134
135function editContent(el) {
136    var isNews = window.location.pathname.includes('news');
137
138    if (el.tagName === 'FAB') {
139        if (!$('text-container').data('edit')) {
140            $(el).children('i').html('clear');
141            $(el).children('tooltip').html('Editierung abbrechen');
142            $('text-container').data('edit', true);
143            $('text-container').data('text', $('text-container text').html());
144            $('text-container text').trumbowyg({
145                lang: 'de', // Language does not inherit from defaultOptions
146                btns: $.trumbowyg.defaultOptions.btns // Currently bugged with sematic false: https://github.com/Alex-D/Trumbowyg/issues/843
147            });
148        } else {
149            if (confirm('Editieren wirklich abbrechen?')) {
150                destroyEditor($('text-container text'));
151            }
152        }
153    } else {
154        if (!$(el).parent().parent().data('edit')) {
155            $(el).parent().parent().data('edit', true);
156            if (!isNews)
157                $(el).parent().parent().data('text', {
158                    title: $(el).parent().parent().children('article-content').children('article-title').html(),
159                    image: $(el).parent().parent().children('article-image').children('img').attr('src'),
160                    content: $(el).parent().parent().children('article-content').children('text').html(),
161                });
162            $(el).parent().parent().css('opacity', 1);
163            $(el).parent().parent().children('article-actions').children().first().html('Abbrechen');
164            $(el).parent().parent().children('article-content').children('article-title').attr('contenteditable', true);
165            $(el).parent().parent().children('article-image').children('img').unbind('load');
166            $(el).parent().parent().children('article-image').children('img').click(function (e) {
167                var url = prompt("Bild URL eingeben:", $(el).parent().parent().children('article-image').children('img').attr('src'));
168                if (!!url)
169                    $(el).parent().parent().children('article-image').children('img').attr('src', url);
170            });
171            // Unclamp text
172            if (isNews) {
173                $(el).parent().parent().children('article-content').children('text').html($(el).parent().parent().data('text'))
174                $(el).parent().parent().children('article-content').children('text').attr('style', '');
175            }
176
177            $(el).parent().parent().children('article-content').children('text').trumbowyg({
178                lang: 'de', // Language does not inherit from defaultOptions
179                btns: isNews ? $.trumbowyg.defaultOptions.btnsNews : $.trumbowyg.defaultOptions.btns // Currently bugged with sematic false: https://github.com/Alex-D/Trumbowyg/issues/843
180            });
181        } else {
182            if (confirm('Editieren wirklich abbrechen?')) {
183                destroyEditor($(el).parent().parent());
184            }
185        }
186    }
187}
188
189function saveContentEntry(trumbowyg) {
190    let title = $(trumbowyg).parent().parent().parent().children('article-content').children('article-title').html();
191    let image = $(trumbowyg).parent().parent().parent().children('article-image').children('img').attr('src');
192    let content = trumbowyg.html();
193    let objid = $(trumbowyg).parent().parent().parent().data('objid');
194    if (!objid) objid = $(trumbowyg).parent().parent().data('objid'); // Handle pages without article element
195    $.ajax({
196        url: '/api/content/' + objid,
197        type: 'PATCH',
198        data: { title, image, content },
199    }).done(function (data) {
200        showToast('Beitrag wurde erfolgreich gespeichert.');
201        let article = trumbowyg.parent().parent().parent();
202        if (article[0].tagName === 'CONTENT') article = trumbowyg.parent().parent().children('div').children('text');
203        destroyEditor(article, data);
204    }).fail(function (error) {
205        console.error(error);
206    });
207}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.