Skip to content

Commit

Permalink
[FIXED JENKINS-11132] Resizable textarea handle does not work if Code…
Browse files Browse the repository at this point in the history
…Mirror is enabled

Merge remote branch 'ohtake/resizable-codemirror' into 11132
  • Loading branch information
ssogabe committed Oct 1, 2011
2 parents cb0a95e + 9912235 commit 56f2492
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -66,6 +66,9 @@
<li class=bug>
HTTPS on port 80 makes Jenkins infer his URI incorrectly
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-11151">issue 11151</a>)
<li class=bug>
Resizable textarea handle does not work if CodeMirror is enabled
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-11132">issue 11132</a>)

</ul>
</div><!--=TRUNK-END=-->
Expand Down
39 changes: 28 additions & 11 deletions war/src/main/webapp/scripts/hudson-behavior.js
Expand Up @@ -727,9 +727,17 @@ var hudsonRules = {
var h = e.clientHeight;
var config = e.getAttribute("codemirror-config") || "";
config = eval('({'+config+'})');
var w = CodeMirror.fromTextArea(e,config).getWrapperElement();
w.setAttribute("style","border:1px solid black;");
w.style.height = h+"px";
var codemirror = CodeMirror.fromTextArea(e,config);
e.codemirrorObject = codemirror;
if(typeof(codemirror.getScrollerElement) !== "function") {
// Maybe older versions of CodeMirror do not provide getScrollerElement method.
codemirror.getScrollerElement = function(){
return findElementsBySelector(codemirror.getWrapperElement(), ".CodeMirror-scroll")[0];
};
}
var scroller = codemirror.getScrollerElement();
scroller.setAttribute("style","border:1px solid black;");
scroller.style.height = h+"px";
},

// deferred client-side clickable map.
Expand Down Expand Up @@ -786,30 +794,39 @@ var hudsonRules = {
return;
}

var handle = textarea.nextSibling;
if(handle==null || handle.className!="textarea-handle") return;
// CodeMirror inserts a wrapper element next to the textarea.
// textarea.nextSibling may not be the handle.
var handles = findElementsBySelector(textarea.parentNode, ".textarea-handle");
if(handles.length != 1) return;
var handle = handles[0];

var Event = YAHOO.util.Event;

function getCodemirrorScrollerOrTextarea(){
return textarea.codemirrorObject ? textarea.codemirrorObject.getScrollerElement() : textarea;
}
handle.onmousedown = function(ev) {
ev = Event.getEvent(ev);
var offset = textarea.offsetHeight-Event.getPageY(ev);
textarea.style.opacity = 0.5;
var s = getCodemirrorScrollerOrTextarea();
var offset = s.offsetHeight-Event.getPageY(ev);
s.style.opacity = 0.5;
document.onmousemove = function(ev) {
ev = Event.getEvent(ev);
function max(a,b) { if(a<b) return b; else return a; }
textarea.style.height = max(32, offset + Event.getPageY(ev)) + 'px';
s.style.height = max(32, offset + Event.getPageY(ev)) + 'px';
return false;
};
document.onmouseup = function() {
document.onmousemove = null;
document.onmouseup = null;
textarea.style.opacity = 1;
var s = getCodemirrorScrollerOrTextarea();
s.style.opacity = 1;
}
};
handle.ondblclick = function() {
textarea.style.height = "";
textarea.rows = textarea.value.split("\n").length;
var s = getCodemirrorScrollerOrTextarea();
s.style.height = "1px"; // To get actual height of the textbox, shrink it and show its scrollbar
s.style.height = s.scrollHeight + 'px';
}
},

Expand Down

0 comments on commit 56f2492

Please sign in to comment.