define([ "dojo/_base/lang", "dojo/query", "dojo/NodeList-html", "dojo/NodeList-traverse" ], function(lang, query) { var paste = lang.getObject("siemens.clipboard.paste", true); var dataTypeMap = {}; dataTypeMap['text/plain'] = "data-copy-text"; dataTypeMap['text/html'] = "data-copy-text-html"; dataTypeMap['application/vnd-websdk'] = "data-copy-websdk"; var targetElement; var targetContainerId; var targetAction; return lang.mixin(paste, { isNavigatorIE : function() { return (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0); }, isPasteCommandSupported : function() { return document.queryCommandSupported('paste'); }, isPasteCommandEnabled : function() { return document.queryCommandEnabled('paste'); }, // try to paste using event.clipboardData; if not supported paste using // window.clipboardData paste : function(element, action, containerId) { targetElement = query(element); var activeElement = query(document.activeElement); var parentInlineFilter = activeElement.parents('tr.CVInlineFilter'), parentToolbar = activeElement .parents('div.gridToolbarCell'); if (parentInlineFilter.length > 0 || parentToolbar.length > 0) { targetElement = activeElement; } if (action) { targetAction = action; } else { var elementType = targetElement.attr('data-context').toString(); targetAction = (elementType === 'Grid') ? 'GRID_PASTE' : 'INPUT_PASTE'; } if (containerId) { targetContainerId = containerId; } else { targetContainerId = targetElement.attr('id').toString(); } if (!paste.pasteCommand()) { paste.pasteText(); } }, // check if event clipboard and paste command are supported, if so execute paste command pasteCommand : function() { var pasteSucceeded = false; if (!(paste.isNavigatorIE()) && document.queryCommandEnabled) { var needDesignMode = !paste.isPasteCommandEnabled(); if (needDesignMode) { document.designMode = 'on'; } pasteSucceeded = (paste.isPasteCommandSupported() && document.execCommand('paste')); if (needDesignMode) { document.designMode = 'off'; } } return pasteSucceeded; }, // apply clipboard data for IE/Firefox pasteText : function() { paste .getClipboardText(function(clipboardData) { if (clipboardData) { var clipData = clipboardData.toString(); var params = 'data-copy-websdk=' + clipData + '&data-copy-text=' + clipData + '&data-copy-text-html=' + clipData; params = 'TARGET_ID=' + targetElement.attr('id').toString() + '&' + params; display_submitForm(targetAction, 'PASTE', targetContainerId, params); } }); }, // apply clipboard data for QT browser pasteData : function(e) { var clipboardData = ''; for (mimeType in dataTypeMap) { var clipboard = e.clipboardData.getData(mimeType); if (clipboard) { clipboardData += '&' + dataTypeMap[mimeType] + '=' + clipboard.toString(); } } if (clipboardData) { display_submitForm(targetAction, 'PASTE', targetContainerId, 'TARGET_ID=' + targetElement.attr('id').toString() + clipboardData); } }, // helper method, only for IE/Firefox getClipboardText : function(callback) { var clipData = ""; if (window.clipboardData && clipboardData.getData) { // set selections from clipboard value clipData = clipboardData.getData("Text"); } else if (top.siemensWebSDKAddon) { // create one-time event listener to invoke the callback var listener = null; listener = function(event) { top.removeEventListener('WebSDKPushClipboard', listener, false); callback(event.detail.data); }; // register for push clipboard event coming from firefox extension top.addEventListener('WebSDKPushClipboard', listener, false); // generate an event to trigger firefox extension to push clipboard var event = new CustomEvent("WebSDKGrabClipboard", { "detail" : { "dataType" : "text" } }); top.dispatchEvent(event); return; } if (callback) { callback(clipData); } else { return clipData; } }, clearEventProperties : function() { targetElement = ''; targetAction = ''; targetContainerId = ''; } }); });