From 72aed21a39865c5fd5ec248bf2656fc5ca33010a Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 24 Feb 2010 13:40:39 +0200 Subject: [PATCH 1/3] - Added a small CSS fix for short pages. - Set the login page to redirect to the referer except when there's already a redirect url specified, and when the previous url is the login page. - Linked the ScribeEngine in the page footer to the project page. - Added auto-expanding comment text areas. --- development.ini | 1 + scribeengine/controllers/account.py | 10 ++++++- scribeengine/controllers/blog.py | 5 ++++ .../public/scripts/ScribeEngine.Blog.js | 26 +++++++++++++++++++ scribeengine/public/scripts/ScribeEngine.js | 4 +++ scribeengine/public/scripts/jquery.elastic.js | 1 + scribeengine/public/styles/style.css | 4 +++ scribeengine/templates/base.mako | 2 +- 8 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 scribeengine/public/scripts/ScribeEngine.Blog.js create mode 100644 scribeengine/public/scripts/jquery.elastic.js diff --git a/development.ini b/development.ini index 0e738fe..f2463cf 100644 --- a/development.ini +++ b/development.ini @@ -23,6 +23,7 @@ static_files = true cache_dir = %(here)s/data beaker.session.key = scribeengine beaker.session.secret = somesecret +beaker.session.timeout = 1209600 # If you'd like to fine-tune the individual locations of the cache data dirs # for the Cache data, or the Session saves, un-comment the desired settings diff --git a/scribeengine/controllers/account.py b/scribeengine/controllers/account.py index f8b330e..93434de 100644 --- a/scribeengine/controllers/account.py +++ b/scribeengine/controllers/account.py @@ -23,6 +23,7 @@ import logging import string import random +from urlparse import urlsplit from datetime import datetime from formencode.validators import Int @@ -208,6 +209,9 @@ class AccountController(BaseController): h.redirect_to('/account/login') def login(self): + if u'redirect_url' not in session and u'REFERER' in request.headers: + session[u'redirect_url'] = str(urlsplit(request.headers[u'REFERER']).path) + session.save() c.page_title = u'Login' return render(u'/account/login.mako') @@ -239,9 +243,13 @@ class AccountController(BaseController): elif user and user.password == password: log.debug('Logged in successfully.') redirect_url = str(session.get(u'redirect_url', u'/')) - session[u'REMOTE_USER'] = user.id if u'redirect_url' in session: del session[u'redirect_url'] + else: + redirect_url = '/' + if redirect_url == '/account/login': + redirect_url = '/' + session[u'REMOTE_USER'] = user.id session.save() h.flash.set_message(u'You have logged in successfully.', u'success') h.redirect_to(redirect_url) diff --git a/scribeengine/controllers/blog.py b/scribeengine/controllers/blog.py index 9f7de2d..39660e8 100644 --- a/scribeengine/controllers/blog.py +++ b/scribeengine/controllers/blog.py @@ -35,6 +35,11 @@ log = logging.getLogger(__name__) class BlogController(BaseController): + def __before__(self): + BaseController.__before__(self) + self._add_javascript(u'jquery.elastic.js') + self._add_javascript(u'ScribeEngine.Blog.js') + def index(self): posts = Session.query(Post)\ .filter_by(status=u'published')\ diff --git a/scribeengine/public/scripts/ScribeEngine.Blog.js b/scribeengine/public/scripts/ScribeEngine.Blog.js new file mode 100644 index 0000000..96ab64f --- /dev/null +++ b/scribeengine/public/scripts/ScribeEngine.Blog.js @@ -0,0 +1,26 @@ +/***************************************************************************** + * ScribeEngine - Open Source Blog Software * + * ------------------------------------------------------------------------- * + * Copyright (c) 2010 Raoul Snyman * + * ------------------------------------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; version 2 of the License. * + * * + * This program is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * + * Public License for more details. * + * * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + *****************************************************************************/ + +ScribeEngine.Namespace.create("ScribeEngine.Blog", { + +}); + +ScribeEngine.Events.load(function () { + ScribeEngine.Widgets.elastic("#commentform textarea"); +}); diff --git a/scribeengine/public/scripts/ScribeEngine.js b/scribeengine/public/scripts/ScribeEngine.js index 4aa3397..fa84f37 100644 --- a/scribeengine/public/scripts/ScribeEngine.js +++ b/scribeengine/public/scripts/ScribeEngine.js @@ -126,6 +126,10 @@ ScribeEngine.Namespace.create("ScribeEngine.Widgets", { tagEditor: function (selector) { $(selector).tagEditor({completeOnBlur: true, initialParse: true}); + }, + elastic: function (selector) + { + $(selector).elastic(); } }); diff --git a/scribeengine/public/scripts/jquery.elastic.js b/scribeengine/public/scripts/jquery.elastic.js new file mode 100644 index 0000000..6f3d4e0 --- /dev/null +++ b/scribeengine/public/scripts/jquery.elastic.js @@ -0,0 +1 @@ +(function(jQuery){jQuery.fn.extend({elastic:function(){var mimics=['paddingTop','paddingRight','paddingBottom','paddingLeft','fontSize','lineHeight','fontFamily','width','fontWeight'];return this.each(function(){if(this.type!='textarea'){return false}var $textarea=jQuery(this),$twin=jQuery('
').css({'position':'absolute','display':'none','word-wrap':'break-word'}),lineHeight=parseInt($textarea.css('line-height'),10)||parseInt($textarea.css('font-size'),'10'),minheight=parseInt($textarea.css('height'),10)||lineHeight*3,maxheight=parseInt($textarea.css('max-height'),10)||Number.MAX_VALUE,goalheight=0,i=0;if(maxheight<0){maxheight=Number.MAX_VALUE}$twin.appendTo($textarea.parent());var i=mimics.length;while(i--){$twin.css(mimics[i].toString(),$textarea.css(mimics[i].toString()))}function setHeightAndOverflow(height,overflow){curratedHeight=Math.floor(parseInt(height,10));if($textarea.height()!=curratedHeight){$textarea.css({'height':curratedHeight+'px','overflow':overflow})}}function update(){var textareaContent=$textarea.val().replace(/&/g,'&').replace(/ /g,' ').replace(/<|>/g,'>').replace(/\n/g,'
');var twinContent=$twin.html();if(textareaContent+' '!=twinContent){$twin.html(textareaContent+' ');if(Math.abs($twin.height()+lineHeight-$textarea.height())>3){var goalheight=$twin.height()+lineHeight;if(goalheight>=maxheight){setHeightAndOverflow(maxheight,'auto')}else if(goalheight<=minheight){setHeightAndOverflow(minheight,'hidden')}else{setHeightAndOverflow(goalheight,'hidden')}}}}$textarea.css({'overflow':'hidden'});$textarea.keyup(function(){update()});$textarea.live('input paste',function(e){setTimeout(update,250)});update()})}})})(jQuery); \ No newline at end of file diff --git a/scribeengine/public/styles/style.css b/scribeengine/public/styles/style.css index 14da007..2b8bf64 100644 --- a/scribeengine/public/styles/style.css +++ b/scribeengine/public/styles/style.css @@ -9,6 +9,10 @@ Released for free under a Creative Commons Attribution 2.5 License padding: 0; } +html { + background-color: #000000; +} + body { background: #000000 url(../images/img01.gif) repeat-x; font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; diff --git a/scribeengine/templates/base.mako b/scribeengine/templates/base.mako index 70c0b3e..57172e8 100644 --- a/scribeengine/templates/base.mako +++ b/scribeengine/templates/base.mako @@ -52,7 +52,7 @@

From 170bc0822c23e23e3b53655fac817fa2b69dcbbb Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 24 Feb 2010 13:53:03 +0200 Subject: [PATCH 2/3] Added a simple print stylesheet. --- scribeengine/public/styles/print.css | 12 ++++++++++++ scribeengine/templates/base.mako | 1 + 2 files changed, 13 insertions(+) create mode 100644 scribeengine/public/styles/print.css diff --git a/scribeengine/public/styles/print.css b/scribeengine/public/styles/print.css new file mode 100644 index 0000000..f39432e --- /dev/null +++ b/scribeengine/public/styles/print.css @@ -0,0 +1,12 @@ +body { + background-color: #ff; + font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; + font-size: 13px; + color: #000; +} + +#menu, +#sidebar, +#commentform { + display: none; +} diff --git a/scribeengine/templates/base.mako b/scribeengine/templates/base.mako index 57172e8..e81957c 100644 --- a/scribeengine/templates/base.mako +++ b/scribeengine/templates/base.mako @@ -9,6 +9,7 @@ + % for script in c.scripts: % endfor From 9134fc8f78939b27b425399062f80bdc382296ee Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 24 Feb 2010 13:54:09 +0200 Subject: [PATCH 3/3] A small fix in the print stylesheet. --- scribeengine/public/styles/print.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scribeengine/public/styles/print.css b/scribeengine/public/styles/print.css index f39432e..4635aca 100644 --- a/scribeengine/public/styles/print.css +++ b/scribeengine/public/styles/print.css @@ -1,5 +1,6 @@ +html, body { - background-color: #ff; + background-color: #fff; font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; font-size: 13px; color: #000;