mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FEATURE: allow copying of color schemes to clipboard
This commit is contained in:
parent
f968b4e662
commit
a19c02f0d3
4 changed files with 38 additions and 0 deletions
|
@ -20,6 +20,31 @@ export default Ember.Controller.extend({
|
||||||
color.undo();
|
color.undo();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
copyToClipboard() {
|
||||||
|
$(".table.colors").hide();
|
||||||
|
let area = $("<textarea id='copy-range'></textarea>");
|
||||||
|
$(".table.colors").after(area);
|
||||||
|
area.text(this.get("model").schemeJson());
|
||||||
|
let range = document.createRange();
|
||||||
|
range.selectNode(area[0]);
|
||||||
|
window.getSelection().addRange(range);
|
||||||
|
let successful = document.execCommand('copy');
|
||||||
|
if (successful) {
|
||||||
|
this.set("model.savingStatus", I18n.t("admin.customize.copied_to_clipboard"));
|
||||||
|
} else {
|
||||||
|
this.set("model.savingStatus", I18n.t("admin.customize.copy_to_clipboard_error"));
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(()=>{
|
||||||
|
this.set("model.savingStatus", null);
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
|
window.getSelection().removeAllRanges();
|
||||||
|
|
||||||
|
$(".table.colors").show();
|
||||||
|
$(area).remove();
|
||||||
|
},
|
||||||
|
|
||||||
copy() {
|
copy() {
|
||||||
var newColorScheme = Em.copy(this.get('model'), true);
|
var newColorScheme = Em.copy(this.get('model'), true);
|
||||||
newColorScheme.set('name', I18n.t('admin.customize.colors.copy_name_prefix') + ' ' + this.get('model.name'));
|
newColorScheme.set('name', I18n.t('admin.customize.colors.copy_name_prefix') + ' ' + this.get('model.name'));
|
||||||
|
|
|
@ -18,6 +18,15 @@ const ColorScheme = Discourse.Model.extend(Ember.Copyable, {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
schemeJson(){
|
||||||
|
let buffer = [];
|
||||||
|
_.each(this.get('colors'), (c) => {
|
||||||
|
buffer.push(` "${c.get('name')}": "${c.get('hex')}"`);
|
||||||
|
});
|
||||||
|
|
||||||
|
return [`"${this.get("name")}": {`, buffer.join(",\n"), "}"].join("\n");
|
||||||
|
},
|
||||||
|
|
||||||
copy: function() {
|
copy: function() {
|
||||||
var newScheme = ColorScheme.create({name: this.get('name'), can_edit: true, colors: Em.A()});
|
var newScheme = ColorScheme.create({name: this.get('name'), can_edit: true, colors: Em.A()});
|
||||||
_.each(this.get('colors'), function(c){
|
_.each(this.get('colors'), function(c){
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
<button {{action "save"}} disabled={{model.disableSave}} class='btn'>{{i18n 'admin.customize.save'}}</button>
|
<button {{action "save"}} disabled={{model.disableSave}} class='btn'>{{i18n 'admin.customize.save'}}</button>
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
<button {{action "copy" model}} class='btn'><i class="fa fa-copy"></i> {{i18n 'admin.customize.copy'}}</button>
|
<button {{action "copy" model}} class='btn'><i class="fa fa-copy"></i> {{i18n 'admin.customize.copy'}}</button>
|
||||||
|
<button {{action "copyToClipboard" model}} class='btn'><i class="fa fa-clipboard"></i> {{i18n 'admin.customize.copy_to_clipboard'}}</button>
|
||||||
{{#if model.theme_id}}
|
{{#if model.theme_id}}
|
||||||
{{i18n "admin.customize.theme_owner"}}
|
{{i18n "admin.customize.theme_owner"}}
|
||||||
{{#link-to "adminCustomizeThemes.show" model.theme_id}}{{model.theme_name}}{{/link-to}}
|
{{#link-to "adminCustomizeThemes.show" model.theme_id}}{{model.theme_name}}{{/link-to}}
|
||||||
|
|
|
@ -2796,6 +2796,9 @@ en:
|
||||||
color: "Color"
|
color: "Color"
|
||||||
opacity: "Opacity"
|
opacity: "Opacity"
|
||||||
copy: "Copy"
|
copy: "Copy"
|
||||||
|
copy_to_clipboard: "Copy to Clipboard"
|
||||||
|
copied_to_clipboard: "Copied to Clipboard"
|
||||||
|
copy_to_clipboard_error: "Error copying data to Clipboard"
|
||||||
theme_owner: "Not editable, owned by:"
|
theme_owner: "Not editable, owned by:"
|
||||||
email_templates:
|
email_templates:
|
||||||
title: "Email Templates"
|
title: "Email Templates"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue