Updated zero.clipboard to fix copy to clipboard function for requirejs.

Removed wrapper function.
This commit is contained in:
Taloth Saldono 2015-02-04 00:46:55 +01:00
parent 58f0e713fa
commit 00dddfeaf3
4 changed files with 2533 additions and 961 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -3,17 +3,20 @@ var StatusModel = require('../System/StatusModel');
var ZeroClipboard = require('zero.clipboard'); var ZeroClipboard = require('zero.clipboard');
var Messenger = require('../Shared/Messenger'); var Messenger = require('../Shared/Messenger');
module.exports = (function(){ $.fn.copyToClipboard = function(input) {
$.fn.copyToClipboard = function(input){
var moviePath = StatusModel.get('urlBase') + '/Content/zero.clipboard.swf'; ZeroClipboard.config({
var client = new ZeroClipboard(this, {moviePath : moviePath}); swfPath: StatusModel.get('urlBase') + '/Content/zero.clipboard.swf'
client.on('load', function(client){ });
client.on('dataRequested', function(client){
client.setText(input.val()); var client = new ZeroClipboard(this);
});
client.on('complete', function(){ client.on('ready', function(e) {
Messenger.show({message : 'Copied text to clipboard'}); client.on('copy', function(e) {
}); e.clipboardData.setData("text/plain", input.val());
}); });
}; client.on('aftercopy', function() {
}).call(this); Messenger.show({message : 'Copied text to clipboard'});
});
});
};

View File

@ -1,123 +1,121 @@
'use strict'; 
define( var vent = require('../../vent');
[ var Marionette = require('marionette');
'vent', var CommandController = require('../../Commands/CommandController');
'marionette', var AsModelBoundView = require('../../Mixins/AsModelBoundView');
'Commands/CommandController', var AsValidatedView = require('../../Mixins/AsValidatedView');
'Mixins/AsModelBoundView',
'Mixins/AsValidatedView',
'Mixins/CopyToClipboard'
], function (vent, Marionette, CommandController, AsModelBoundView, AsValidatedView) {
var view = Marionette.ItemView.extend({
template: 'Settings/General/GeneralViewTemplate',
events: { require('../../Mixins/CopyToClipboard');
'change .x-auth' : '_setAuthOptionsVisibility',
'change .x-ssl' : '_setSslOptionsVisibility',
'click .x-reset-api-key' : '_resetApiKey',
'change .x-update-mechanism' : '_setScriptGroupVisibility'
},
ui: { var view = Marionette.ItemView.extend({
authToggle : '.x-auth', template: 'Settings/General/GeneralViewTemplate',
authOptions : '.x-auth-options',
sslToggle : '.x-ssl',
sslOptions : '.x-ssl-options',
resetApiKey : '.x-reset-api-key',
copyApiKey : '.x-copy-api-key',
apiKeyInput : '.x-api-key',
updateMechanism : '.x-update-mechanism',
scriptGroup : '.x-script-group'
},
initialize: function () { events: {
this.listenTo(vent, vent.Events.CommandComplete, this._commandComplete); 'change .x-auth' : '_setAuthOptionsVisibility',
}, 'change .x-ssl' : '_setSslOptionsVisibility',
'click .x-reset-api-key' : '_resetApiKey',
'change .x-update-mechanism' : '_setScriptGroupVisibility'
},
onRender: function(){ ui: {
if(this.ui.authToggle.val() === 'none'){ authToggle : '.x-auth',
this.ui.authOptions.hide(); authOptions : '.x-auth-options',
} sslToggle : '.x-ssl',
sslOptions : '.x-ssl-options',
resetApiKey : '.x-reset-api-key',
copyApiKey : '.x-copy-api-key',
apiKeyInput : '.x-api-key',
updateMechanism : '.x-update-mechanism',
scriptGroup : '.x-script-group'
},
if(!this.ui.sslToggle.prop('checked')){ initialize: function () {
this.ui.sslOptions.hide(); this.listenTo(vent, vent.Events.CommandComplete, this._commandComplete);
} },
if (!this._showScriptGroup()) { onRender: function(){
this.ui.scriptGroup.hide(); if(this.ui.authToggle.val() === 'none'){
} this.ui.authOptions.hide();
}
CommandController.bindToCommand({ if(!this.ui.sslToggle.prop('checked')){
element: this.ui.resetApiKey, this.ui.sslOptions.hide();
command: { }
name: 'resetApiKey'
}
});
},
onShow: function () { if (!this._showScriptGroup()) {
this.ui.copyApiKey.copyToClipboard(this.ui.apiKeyInput); this.ui.scriptGroup.hide();
}, }
_setAuthOptionsVisibility: function () { CommandController.bindToCommand({
element: this.ui.resetApiKey,
var showAuthOptions = this.ui.authToggle.val() !== 'none'; command: {
name: 'resetApiKey'
if (showAuthOptions) {
this.ui.authOptions.slideDown();
}
else {
this.ui.authOptions.slideUp();
}
},
_setSslOptionsVisibility: function () {
var showSslOptions = this.ui.sslToggle.prop('checked');
if (showSslOptions) {
this.ui.sslOptions.slideDown();
}
else {
this.ui.sslOptions.slideUp();
}
},
_resetApiKey: function () {
if (window.confirm('Reset API Key?')) {
CommandController.Execute('resetApiKey', {
name : 'resetApiKey'
});
}
},
_commandComplete: function (options) {
if (options.command.get('name') === 'resetapikey') {
this.model.fetch();
}
},
_setScriptGroupVisibility: function () {
if (this._showScriptGroup()) {
this.ui.scriptGroup.slideDown();
}
else {
this.ui.scriptGroup.slideUp();
}
},
_showScriptGroup: function () {
return this.ui.updateMechanism.val() === 'script';
} }
}); });
},
AsModelBoundView.call(view); onShow: function () {
AsValidatedView.call(view); this.ui.copyApiKey.copyToClipboard(this.ui.apiKeyInput);
},
return view; _setAuthOptionsVisibility: function () {
});
var showAuthOptions = this.ui.authToggle.val() !== 'none';
if (showAuthOptions) {
this.ui.authOptions.slideDown();
}
else {
this.ui.authOptions.slideUp();
}
},
_setSslOptionsVisibility: function () {
var showSslOptions = this.ui.sslToggle.prop('checked');
if (showSslOptions) {
this.ui.sslOptions.slideDown();
}
else {
this.ui.sslOptions.slideUp();
}
},
_resetApiKey: function () {
if (window.confirm('Reset API Key?')) {
CommandController.Execute('resetApiKey', {
name : 'resetApiKey'
});
}
},
_commandComplete: function (options) {
if (options.command.get('name') === 'resetapikey') {
this.model.fetch();
}
},
_setScriptGroupVisibility: function () {
if (this._showScriptGroup()) {
this.ui.scriptGroup.slideDown();
}
else {
this.ui.scriptGroup.slideUp();
}
},
_showScriptGroup: function () {
return this.ui.updateMechanism.val() === 'script';
}
});
AsModelBoundView.call(view);
AsValidatedView.call(view);
module.exports = view;