|
@@ -19,66 +19,103 @@ SC.loadPackage({ 'MenuItemPaste': {
|
|
|
this.delegate('MenuItem', 'init', theDocumentMenu);
|
|
|
this.set({ isActionButton: true });
|
|
|
|
|
|
+
|
|
|
+ var self = this;
|
|
|
+
|
|
|
this.get('menuButton').addEventListener('mouseup', function(){
|
|
|
|
|
|
SuperGlue.get('clipboard').do('paste', function(pasteData){
|
|
|
|
|
|
- var domNodes, newNode, newChild, offset;
|
|
|
+ if(pasteData.indexOf('class="sg-element"') > -1){
|
|
|
+
|
|
|
+ self.do('pasteSGElement', pasteData);
|
|
|
+
|
|
|
+ }else{
|
|
|
+
|
|
|
+ self.do('pasteText', pasteData);
|
|
|
|
|
|
- try{
|
|
|
- domNodes = (new DOMParser()).parseFromString(pasteData, 'text/html').body.children;
|
|
|
- domNodes = Array.prototype.slice.call(domNodes);
|
|
|
- }catch(e){
|
|
|
- return;
|
|
|
}
|
|
|
|
|
|
+ theDocumentMenu.do('close');
|
|
|
|
|
|
- offset = SuperGlue.get('document').get('grid').get('active')
|
|
|
- ? SuperGlue.get('document').get('grid').get('gridSize')
|
|
|
- : 10;
|
|
|
|
|
|
- SC.setHandlerForMessageNotUnderstood(function(message, reason, params){
|
|
|
- throw new Error('SC: Message not understood: ' + message + '; ' + reason);
|
|
|
- });
|
|
|
+ });
|
|
|
|
|
|
- for(var i = 0, l = domNodes.length; i < l; i++){
|
|
|
+ }, false)
|
|
|
|
|
|
- newNode = domNodes[i];
|
|
|
+ }
|
|
|
|
|
|
- newNode.removeAttribute('data-superglue-group')
|
|
|
+ },
|
|
|
|
|
|
- try{
|
|
|
+ pasteSGElement: {
|
|
|
+ comment: 'I paste a SuperGlue Element.',
|
|
|
+ code: function(pasteData){
|
|
|
|
|
|
- SuperGlue.get('document').get('pageContainer').appendChild(newNode);
|
|
|
+ var domNodes, newNode, newChild, offset;
|
|
|
|
|
|
- newChild = SC.do('Element', 'awakeFromDOM', newNode)
|
|
|
- newChild.set({
|
|
|
- top: newChild.get('top') + offset,
|
|
|
- left: newChild.get('left') + offset
|
|
|
- })
|
|
|
+ try{
|
|
|
+ domNodes = (new DOMParser()).parseFromString(pasteData, 'text/html').body.children;
|
|
|
+ domNodes = Array.prototype.slice.call(domNodes);
|
|
|
+ }catch(e){
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- }catch(e){
|
|
|
- SuperGlue.get('document').get('pageContainer').removeChild(newNode);
|
|
|
- continue;
|
|
|
- }
|
|
|
|
|
|
- SuperGlue.get('document').get('children').push(newChild);
|
|
|
- SuperGlue.get('document').do('afterLayoutHasChanged');
|
|
|
+ offset = SuperGlue.get('document').get('grid').get('active')
|
|
|
+ ? SuperGlue.get('document').get('grid').get('gridSize')
|
|
|
+ : 10;
|
|
|
|
|
|
- }
|
|
|
+ SC.setHandlerForMessageNotUnderstood(function(message, reason, params){
|
|
|
+ throw new Error('SC: Message not understood: ' + message + '; ' + reason);
|
|
|
+ });
|
|
|
|
|
|
- SC.setHandlerForMessageNotUnderstood();
|
|
|
+ for(var i = 0, l = domNodes.length; i < l; i++){
|
|
|
|
|
|
- theDocumentMenu.do('close');
|
|
|
+ newNode = domNodes[i];
|
|
|
|
|
|
+ newNode.removeAttribute('data-superglue-group');
|
|
|
|
|
|
- });
|
|
|
+ try{
|
|
|
|
|
|
- }, false)
|
|
|
+ SuperGlue.get('document').get('pageContainer').appendChild(newNode);
|
|
|
|
|
|
- }
|
|
|
+ newChild = SC.do('Element', 'awakeFromDOM', newNode)
|
|
|
+ newChild.set({
|
|
|
+ top: newChild.get('top') + offset,
|
|
|
+ left: newChild.get('left') + offset
|
|
|
+ })
|
|
|
+
|
|
|
+ }catch(e){
|
|
|
+ SuperGlue.get('document').get('pageContainer').removeChild(newNode);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ SuperGlue.get('document').get('children').push(newChild);
|
|
|
+ SuperGlue.get('document').do('afterLayoutHasChanged');
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ SC.setHandlerForMessageNotUnderstood();
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ pasteText: {
|
|
|
+ comment: 'I paste text as TextElement.',
|
|
|
+ code: function(pasteData){
|
|
|
+
|
|
|
+ SuperGlue.get('document').do('createNewElement', {
|
|
|
+ classname: 'TextElement',
|
|
|
+ top: 30,
|
|
|
+ left: 30,
|
|
|
+ width: 200,
|
|
|
+ height: 140
|
|
|
+ }).get('node').innerHTML = pasteData;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|