Commits

Anonymous committed 53c729a

working darg and drop.

Comments (0)

Files changed (2)

static/css/src/layout.css

 }
 
 
-#freview {
+.comment-box #freview {
     width: 100%;
     padding: 0.3em;
     margin: 0;
     position: relative;
 }
 
-#freview textarea#new_review {
+#freview textarea {
     height: 120px;
-    /*position: relative;*/
+    position: relative;
 }
 
 .reviewflag {

static/js/src/review.js

             if (!el.classList.has("line-number") &&  (!pel.classList.has("line-number"))) 
                 return;
         
-        this.el =  this.currentRow.querySelector("td");
+        this.el = this.currentRow.querySelector("td");
         if (this.ghostReview && !this.ghostReview.classList.has('hidden'))
             this.ghostReview.classList.add('hidden');
 
 
         var div = document.createElement("div");
         div.classList.add("comment-box");
+        div.classList.add("hidden");
         div.setStyle("z-index: 10000");
         div.setOpacity("0.9");
 
         document.body.appendChild(this.overlay);
         document.body.appendChild(this.divComment);
 
-        if (base2.detect("MSIE")) {
-            this.ieframe = document.createElement("iframe");
-            this.ieframe.id="overlay-frame";
-            this.ieframe.setStyle("z-index:1000;border:none;margin:0;padding:0;position:absolute;width:100%;height:100%;top:0;left:0");
-            this.ieframe.setOpacity("0");
-            document.body.appendChild(this.ieframe);
-        }
-
-
         var lineNumber = this._lineNumberForRow(this.currentRow);
         
         var url = '/' + snippet_id + '/reviews/' + lineNumber;
         var form = document.createElement('form');
         form.action  = action;
         form.id = 'freview';
+        div.appendChild(form);
         var h3 = document.createElement('h3');
         h3.appendChild(document.createTextNode('Add your review to line ' + 
                     lineNumber));
         bclose.value = 'close';
         p.appendChild(bclose);
         form.appendChild(p);
-        div.appendChild(form);
+        
         var comments_title = document.createElement('h3');
         comments_title.appendChild(document.createTextNode('All comments for this line'));
         div.appendChild(comments_title);
         sreview.addEventListener("click", this.add_review.bind(this), false);
 
         if(!base2.detect("webkit"))
-            new Resizeable('#new_review', 120);
-
-        textarea.focus();
+            new Resizeable('#new_review', 120); 
 
         new Ajax.request({
             url: url,
                 method: "POST",
                 success: function(data) {
                     if (data["ok"]) {
-                        
-                         
-                        
                         // refresh reviews list
                         if (!ul) { 
                             ul = document.createElement('ul');
                                 ul.insertBefore(li, ul.firstChild);
                             }
                         }
-                        // update number of reviews in review flag
-                        /*self._reviews[lineNumber] = self.currentRow;
-                        var span_count = self.currentRow.querySelector('span.reviewflag');
-                        line_count = parseInt(span_count.innerHTML);
-                        if (line_count < data['count'])
-                            span_count.innerHTML = data['count'];
-                        
-                        if (!self.currentRow.classList.has('hasreview'))
-                            self.currentRow.classList.add('hasreview');*/
-
                         // reset textarea
                         textarea.value = '';
                         textarea.focus();
         this.divComment.classList.add("hidden");
         remove(this.divComment);
         remove(this.overlay);
-        if (this.ieframe)
-            remove(this.ieframe);
 
         if (this.hideIfClickOutside) {
             document.removeEventListener("click", this.hideIfClickOutside, false);
          // handle drag and drop
         this.isDragging = false;
         this.divComment.removeEventListener('mousedown', this.beginDragCB, false);
-        this.divComment.removeEventListener('mousemove', this.dragCB, false);
-        this.divComment.removeEventListener('mouseup', this.endDragCB, false);
+        document.removeEventListener('mousemove', this.dragCB, false);
+        document.removeEventListener('mouseup', this.endDragCB, false);
     },
 
     setCommentBoxPosition: function() {
         var offset = this.el.getOffsets();
-        this.divComment.style.top = offset.y + this.el.outerHeight() + 5 + "px";
+    
+        var p = [
+            offset.y + this.el.outerHeight() + 5,
+            offset.x + this.el.offsetWidth + 20
+        ];
 
-        this.divComment.style.left = offset.x + this.el.offsetWidth + 20 + "px";
+        this.divComment.style.top = p[0] + "px";
+        this.divComment.style.left =  p[1] + "px";
         
-        if (this.ieframe) {
-            this.ieframe.width = this.divComment.outerWidth();
-            this.ieframe.height = this.divComment.outerHeight();
-        }
         window.scrollTo(document.body.scrollLeft, offset.y - 64);
+        this.divComment.classList.remove('hidden');
+        this.divComment.querySelector('textarea').focus();
         resizeBottom();
     },
 
         offset.right = offset.x + this.divComment.outerWidth();
         offset.bottom = offset.y + this.divComment.outerHeight();
         
-        if (!e.pageY && !e.pageY) {
-            var docElement = document.documentElement;
-            e.pageX = e.clientX + 
-                (docElement.scrollLeft || document.body.scrollLeft) -
-                (docElement.clientLeft || 0);
-            e.pageY = e.clientY +  
-                (docElement.scrollTop || document.body.scrollTop) -
-                (docElement.clientTop || 0);
-        }
-
-        return e.pageY < offset.bottom &&
-            e.pageY > offset.y &&
-            e.pageX < offset.right &&
-            e.pageX > offset.x;
+        point = pointer(e);
+        
+        return point.y < offset.bottom &&
+            point.y > offset.y &&
+            point.x < offset.right &&
+            point.x > offset.x;
     }, 
 
     currentDelta: function() {
             tag_name=='TEXTAREA')) return;
         
         this.isDragging = true;
-        e.target.focus();
 
         this.divComment.style.cursor = "move";
         var point = pointer(e);
        
         this.offset = [point.x - pos.x, point.y - pos.y];
         this.pointer = point;
+        this.boxDimensions = this.divComment.getDimensions();
 
         // remove text selection
         document.body.focus();
     dragCB: function(e) {
         if (!this.isDragging) 
             return;
-       
-         
+      
+        if (!e)
+           e = window.event;
+
+        var e = e;
         var point = pointer(e);
         var pos = this.divComment.cumulativeOffset();
 
-        var diffX = Math.abs(point.x - this.pointer.x);
-        var diffY = Math.abs(point.y -this.pointer.y);
-
-        if (diffX < 3 || diffY < 3)
-            return;
-
         var d = this.currentDelta();
         pos.x -= d[0];
         pos.y -= d[1];
         this.divComment.style.left = p[0] + "px";
         this.divComment.style.top = p[1] + "px";
 
-
-
         if (base2.detect('webkit'))
              window.scrollBy(0,0);
 
+        // autoscroll
+        var self = this;
+        setTimeout(function() { 
+            var bottom =  p[1] + self.divComment.outerHeight()
+            var right = p[0] + self.divComment.outerWidth();
+
+            T = document.body.scrollTop;
+            L = document.body.scrolLeft;
+        
+            if (bottom > document.body.offsetHeight - 15)
+                window.scrollBy(0, bottom); 
+            else if (bottom < 15)
+                window.scrollBy(0, right);
+            if (right > document.body.offsetWidth)
+                 window.scrollBy(right, 0);
+            else if (right < 15)
+                window.scrollBy(-right, 0);
+
+        }, 10); 
+
         this.pointer = pointer(e);
         e.preventDefault();
         e.stopPropagation();
             document.onselectstart = this.old_onselectstart;
             this.old_onsselectstart = null;
         }
-
         this.divComment.style.cursor = "default";
+        this.divComment.querySelector('textarea').focus();
     },
 
     showCommentBox: function() {
         // handle drag and drop
         this.divComment.addEventListener('mousedown', 
                 this.beginDragCB.bind(this), false);
-        this.divComment.addEventListener('mousemove', 
+        document.addEventListener('mousemove', 
                 this.dragCB.bind(this), false);
-        this.divComment.addEventListener('mouseup', 
+        document.addEventListener('mouseup', 
                 this.endDragCB.bind(this), false);
         
         var self = this;