-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* list-style now shows a disc * Index page shows "other" posts in correct way * Add scroll to post list and autoloading of more posts * Change view of listed post * Add errors to forms
- Loading branch information
Showing
17 changed files
with
1,102 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
class PostsController < ApplicationController | ||
|
||
def index | ||
@posts = Post.latest | ||
@posts = Post.scoped | ||
@posts = @posts.latest.limit(20).includes(:tags) | ||
@posts = @posts.offset(params[:offset].to_i) if params[:offset] | ||
render :partial => "listed_post", :collection => @posts.all if params[:list] | ||
end | ||
|
||
def show | ||
@post = Post.find_by_id(params[:id]) | ||
@posts = Post.latest - [@post] | ||
@posts = Post.latest.limit(20).includes(:tags) - [@post] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
- stylesheet "posts" | ||
- javascript "elastic" | ||
|
||
= form_for [:admin, @post] do |f| | ||
= f.label :title | ||
%br | ||
= f.text_field :title | ||
%br | ||
= f.label :tag_list | ||
%br | ||
= f.text_field :tag_list | ||
%br | ||
= f.label :body | ||
%br | ||
= f.text_area :body | ||
%br | ||
= f.label :published_on | ||
%br | ||
= f.date_select :published_on | ||
%br | ||
= f.submit "Save", :class => "button" | ||
= f.submit "Save", :class => "button medium" | ||
|
||
:javascript | ||
$('textarea#post_body').elastic(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
= render "posts_list" | ||
- content_for(:menu) do | ||
%p | ||
= link_to "Write a new post", [:new, :admin, :post], :class => "button in_menu" | ||
|
||
|
||
- content_for(:bottom) do | ||
= render "posts_list" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/** | ||
* @name Elastic | ||
* @descripton Elastic is Jquery plugin that grow and shrink your textareas automaticliy | ||
* @version 1.6.4 | ||
* @requires Jquery 1.2.6+ | ||
* | ||
* @author Jan Jarfalk | ||
* @author-email jan.jarfalk@unwrongest.com | ||
* @author-website http://www.unwrongest.com | ||
* | ||
* @licens MIT License - http://www.opensource.org/licenses/mit-license.php | ||
*/ | ||
|
||
(function(jQuery){ | ||
jQuery.fn.extend({ | ||
elastic: function() { | ||
|
||
// We will create a div clone of the textarea | ||
// by copying these attributes from the textarea to the div. | ||
var mimics = [ | ||
'paddingTop', | ||
'paddingRight', | ||
'paddingBottom', | ||
'paddingLeft', | ||
'fontSize', | ||
'lineHeight', | ||
'fontFamily', | ||
'width', | ||
'fontWeight']; | ||
|
||
return this.each( function() { | ||
|
||
// Elastic only works on textareas | ||
if ( this.type != 'textarea' ) { | ||
return false; | ||
} | ||
|
||
var $textarea = jQuery(this), | ||
$twin = jQuery('<div />').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; | ||
|
||
// Opera returns max-height of -1 if not set | ||
if (maxheight < 0) { maxheight = Number.MAX_VALUE; } | ||
|
||
// Append the twin to the DOM | ||
// We are going to meassure the height of this, not the textarea. | ||
$twin.appendTo($textarea.parent()); | ||
|
||
// Copy the essential styles (mimics) from the textarea to the twin | ||
var i = mimics.length; | ||
while(i--){ | ||
$twin.css(mimics[i].toString(),$textarea.css(mimics[i].toString())); | ||
} | ||
|
||
|
||
// Sets a given height and overflow state on the textarea | ||
function setHeightAndOverflow(height, overflow){ | ||
curratedHeight = Math.floor(parseInt(height,10)); | ||
if($textarea.height() != curratedHeight){ | ||
$textarea.css({'height': curratedHeight + 'px','overflow':overflow}); | ||
|
||
} | ||
} | ||
|
||
|
||
// This function will update the height of the textarea if necessary | ||
function update() { | ||
|
||
// Get curated content from the textarea. | ||
var textareaContent = $textarea.val().replace(/&/g,'&').replace(/ /g, ' ').replace(/<|>/g, '>').replace(/\n/g, '<br />'); | ||
|
||
var twinContent = $twin.html(); | ||
|
||
if(textareaContent+' ' != twinContent){ | ||
|
||
// Add an extra white space so new rows are added when you are at the end of a row. | ||
$twin.html(textareaContent+' '); | ||
|
||
// Change textarea height if twin plus the height of one line differs more than 3 pixel from textarea height | ||
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'); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
// Hide scrollbars | ||
$textarea.css({'overflow':'hidden'}); | ||
|
||
// Update textarea size on keyup | ||
$textarea.keyup(function(){ update(); }); | ||
|
||
// And this line is to catch the browser paste event | ||
$textarea.live('input paste',function(e){ setTimeout( update, 250); }); | ||
|
||
// Run update once when elastic is initialized | ||
update(); | ||
|
||
}); | ||
|
||
} | ||
}); | ||
})(jQuery); |
Oops, something went wrong.