Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
danja committed Jan 30, 2015
1 parent 23d8337 commit 9bc6124
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 2 deletions.
1 change: 1 addition & 0 deletions css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ legend {
textarea {
display: block;
width: 100%;
height:auto ;
border: 2px solid pink;
font-size: 75%;
}
Expand Down
3 changes: 3 additions & 0 deletions edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<script src="js/jquery-1.10.2.js"></script>
<script src="js/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.autogrowtextarea.js"></script>

<!-- from https://github.com/aehlke/tag-it -->
<script src="js/tag-it.js" type="text/javascript" charset="utf-8"></script>
Expand Down Expand Up @@ -83,6 +84,8 @@

setupTags("#maintagscontainer", pageMap, false);
// $("##foowikitagscontainer").tagit({

$("textarea").autoGrow();
};
getDataForURL(doneCallback, getPageUrl);
setupPosting();
Expand Down
2 changes: 2 additions & 0 deletions js/foowiki-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ function getPage() {
}

function formatEntry(entry) {
// entry.content = unescapeLiterals(entry.content);

entry.content = tweakBlockquotes(entry.content);
entry.content = marked(entry.content);

Expand Down
3 changes: 2 additions & 1 deletion js/html-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var rowTemplate = " <tr> \
<td class='center'>~{nick}~</td> \
</tr>";

/* rows='20' */
var editEntryTemplate = "<div class='entry'> \
<h1 class='center'><a href=\"~{uri}~\">~{title}~</a></h1> \
<form> \
Expand All @@ -41,7 +42,7 @@ var editEntryTemplate = "<div class='entry'> \
<label for='title'>Title</label> \
<input id='title' type='text' value='~{title}~'></input> \
<label for='content'>Content</label> \
<textarea class='content' id='content' rows='20'>~{content}~</textarea> \
<textarea class='content' id='content' >~{content}~</textarea> \
<label for='maintagscontainer'>Tags</label> \
<ul id='maintagscontainer' id='allowSpacesTags'> \
</ul> \
Expand Down
61 changes: 61 additions & 0 deletions js/jquery.autogrowtextarea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <[email protected]> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. Jevin O. Sewaruth
* ----------------------------------------------------------------------------
*
* Autogrow Textarea Plugin Version v3.0
* http://www.technoreply.com/autogrow-textarea-plugin-3-0
*
* THIS PLUGIN IS DELIVERD ON A PAY WHAT YOU WHANT BASIS. IF THE PLUGIN WAS USEFUL TO YOU, PLEASE CONSIDER BUYING THE PLUGIN HERE :
* https://sites.fastspring.com/technoreply/instant/autogrowtextareaplugin
*
* Date: October 15, 2012
*/

jQuery.fn.autoGrow = function() {
return this.each(function() {

var createMirror = function(textarea) {
jQuery(textarea).after('<div class="autogrow-textarea-mirror"></div>');
return jQuery(textarea).next('.autogrow-textarea-mirror')[0];
}

var sendContentToMirror = function (textarea) {
mirror.innerHTML = String(textarea.value).replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#39;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '<br />') + '.<br/>.';

if (jQuery(textarea).height() != jQuery(mirror).height())
jQuery(textarea).height(jQuery(mirror).height());
}

var growTextarea = function () {
sendContentToMirror(this);
}

// Create a mirror
var mirror = createMirror(this);

// Style the mirror
mirror.style.display = 'none';
mirror.style.wordWrap = 'break-word';
mirror.style.whiteSpace = 'normal';
mirror.style.padding = jQuery(this).css('padding');
mirror.style.width = jQuery(this).css('width');
mirror.style.fontFamily = jQuery(this).css('font-family');
mirror.style.fontSize = jQuery(this).css('font-size');
mirror.style.lineHeight = jQuery(this).css('line-height');

// Style the textarea
this.style.overflow = "hidden";
this.style.minHeight = this.rows+"em";

// Bind the textarea's event
this.onkeyup = growTextarea;

// Fire the event for text already present
sendContentToMirror(this);

});
};
13 changes: 12 additions & 1 deletion js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
var template = Hogan.compile(raw, {
delimiters: '~{ }~'
});

var result = template.render(replacementMap);
return htmlUnescape(result);
}
Expand Down Expand Up @@ -125,9 +126,18 @@
markup = markup.replace(/&/g, "&amp;");
markup = markup.replace(/</g, "&lt;");
markup = markup.replace(/>/g, "&gt;");
// markup = escapeLiterals(markup);
return markup;
}

function unescapeLiterals(text) {
return text.replace(/&#34&#34&#34/g, '"""');
}

function escapeLiterals(text) {
text.replace(/"""/g, "&#34&#34&#34");
}

function escapeRegExp(string) {
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
Expand All @@ -151,13 +161,14 @@

value = value.replace(/&lt;/g, "<");
value = value.replace(/&gt;/g, ">");

value = value.replace(/&quot;/g, "\"");
value = value.replace(/&amp;/g, "&");

return value;
}

function hUnescape(value) {

var d = $("<div>");
d.html(value);
return d.text();
Expand Down

0 comments on commit 9bc6124

Please sign in to comment.