client.post(evt, {dataType: 'html'}).then(function (response) { var $container = evt.$trigger.closest('.comment'); var $html = $(response.html); $container.prepend($html); evt.$trigger.closest('.showMore').remove(); additions.applyTo($html); }).catch(function (err) {
RichText.prototype.init = function() { // If in edit mode we do not actually render, we just hold the content if(!this.options.edit) { this.editor = new MarkdownEditor(this.$, this.options); this.$.html(this.editor.render()); additions.applyTo(this.$, {filter: ['highlightCode']}); } // See https://github.com/ProseMirror/prosemirror/issues/432 document.execCommand('enableObjectResizing', false, 'false'); document.execCommand('enableInlineTableEditing', false, 'false'); };
var initAddition = function () { additions.register('markdown', '[data-ui-markdown]', function ($match) { var converter = new Markdown.getSanitizingConverter(); Markdown.Extra.init(converter); $match.each(function () { var $this = $(this); if ($this.data('markdownProcessed')) { return; } // Export all richtext features var features = {}; $this.find('[data-richtext-feature], .oembed_snippet').each(function () { var $this = $(this); var featureKey = $this.data('guid') || '@-' + $this.attr('id'); // old oembeds if ($this.is('.oembed_snippted') && !$this.data('guid')) { featureKey = '@-oembed-' + $this.data('url'); } features[featureKey] = $this.clone(); // We add a space to make sure our placeholder is not appended to any link or something. $this.replaceWith(' ' + featureKey); }); var text = richtext.Richtext.plainText($this.clone()); var result = converter.makeHtml(text); // Rewrite richtext feature $.each(features, function (featureKey, $element) { result = result.replace(new RegExp('( )?' + featureKey.trim(), 'g'), $('<div></div>').html($element).html()); }); $this.html(result).data('markdownProcessed', true); // Make sure to add noopener to all links $this.find('a').attr('rel', 'noopener noreferrer'); }); }); };
Form.prototype.addComment = function (html) { var $html = $(html); // Filter out all script/links and text nodes var $elements = $html.not('script, link').filter(function () { return this.nodeType === 1; // filter out text nodes }); // We use opacity because some additions require the actual size of the elements. $elements.css('opacity', 0); // call insert callback this.getCommentsContainer().append($html); this.incrementCommentCount(1); // apply additions to elements and fade them in. additions.applyTo($elements); $elements.hide().css('opacity', 1).fadeIn('fast'); };
return new Promise(function (resolve, reject) { var $html = $(html); // Filter out all script/links and text nodes var $elements = $html.not('script, link').filter(function () { return this.nodeType === 1; // filter out text nodes }); // We use opacity because some additions require the actual size of the elements. $elements.css('opacity', 0); // call insert callback insert.call(that, $html); // apply additions to elements and fade them in. additions.applyTo($elements); $elements.hide().css('opacity', 1).fadeIn('fast', function () { that.onChange(); resolve(); }); });
var init = function () { additions.register('ui.picker', '.multiselect_dropdown', function ($match) { $match.each(function () { Picker.instance(this); }); }); // This extension allows preselected values in our picker if the mininput value is not exceded. // http://stackoverflow.com/questions/33080739/select2-default-options-with-ajax // https://gist.github.com/govorov/3ee75f54170735153349b0a430581195 $.fn.select2.amd.define('select2/data/extended-ajax', ['./ajax', '../utils', './minimumInputLength'], function (AjaxAdapter, Utils, MinimumInputLength) { function ExtendedAjaxAdapter($element, options) { //we need explicitly process minimumInputLength value //to decide should we use AjaxAdapter or return defaultResults, //so it is impossible to use MinimumLength decorator here this.minimumInputLength = options.get('minimumInputLength'); this.defaultResults = options.get('defaultResults'); ExtendedAjaxAdapter.__super__.constructor.call(this, $element, options); } Utils.Extend(ExtendedAjaxAdapter, AjaxAdapter); //override original query function to support default results var originQuery = AjaxAdapter.prototype.query; ExtendedAjaxAdapter.prototype.query = function (params, callback) { var defaultResults = (typeof this.defaultResults == 'function') ? this.defaultResults.call(this) : this.defaultResults; if (defaultResults && defaultResults.length && (!params.term || params.term.length < this.minimumInputLength)) { if (!params.term || !params.term.length) { var processedResults = this.processResults(defaultResults, params); callback(processedResults); return; } // If search term var filterResult = []; $.each(defaultResults, function (index, item) { if (item['data-text'].toLowerCase().indexOf(params.term.toLowerCase()) >= 0) { filterResult.push(item); } }); if (filterResult.length) { var processedResults = this.processResults(filterResult, params); callback(processedResults); } else { this.container.$results.empty(); } var $message = $('<li role="treeitem" aria-live="assertive" class="select2-results__option select2-results__message">' + this.options.get('inputTooShort') + '</li>'); this.container.$results.prepend($message); } else { originQuery.call(this, params, callback); } }; return ExtendedAjaxAdapter; }); };
var Comment = Content.extend(function (node) { Content.call(this, node); additions.observe(this.$); });
client.post(evt, {dataType: 'html'}).then(function (response) { var $container = evt.$trigger.parent(); $container.html(response.html); additions.applyTo($container); }).catch(function (err) {
Comment.prototype.highlight = function () { additions.highlight(this.$.find('.comment-message')); };
Comment.prototype.replace = function (content) { var id = this.$.attr('id'); this.$.replaceWith(content); this.$ = $('#' + id); additions.observe(this.$, true); };
StreamEntry.prototype.highlight = function () { additions.highlight(this.getContent()); };
StreamEntry.prototype.apply = function () { additions.applyTo(this.$); };
var Root = function (node, options) { Widget.call(this, node, options); additions.observe(this.$); };