define([ "dojo/_base/lang", "dojo/query", "dojo/NodeList-html", "dojo/NodeList-traverse" ], function(lang, query) { var pasteTA = lang.getObject("siemens.clipboard.pasteTA", true); var dataTypeMap = {}; dataTypeMap['application/json'] = "data-copy-json"; dataTypeMap['application/vnd-websdk'] = "data-copy-websdk"; var targetContainerId; var targetElement; var targetAction; var isPasteTANewRow; return lang.mixin(pasteTA, { 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'); }, paste : function(container) { targetElement = container; targetContainerId = container.id; if(targetContainerId == undefined){ targetElement = container[0]; targetContainerId = container[0].id; } if (!pasteTA.pasteCommand()) { pasteTA.pasteText(); } }, pasteTA : function(container) { isPasteTANewRow = false; pasteTA.paste(container); }, pasteTANewRow : function(container) { isPasteTANewRow = true; pasteTA.paste(container); }, // check if event clipboard and pasteTA command are supported, if so execute pasteTA command pasteCommand : function() { var pasteSucceeded = false; if (!(pasteTA.isNavigatorIE()) && document.queryCommandEnabled) { var needDesignMode = !pasteTA.isPasteCommandEnabled(); if (needDesignMode) { document.designMode = 'on'; } pasteSucceeded = (pasteTA.isPasteCommandSupported() && document.execCommand('pasteTA')); if (needDesignMode) { document.designMode = 'off'; } } return pasteSucceeded; }, // apply clipboard data for IE/Firefox pasteText : function() { pasteTA .getClipboardText(function(clipboardData) { if (clipboardData) { var clipData = clipboardData.toString(); var params = 'data-copy-websdk=' + clipData + '&data-copy-json=' + clipData; if (isPasteTANewRow) { display_submitForm('GRID_NEW_ROW_CLIPBOARD_HANDLER', 'GRID_NEW_ROW', targetElement, params); } else { params += '&TARGETID=' + targetContainerId; display_sendAction('GRID_PASTE_TA', 'PASTE_TA', 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) { if (isPasteTANewRow) { display_submitForm('GRID_NEW_ROW_CLIPBOARD_HANDLER', 'GRID_NEW_ROW', targetContainerId, clipboardData); } else { params += 'TARGETID=' + targetContainerId; display_sendAction('GRID_PASTE_TA', 'PASTE_TA', 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() { targetAction = ''; targetContainerId = ''; } }); });