Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function () {
- var forumLabels = {
- labels: {},
- insertionIndex: 0,
- copy: function () {
- var labels = this.labels = [];
- $('div.list.ui-autoform').children().each(function () {
- var name = $(this).find('input.tl-name-input').val();
- if ('' == name)
- return;
- labels.push({
- name: name,
- color: $(this).find('input.tl-color-input').val(),
- perms: {
- access: $(this).find('input.tl-permi' + 'ssions_accessible-input').val(),
- view: $(this).find('input.tl-permi' + 'ssions_viewable-input').val()
- }
- });
- });
- function unique(e) {
- for (var t = {}, i = [], n = 0, a = e.length; n < a; ++n)
- JSON.stringify(e[n], null, 0)in t || (i.push(e[n]), t[JSON.stringify(e[n], null, 0)] = 1);
- return i
- }
- labels = unique(labels);
- },
- paste: function () {
- if (0 == this.labels.length)
- return;
- this.insertionIndex = 0;
- this.insertNextLabels();
- },
- insertNextLabels() {
- var label = this.labels[this.insertionIndex++];
- var list = $('.thread_label_div.ui-autoform .list.ui-autoform');
- var newItem = list.find('.ui-autoform-new-item:last');
- if (this.labels.length > this.insertionIndex)
- list.one('DOMNodeInserted', '.ui-autoform-new-item', this.insertNextLabels.bind(this));
- $('#colorPicker').css({
- visibility: 'hidden'
- });
- newItem
- .find('input.tl-color-input')
- .val(label.color)
- .trigger('focus')
- .trigger('change')
- .trigger('blur')
- .end()
- .find('input.tl-permi' + 'ssions_accessible-input')
- .val(label.perms.access)
- .end()
- .find('input.tl-permi' + 'ssions_viewable-input')
- .val(label.perms.view)
- .end()
- .find('input.tl-name-input')
- .val(label.name)
- .trigger('change');
- $('#colorPicker').css({
- visibility: ''
- });
- }
- };
- (function () {
- $(document).ajaxComplete(function (event, xhr, settings) {
- if (settings.url == proboards.route('category_board_board_dialog')) {
- const buttonpane = $('#dialog_settings').nextAll('.ui-dialog-buttonpane').find('.ui-dialog-buttonset');
- function addPasteButton() {
- "undefined" !== typeof forumLabels.labels.length && forumLabels.labels.length && buttonpane.find('.ui-button.board-paste').length == 0 && $('<button>', {
- role: 'button',
- type: 'button',
- class: 'ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only board-paste',
- title: '[' + forumLabels.labels.map(x => {
- return x.name
- }).join('][') + ']'
- }).append('<span class="ui-button-text">Paste Board Labels</span>').click(function (e) {
- forumLabels.paste();
- e.preventDefault();
- return false;
- }).prependTo(buttonpane)
- }
- function addCopyButton() {
- $('.list.ui-autoform > .item').not('.ui-autoform-new-item').length && buttonpane.find('.ui-button.board-copy').length == 0 && $('<button>', {
- role: 'button',
- type: 'button',
- class: 'ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only board-copy'
- }).append('<span class="ui-button-text">Copy Board Labels</span>').click(function (e) {
- forumLabels.copy();
- e.preventDefault();
- $('.thread_label_div').prevAll('b').first().setStatus('Copied', {
- position: 'after'
- }),
- addPasteButton();
- return false;
- }).prependTo(buttonpane);
- }
- addCopyButton(),
- addPasteButton()
- }
- })
- })();
- })()
- /** CHANGELOG:
- 1. added copy and paste buttons
- 2. added dynamic paste button when data copied
- 3. added duplicate filtering during copy process
- **/
Add Comment
Please, Sign In to add comment