').html(val).text()
+ },
+ replaceCkeContent: function () {
+ return CKEDITOR.instances.issue_description.setData($('#issue_description').val())
+ },
+ hideOverwiteConfirm: function () {
+ let cookieArray = []
+ if (document.cookie !== '') {
+ let tmp = document.cookie.split(' ')
+ for (let i = 0; i < tmp.length; i++) {
+ let data = tmp[i].split('=')
+ cookieArray[data[0]] = decodeURIComponent(data[1])
+ }
+ }
+ let confirmationCookie = cookieArray['issue_template_confirm_to_replace_hide_dialog']
+ if (confirmationCookie == undefined || parseInt(confirmationCookie) === 0) {
+ return false
+ }
+ return true
+ },
+ changeTemplatePlace: function () {
+ if (document.querySelector('div.flash_message')) {
+ document.querySelector('div.flash_message').remove()
+ }
+ const subjectNode = document.getElementById('issue_subject')
+ if (subjectNode) {
+ const subjectParentNode = subjectNode.parentNode
+ subjectParentNode.parentNode.insertBefore(document.getElementById('template_area'), subjectParentNode)
}
+ }
};
// jQuery plugin for issue template
(function ($) {
- var methods = {
- init: function (options) {},
- updateTemplateSelect: function (options) {
- options = $.extend({
- target: '#issue_template',
- template_id: 'data-issue-template-id'
- }, options);
- return $(this).each(function () {
- $(this).click(function () {
- var obj = $(options.target);
- var id = $(this).attr(options.template_id);
- obj.attr("selected", false);
- // has template-global class?
- if ($(this).hasClass('template-global')) {
- obj.find('option[value="' + id + '"][class="global"]').prop('selected', true);
- } else {
- obj.val(id);
- }
- obj.trigger('change');
- });
- });
- },
- displayTooltip: function (options) {
- options = $.extend({
- tooltip_body_id: 'data-tooltip-content',
- tooltip_target_id: 'data-tooltip-area'
- }, options);
- return $(this).each(function () {
- $(this).hover(function () {
- var content = $(this).attr(options.tooltip_body_id);
- var target = $(this).attr(options.tooltip_target_id);
- var obj = $(content);
- if (obj.length)
- $(target).html(obj);
- obj.toggle();
- });
- });
- },
- expandHelp: function (options) {
- options = $.extend({
- attr_name: 'data-template-help-target'
- }, options);
- return $(this).each(function () {
- $(this).click(function () {
- var target = $(this).attr(options.attr_name);
- var obj = $(target);
- if (obj.length)
- obj.toggle();
- });
- });
- },
- flash_message: function (options) {
- // default
- options = $.extend({
- text: 'Done',
- time: 3000,
- how: 'before',
- class_name: ''
- }, options);
-
- return $(this).each(function () {
- if ($(this).parent().find('.flash_message').get(0)) return;
+ let methods = {
+ init: function (options) {},
+ updateTemplateSelect: function (options) {
+ options = $.extend({
+ target: '#issue_template',
+ template_id: 'data-issue-template-id'
+ }, options)
+ return $(this).each(function () {
+ $(this).click(function () {
+ let obj = $(options.target)
+ let id = $(this).attr(options.template_id)
+ obj.attr('selected', false)
+ // has template-global class?
+ if ($(this).hasClass('template-global')) {
+ obj.find('option[value="' + id + '"][class="global"]').prop('selected', true)
+ } else {
+ obj.val(id)
+ }
+ obj.trigger('change')
+ })
+ })
+ },
+ displayTooltip: function (options) {
+ options = $.extend({
+ tooltip_body_id: 'data-tooltip-content',
+ tooltip_target_id: 'data-tooltip-area'
+ }, options)
+ return $(this).each(function () {
+ $(this).hover(function () {
+ let content = $(this).attr(options.tooltip_body_id)
+ let target = $(this).attr(options.tooltip_target_id)
+ let obj = $(content)
+ if (obj.length) {
+ $(target).html(obj)
+ }
+ obj.toggle()
+ })
+ })
+ },
+ expandHelp: function (options) {
+ options = $.extend({
+ attr_name: 'data-template-help-target'
+ }, options)
+ return $(this).each(function () {
+ $(this).click(function () {
+ let target = $(this).attr(options.attr_name)
+ let obj = $(target)
+ if (obj.length) {
+ obj.toggle()
+ }
+ })
+ })
+ },
+ flash_message: function (options) {
+ // default
+ options = $.extend({
+ text: 'Done',
+ time: 3000,
+ how: 'before',
+ class_name: ''
+ }, options)
- var message = $('
', {
- 'class': 'flash_message ' + options.class_name,
- html: options.text
- // display with fade in
- }).hide().fadeIn('fast');
+ return $(this).each(function () {
+ if ($(this).parent().find('.flash_message').get(0)) return
- $(this)[options.how](message);
- //delay and fadeout
- message.delay(options.time).fadeOut('normal', function () {
- $(this).remove();
- });
+ let message = $('
', {
+ 'class': 'flash_message ' + options.class_name,
+ html: options.text
+ // display with fade in
+ }).hide().fadeIn('fast')
- });
- },
- disabled_link: function (options) {
- options = $.extend({}, options);
- return $(this).each(function () {
- $(this).click(function (event) {
- title = event.target.title;
- if (title.length && event.target.hasAttribute('disabled')) {
- event.stopPropagation();
- alert(title);
- return false;
- }
- });
- });
- }
- };
+ $(this)[options.how](message)
+ //delay and fadeout
+ message.delay(options.time).fadeOut('normal', function () {
+ $(this).remove()
+ })
+ })
+ },
+ disabled_link: function (options) {
+ options = $.extend({}, options)
+ return $(this).each(function () {
+ $(this).click(function (event) {
+ let title = event.target.title
+ if (title.length && event.target.hasAttribute('disabled')) {
+ event.stopPropagation()
+ window.alert(title)
+ return false
+ }
+ })
+ })
+ }
+ }
- $.fn.issueTemplate = function (method) {
+ $.fn.issueTemplate = function (method) {
- // Method dispatch logic
- if (methods[method]) {
- return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
- } else if (typeof method === 'object' || !method) {
- return methods.init.apply(this, arguments);
- } else {
- $.error('Method ' + method + ' does not exist on jQuery.issueTemplate');
- }
- };
-})(jQuery);
+ // Method dispatch logic
+ if (methods[method]) {
+ return methods[method].apply(this, Array.prototype.slice.call(arguments, 1))
+ } else if (typeof method === 'object' || !method) {
+ return methods.init.apply(this, arguments)
+ } else {
+ $.error('Method ' + method + ' does not exist on jQuery.issueTemplate')
+ }
+ }
+})(jQuery)
$(function () {
- // set plugin
- $('a.template-help').issueTemplate('displayTooltip');
- $('a.template-help.collapsible').issueTemplate('expandHelp');
- $('a.template-help.collapsible').click(function () {
- $(this).toggleClass('collapsed');
- });
+ // set plugin
+ $('a.template-help').issueTemplate('displayTooltip')
+ $('a.template-help.collapsible').issueTemplate('expandHelp')
+ $('a.template-help.collapsible').click(function () {
+ $(this).toggleClass('collapsed')
+ })
- $('a.template-disabled-link').issueTemplate('disabled_link');
+ $('a.template-disabled-link').issueTemplate('disabled_link')
- // display orphaned template list
- $('#orphaned_template_link').on(
- 'ajax:success', function (e) {
- var xhr = e.detail[2];
- $('#orphaned_templates').toggle();
- $('#orphaned_templates').html(xhr.response);
- }
- );
-});
+ // display orphaned template list
+ $('#orphaned_template_link').on(
+ 'ajax:success',
+ function (e) {
+ let xhr = e.detail[2]
+ $('#orphaned_templates').toggle()
+ $('#orphaned_templates').html(xhr.response)
+ }
+ )
+})
// for IE11 compatibility (IE11 does not support native Element.closest)
// Ref. https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill
// Ref. https://github.com/akiko-pusu/redmine_issue_templates/issues/270
if (!Element.prototype.matches) {
- Element.prototype.matches = Element.prototype.msMatchesSelector ||
- Element.prototype.webkitMatchesSelector;
+ Element.prototype.matches = Element.prototype.msMatchesSelector ||
+ Element.prototype.webkitMatchesSelector
}
if (!Element.prototype.closest) {
- Element.prototype.closest = function(s) {
- var el = this;
+ Element.prototype.closest = function (s) {
+ let el = this
- do {
- if (el.matches(s)) return el;
- el = el.parentElement || el.parentNode;
- } while (el !== null && el.nodeType === 1);
- return null;
- };
+ do {
+ if (el.matches(s)) return el
+ el = el.parentElement || el.parentNode
+ } while (el !== null && el.nodeType === 1)
+ return null
+ }
}