Commit 034d7ee2 authored by maxwell's avatar maxwell

first commit

parent 390fffde
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
!!!
%html{:lang => I18n.locale.to_s}
%head
%title
= "#{current_user.real_name} | diaspora" if current_user
/%meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/
= stylesheet_link_tag 'mobile'
= stylesheet_link_tag 'http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css'
- if current_user
%link{:rel => "alternate", :href => "#{current_user.public_url}", :type => "application/atom+xml", :title => "Public Diaspora Feed for #{current_user.real_name}"}
/= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
= javascript_include_tag 'vendor/jquery-1.4.2.min', 'rails', 'vendor/jquery_mobile_a1'
= csrf_meta_tag
= yield(:head)
%body
#news{ :data => {:role => "page"}}
%div{:data => {:role => 'header', :nobackbtn => 'true'}}
foo
%header
.container
#notification
- flash.each do |name, msg|
= content_tag :div, msg, :id => "flash_#{name}"
#diaspora_text{:data => {:role => 'header', :nobackbtn => 'true'}}
%h1= link_to "DIASPORA", (current_user ? root_path : new_user_session_path)
%ul#user_menu
.avatar
= owner_image_tag
= link_to current_user.real_name, '#'
%li= link_to t('.view_profile'), current_user.person
%li= link_to t('.edit_profile'), edit_person_path(current_user.person)
%li= link_to t('.account_settings'), edit_user_path(current_user)
%li= link_to t('.logout.'), destroy_user_session_path
= render "shared/aspect_nav"
.container
.span-24.last
= yield
.span-24.last
= render "posts/debug"
......@@ -3,8 +3,10 @@
# the COPYRIGHT file.
class ApplicationController < ActionController::Base
has_mobile_fu
protect_from_forgery :except => :receive
before_filter :set_friends_and_status, :except => [:create, :update]
before_filter :count_requests
before_filter :set_invites
......
......@@ -18,7 +18,7 @@ class StatusMessagesController < ApplicationController
raise 'MongoMapper failed to catch a failed save' unless status_message.id
current_user.dispatch_post(status_message, :to => params[:status_message][:to])
end
render :nothing => true
redirect_to :back
end
......
......@@ -68,6 +68,9 @@ module ApplicationHelper
image_location
end
def hard_link(string, path)
link_to string, path, :rel => 'external'
end
def person_image_link(person, opts = {})
if opts[:to] == :photos
......
%div{:data => {:role => 'content'}}
%div{:data => {:role => 'fieldcontain'}}
=render 'shared/publisher', :aspect => @aspect
= render 'shared/stream', :posts => @posts
%div{:data => {:role => 'footer', :id => 'footer-toolbar', :position => 'fixed'}}
%div{:data => {:role => 'navbar'}}
%ul
%li{:class => 'ui-btn-active'}
= link_to 'posts', '#'
%li
=link_to 'friends', '#'
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
!!!
%html{:lang => I18n.locale.to_s}
%head
%title
= "#{current_user.real_name} | diaspora" if current_user
%meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/
= javascript_include_tag 'vendor/jquery-1.4.3.min.js'
= javascript_include_tag 'vendor/jquery.mobile-1.0a1.js', 'rails'
= stylesheet_link_tag "http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css"
= stylesheet_link_tag 'mobile'
= csrf_meta_tag
= yield(:head)
%body
#content{:data => {:role => 'page'}}
%div{:data => {:role => 'header', :nobackbtn => 'true'}}
%h1
= person_image_tag (current_user.person)
= current_user.real_name
= yield
%div{:data => {:role => 'fieldcontain'}}
= form_tag(people_path, :method => 'get') do
= text_field_tag 'q', nil, :placeholder => t('.search'), :type => 'search'
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
- content_for :head do
:javascript
$("div.public_toggle input").live("click", function(evt){
if($(this).attr('checked') == true){
$(".question_mark").click();
};
});
$("#publisher textarea, #publisher input").live("focus", function(evt){
$("#publisher .options_and_submit").fadeIn(50);
});
$("#publisher form").live("submit", function(evt){
$("#publisher .options_and_submit").hide();
});
#publisher
= form_for StatusMessage.new, :remote => true do |status|
%p
= status.label :message, t('.post_a_message_to', :aspect => (aspect == :all ? t('.all') : aspect))
= status.text_area :message, :rows => 2, :value => params[:prefill]
= status.hidden_field :to, :value => (aspect == :all ? aspect : aspect.id)
.options_and_submit
- if aspect == :all
= status.submit t('.share'), :title => t('.share_with_all')
- else
= status.submit t('.share'), :title => t('.share_with', :aspect => aspect)
- if aspect == :all
.public_toggle
%p.checkbox_select
= status.check_box( :public, {}, true, false )
= status.label :public, t('.make_public')
= link_to '(?)', "#question_mark_pane", :class => 'question_mark', :style=>"display:none;"
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
%li.message{:data=>{:guid=>post.id}}
= person_image_link(post.person)
.content
.from
= link_to post.person.real_name, post.person
.aspect
%ul
- if post.public?
%li= t('.the_world')
- else
- for aspect in current_user.aspects_with_post( post.id )
%li= link_to aspect.name, aspect
- if current_user.owns?(post)
.right
= link_to t('delete'), photo_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete"
= render type_partial(post), :post => post
.info
%span.time= link_to(how_long_ago(post), object_path(post))
= link_to "#{t('.show_comments')} (#{post.comments.count})", '#', :class => "show_post_comments"
= render "comments/comments", :post => post
......@@ -7,3 +7,4 @@
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
Mime::Type.register_alias "text/html", :mobile
/* Copyright (c) 2010, Diaspora Inc. This file is
* licensed under the Affero General Public License version 3 or later. See
* the COPYRIGHT file.
*/
var Publisher = {
initialize: function() {
$("ul .person").draggable({
revert: true,
start: AspectEdit.startDrag,
drag: AspectEdit.duringDrag,
stop: AspectEdit.stopDrag
});
$(".aspect ul.dropzone").droppable({
hoverClass: 'active',
drop: AspectEdit.onDropMove
});
$(".delete").live("click", AspectEdit.deletePerson);
$(".aspect h3").live('focus', AspectEdit.changeName);
},
startDrag: function() {
AspectEdit.animateImage($(this).children("img").first());
$(".draggable_info").fadeIn(100);
},
animateImage: function(image) {
image.animate({'height':80, 'width':80, 'opacity':0.8}, 200);
image.tipsy("hide");
},
duringDrag: function(event, ui) {
$(this).children("img").tipsy("hide"); //ensure this is hidden
},
stopDrag: function(event, ui) {
$(this).children("img").animate({'height':70, 'width':70, 'opacity':1}, 200);
$(".draggable_info").fadeOut(100);
},
onDropMove: function(event, ui) {
var dropzone = $(this);
var person = ui.draggable;
if (person.hasClass('request')) {
$.ajax({
type: "DELETE",
url: "/requests/" + person.attr('data-guid'),
data: {"accept" : true, "aspect_id" : dropzone.attr('data-aspect_id') },
success: function(data) {
AspectEdit.decrementRequestsCounter();
person.removeClass('request');
}
});
}
if (dropzone.attr('data-aspect_id') != person.attr('data-aspect_id')) {
$.ajax({
url: "/aspects/move_friend/",
data: {"friend_id" : person.attr('data-guid'),
"from" : person.attr('data-aspect_id'),
"to" : { "to" : dropzone.attr('data-aspect_id') }},
success: function(data) {
person.attr('data-aspect_id', dropzone.attr('data-aspect_id'));
}});
}
dropzone.closest("ul").append(person);
},
deletePersonFromAspect: function(person) {
var person_id = person.attr('data-guid');
if( $(".person[data-guid='"+ person_id +"']").length == 1) {
alert("You can not remove the person from the last aspect");
} else {
if (!person.hasClass('request')) {
$.ajax({
type: "POST",
url: "/aspects/remove_from_aspect",
data:{
'friend_id' : person_id,
'aspect_id' : person.attr('data-aspect_id') }
});
}
person.fadeOut(400, function() {
person.remove();
});
}
},
changeName: function() {
var $this = $(this);
var id = $this.closest("li.aspect").attr("data-guid");
var link = "/aspects/" + id;
$this.keypress(function(e) {
if (e.which == 13) {
e.preventDefault();
$this.blur();
//save changes
$.ajax({
type: "PUT",
url: link,
data: {"aspect" : {"name" : $this.text() }}
});
}
//update all other aspect links
$this.keyup(function(e) {
$("#aspect_nav a[href='" + link + "']").text($this.text());
});
});
},
deletePerson: function() {
var person = $(this).closest("li.person");
if (person.hasClass('request')) {
if (confirm("Ignore request?")) {
var request_id = person.attr("data-guid");
$.ajax({
type: "DELETE",
url: "/requests/" + request_id,
success: function () {
AspectEdit.decrementRequestsCounter();
}
});
}
} else {
if (confirm("Also remove this person from all aspects?")) {
var person_id = $(this).closest("li.person").attr('data-guid');
$.ajax({
type: "DELETE",
url: "/people/" + person_id,
success: function() {
$(".person[data-guid='"+ person_id +"']").fadeOut(200);
}
});
} else {
AspectEdit.deletePersonFromAspect(person);
}
}
},
decrementRequestsCounter: function() {
var $new_requests = $(".new_requests");
var request_html = $new_requests.html();
var old_request_count = request_html.match(/\d+/);
if (old_request_count == 1) {
$new_requests.html(
request_html.replace(/ \(\d+\)/, '')
);
} else {
$new_requests.html(
request_html.replace(/\d+/, old_request_count - 1)
);
}
}
};
$(document).ready(Publisher.initialize);
This diff is collapsed.
(function( $ ){
var methods = {
init : function( options ) {
return this.each( function () {
var $this = $(this);
$.each(options, function( label, setting ) {
$this.data(label, setting);
});
$this.bind('dragenter.dndUploader', methods.dragEnter);
$this.bind('dragover.dndUploader', methods.dragOver);
$this.bind('drop.dndUploader', methods.drop);
});
},
dragEnter : function ( event ) {
event.stopPropagation();
event.preventDefault();
return false;
},
dragOver : function ( event ) {
event.stopPropagation();
event.preventDefault();
return false;
},
drop : function( event ) {
event.stopPropagation();
event.preventDefault();
var $this = $(this);
var dataTransfer = event.originalEvent.dataTransfer;
if (dataTransfer.files.length > 0) {
$.each(dataTransfer.files, function ( i, file ) {
var xhr = new XMLHttpRequest();
var upload = xhr.upload;
xhr.open($this.data('method') || 'POST', $this.data('url'), true);
xhr.setRequestHeader('X-Filename', file.fileName);
xhr.send(file);
});
};
return false;
}
};
$.fn.dndUploader = function( method ) {
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.dndUploader' );
}
};
})( jQuery );
This diff is collapsed.
This diff is collapsed.
.avatar {
width: 50px;
height: 50px;
padding: 0; }
.avatar
:width 50px
:height 50px
:padding 0
describe("Publisher", function() {
)};
commit a46e0d5ff0a95407bbd8f3437a372ced53d90c9b
Author: Brendan G. Lim <brendan@intridea.com>
Date: Sat Dec 20 20:59:49 2008 -0500
Added a helper method to determine if a device is JavaScript enabled and one to output the XHTML Mobile 1.0 doctype
commit f4b29b2e2c68a79b8904dddb7a91efd4341540ee
Author: Brendan G. Lim <brendan@intridea.com>
Date: Sun Sep 21 21:39:10 2008 -0400
Fixes issue with 'in_mobile_view' instead of 'is_mobile_view' helper method
commit 29e8e8b407dd3dc8d5f3248183223d11c6a78843
Author: Brendan G. Lim <brendan@intridea.com>
Date: Wed Sep 10 12:51:12 2008 -0400
Updating CHANGELOG
commit 0aac5bd7f0d2f71e6af7b144a04a18dad9f5aca5
Author: Brendan G. Lim <brendan@intridea.com>
Date: Wed Sep 10 12:50:50 2008 -0400
Styling overrides for iPods
commit f30c97c794ba74e737856aa9226328469c8395b6
Author: Brendan G. Lim <brendan@intridea.com>
Date: Mon Sep 8 00:07:27 2008 -0400
Adding in some comments to the latest changes
commit 78dae861e46d383356d7e4d6dfdaefbf60072e27
Author: Brendan G. Lim <brendan@intridea.com>
Date: Mon Sep 8 00:06:16 2008 -0400
Updating README
commit 1a66ccd2142e387f6d3138acb688a58df4687fcd
Author: Brendan G. Lim <brendan@intridea.com>
Date: Mon Sep 8 00:05:48 2008 -0400
Adding in a helper method to check for a specific mobile device and adding in 'ipod' to the list of mobile user agents
commit cbb26fff3287e16a757ee2aed2dcc8e98cbfb369
Author: Brendan G. Lim <brendan@intridea.com>
Date: Fri Aug 22 22:16:19 2008 -0400
Updating the CHANGELOG
commit ee49945b593b1c55bf546da1d595a0941d071f94
Author: Brendan G. Lim <brendan@intridea.com>
Date: Fri Aug 22 22:16:00 2008 -0400
Updating README
commit 02c12a8563466f7cef6aba8e53915dc2efec908c
Author: Brendan G. Lim <brendan@intridea.com>
Date: Mon Aug 18 16:08:51 2008 -0400
Adding in support for Android
commit 2dffa5958905c0419288d03a0650127a0734b41a
Author: Brendan G. Lim <brendan@intridea.com>
Date: Sat Jul 26 14:08:56 2008 -0400
Adding in other phone user agents, including some Japanese and French manufacturers
commit e8f9f1a9c2e668d639690f4f1beb4f701f742cfa
Author: Brendan G. Lim <brendan@intridea.com>
Date: Fri Jul 18 11:15:52 2008 -0400
Adding in CHANGELOG
commit a3122b40c0c722b2942e9cb5341614d0e0d834a5
Author: Brendan G. Lim <brendan@intridea.com>
Date: Fri Jul 18 11:14:35 2008 -0400
Changes to README
commit 64a24e36b6a770757963eb2d961262fb8a14ec1b
Author: Brendan G. Lim <brendan@intridea.com>
Date: Fri Jul 18 11:10:40 2008 -0400
Quick fix
commit 116fa5b7c1168471cf56cb9961b98f0b73fc3308
Author: Brendan G. Lim <brendan@intridea.com>
Date: Fri Jul 18 10:04:41 2008 -0400
Fixed issue with mobile view session variable getting set incorrectly, when forcing mobile format
commit d172665c9d0458801fd672076e269a3c0ee9d80d
Author: Brendan G. Lim <brendan@intridea.com>
Date: Fri Jul 18 01:04:19 2008 -0400
Adding in more MIT license goodness
commit a6c947d684d2d9abdbe354dc1ea757f23cd5a633
Author: Brendan G. Lim <brendan@intridea.com>
Date: Fri Jul 18 01:00:55 2008 -0400
Change to the README
commit dad4f4db1f3cb816283069a91c01982c953ff8a5
Author: Brendan G. Lim <brendan@intridea.com>
Date: Fri Jul 18 01:00:16 2008 -0400
Change to the README
commit c5ec9de6ef19e48a66917d8f6f3a59771295765b
Author: Brendan G. Lim <brendan@intridea.com>
Date: Fri Jul 18 00:59:36 2008 -0400
Releasing Mobile Fu to the world
Copyright (c) 2008 Brendan G. Lim, Intridea, Inc.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
= Mobile Fu
Want to automatically detect mobile devices that access your Rails application?
Mobile Fu allows you to do just that. People can access your site from a Palm,
Blackberry, iPhone, iPad, Nokia, etc. and it will automatically adjust the format
of the request from :html to :mobile.
== Rails 3 Compatibility
The master branch of this plugin is Rails 3 compatible.
To use the Rails 3 compatible version of this plugin, please install it like so:
rails plugin install git://github.com/brendanlim/mobile-fu.git
== Rails 2 Compatibility
You will need to install this plugin from the 2.x branch.
To use the Rails 2 compatible version of this plugin, please install it like so:
script/plugin install git://github.com/brendanlim/mobile-fu.git -r 2.x
== Usage
Add this this one line to the controller.
class ApplicationController < ActionController::Base
has_mobile_fu
end
Once this is in place, any request that comes from a mobile device will be be
set as :mobile format. It is up to you to determine how you want to handle
these requests. It is also up to you to create the .mobile.erb versions of
your views that are to be requested.
Then add the line below to config/initializers/mime_types.rb
Mime::Type.register_alias "text/html", :mobile
I recommend that you setup a before_filter that will redirect to a specific page
depending on whether or not it is a mobile request. How can you check this?
is_mobile_device? # => Returns true or false depending on the device
You can also determine which format is currently set in by calling the following:
is_mobile_view? # => Returns true or false depending on current req. format
Also, if you want the ability to allow a user to switch between 'mobile' and
'standard' format (:html), you can just adjust the mobile_view session variable
in a custom controller action.
session[:mobile_view] # => Set to true if request format is :mobile and false
if set to :html
So, different devices need different styling. Don't worry, we've got this
baked in to Mobile Fu.
If you are including a css or sass file via stylesheet_link_tag, all you have
to do is add _device to the name of one of your files to override your styling
for a certain device. The stylesheet that is loaded is dependant on which device
is making the request.
e.g., Accessing a page from a Blackberry.
... stylesheet_link_tag 'mobile.css' ...
This loads mobile.css, and mobile_blackberry.css if the file exists.
Supported stylesheet override device extensions at the moment are:
blackberry
iphone (iphone,ipod)
ipad
android
mobileexplorer
nokia
palm
The stylesheet awesomeness was derived from Michael Bleigh's browserized styles:
http://www.intridea.com/2007/12/9/announcing-browserized-styles
Inspiration for Mobile Fu came from Noel Rappin's rails_iui:
http://blogs.pathf.com/agileajax/2008/05/rails-developme.html
Hopefully this should help you create some awesome mobile applications.
== Testing Mobile Interface
If you want to force the mobile interface for testing, you can either use a
mobile device emulator, or you can pass 'true' to has_mobile_fu.
class ApplicationController < ActionController::Base
has_mobile_fu(true)
end
Copyright (c) 2008 Brendan G. Lim, Intridea, Inc., released under the MIT license
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
desc 'Default: run unit tests.'
task :default => :test