1
0
mirror of synced 2025-11-06 04:30:40 +08:00

Initial fix for auto-height and multiple editors.

This commit is contained in:
Jamie Peabody
2013-03-09 13:48:46 +00:00
parent c382afa2a5
commit a3e50f8d8e
2 changed files with 114 additions and 6 deletions

96
examples/example4.html Executable file
View File

@@ -0,0 +1,96 @@
<!--
This example demonstrates how to enable line wrapping
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" /><title>Mergely - Simple Example</title>
<meta http-equiv="X-UA-Compatible" content="chrome=1, IE=edge">
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<meta name="description" content="Merge and Diff your documents with diff online and share" />
<meta name="keywords" content="diff,merge,compare,jsdiff,comparison,difference,file,text,unix,patch,algorithm,saas,longest common subsequence" />
<meta name="author" content="Jamie Peabody" />
<!-- Requires jQuery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js" type="text/javascript"></script>
<!-- Requires CodeMirror -->
<script type="text/javascript" src="../lib/codemirror.js"></script>
<link type="text/css" rel="stylesheet" href="../lib/codemirror.css" />
<!-- Requires Mergely -->
<script type="text/javascript" src="../lib/mergely.js"></script>
<link type="text/css" rel="stylesheet" href="../lib/mergely.css" />
<script type="text/javascript">
$(document).ready(function () {
$('#compare1').mergely({
width: 'auto',
height: 200,
cmsettings: {
readOnly: false,
lineWrapping: true,
}
});
$('#compare2').mergely({
width: 'auto',
height: 200,
cmsettings: {
readOnly: false,
lineWrapping: true,
}
});
$('#compare3').mergely({
width: 500,
height: 200,
cmsettings: {
readOnly: false,
lineWrapping: true,
}
});
$('#compare4').mergely({
width: 500,
height: 200,
cmsettings: {
readOnly: false,
lineWrapping: true,
}
});
$.ajax({
type: 'GET', async: true, dataType: 'text',
url: 'lhs_long.txt',
success: function (response) {
$('#compare1').mergely('lhs', response);
$('#compare2').mergely('lhs', response);
$('#compare3').mergely('lhs', response);
$('#compare4').mergely('lhs', response);
}
});
$.ajax({
type: 'GET', async: true, dataType: 'text',
url: 'rhs_long.txt',
success: function (response) {
$('#compare1').mergely('rhs', response);
$('#compare2').mergely('rhs', response);
$('#compare3').mergely('rhs', response);
$('#compare4').mergely('rhs', response);
}
});
});
</script>
</head>
<body>
<div id="compare1"></div>
<div id="compare2"></div>
<table style="width:100%">
<tr>
<td><div id="compare3"></div></td>
<td><div id="compare4"></div></td>
</tr>
</table>
</body>
</html>

View File

@@ -369,13 +369,25 @@ jQuery.extend(Mgly.mergely.prototype, {
lhs: function(setValue) { },
rhs: function(setValue) { },
loaded: function() { },
height: function(h) { return h - 20; },
width: function(w) { return w; },
_auto_height: function(h) { return h - 20; },
_auto_width: function(w) { return w; },
resize: function() {
var w = jQuery(el).parent().width();
var h = jQuery(window).height();
if (this.width) w = this.width(w);
if (this.height) h = this.height(h);
if (this.width == 'auto') {
w = this._auto_width(w);
}
else {
w = this.width;
this.editor_width = w;
}
if (this.height == 'auto') {
h = this._auto_height(h);
}
else {
h = this.height;
this.editor_height = h;
}
var content_width = w / 2.0 - 2 * 8 - 8;
var content_height = h;
var self = jQuery(el);
@@ -383,7 +395,7 @@ jQuery.extend(Mgly.mergely.prototype, {
self.find('.mergely-column, .mergely-canvas, .mergely-margin, .mergely-column textarea, .CodeMirror-scroll, .cm-s-default').css({ 'height': content_height + 'px' });
self.find('.mergely-canvas').css({ 'height': content_height + 'px' });
self.find('.mergely-column textarea').css({ 'width': content_width + 'px' });
self.css({ 'width': w + 'px', 'height': h + 'px' });
self.css({ width: w, height: h, clear: 'both' });
if (self.css('display') == 'none') {
if (this.fadein != false) self.fadeIn(this.fadein);
else self.show();
@@ -1190,7 +1202,7 @@ jQuery.extend(Mgly.mergely.prototype, {
var dcanvas = document.getElementById(editor_name1 + '-' + editor_name2 + '-canvas');
if (dcanvas == undefined) throw 'Failed to find: ' + editor_name1 + '-' + editor_name2 + '-canvas';
jQuery.each(jQuery('canvas'), function () {
jQuery.each(jQuery.find('#' + this.id + ' canvas'), function () {
jQuery(this).get(0).height = visible_page_height;
});
var clhs = jQuery('#' + this.id + '-lhs-margin');