Improved work-around for pasting on iOS
authorAlexander Ebert <ebert@woltlab.com>
Tue, 10 Feb 2015 17:05:58 +0000 (18:05 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 10 Feb 2015 17:05:58 +0000 (18:05 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index 29bfc4fe7ae6c52437acb7ee6397beb1831d26af..ba21de8d9120751ee36037b11cbab28ec2067ce0 100644 (file)
@@ -1035,7 +1035,21 @@ RedactorPlugins.wmonkeypatch = function() {
                        var $mpCreatePasteBox = this.paste.createPasteBox;
                        this.paste.createPasteBox = (function() {
                                if ($.browser.iOS) {
-                                       this.$pasteBox = $('<div>').html('').attr('contenteditable', 'true').css({ position: 'absolute', visibility: 'hidden' });
+                                       var $top = 0;
+                                       if (window.getSelection().rangeCount) {
+                                               var $container = window.getSelection().getRangeAt(0).endContainer;
+                                               if ($container.nodeType !== Node.ELEMENT_NODE) {
+                                                       $container = $container.parentElement;
+                                               }
+                                               $container = $($container);
+                                               
+                                               $top = $($container).offset().top;
+                                       }
+                                       else {
+                                               $top = $(window).scrollTop();
+                                       }
+                                       
+                                       this.$pasteBox = $('<div>').html('').attr('contenteditable', 'true').css({ position: 'fixed', /*width: 0, */top: $top + 'px', /*left: '-9999px', */fontSize: '16px' });
                                        
                                        this.$box.parent().append(this.$pasteBox);
                                        this.$pasteBox.focus();