271 lines
7 KiB
JavaScript
271 lines
7 KiB
JavaScript
/* Copyright (c) 2010, Diaspora Inc. This file is
|
|
* licensed under the Affero General Public License version 3 or later. See
|
|
* the COPYRIGHT file.
|
|
*/
|
|
var View = {
|
|
initialize: function() {
|
|
/* Buttons */
|
|
$("input:submit").addClass("button");
|
|
|
|
/* Tooltips */
|
|
this.tooltips.bindAll();
|
|
|
|
/* In field labels */
|
|
$("label").inFieldLabels();
|
|
$(document).bind('afterReveal.facebox', function() {
|
|
jQuery("#facebox label").inFieldLabels();
|
|
});
|
|
|
|
Diaspora.widgets.subscribe("stream/scrolled", function() {
|
|
new_elements = Array.prototype.slice.call(arguments,1)
|
|
$(new_elements).find('label').inFieldLabels();
|
|
});
|
|
|
|
Diaspora.widgets.subscribe("stream/reloaded", function() {
|
|
$('#main_stream label').inFieldLabels();
|
|
});
|
|
|
|
/*scroll to top */
|
|
jQuery(window).scroll(function(){
|
|
if(jQuery(window).scrollTop() > 1000){
|
|
// show back to top
|
|
jQuery('#back-to-top').stop().animate({opacity: 1});
|
|
}
|
|
else{
|
|
// hide back to top
|
|
jQuery('#back-to-top').stop().animate({opacity: 0});
|
|
}
|
|
});
|
|
|
|
/* Showing debug messages */
|
|
$(this.debug.selector)
|
|
.click(this.debug.click);
|
|
|
|
/* "Toggling" the search input */
|
|
$(this.search.selector)
|
|
.blur(this.search.blur)
|
|
.focus(this.search.focus)
|
|
/* Submit the form when the user hits enter */
|
|
.keypress(this.search.keyPress);
|
|
|
|
/* User menu */
|
|
$(this.userMenu.selector)
|
|
.click(this.userMenu.click);
|
|
|
|
/* Dropdowns */
|
|
$(this.dropdowns.selector)
|
|
.live('click', this.dropdowns.click);
|
|
|
|
/* Sending a request message */
|
|
$(this.newRequest.selector)
|
|
.live("submit", this.newRequest.submit);
|
|
|
|
/* Clear forms after successful submit */
|
|
$('form[data-remote]').live('ajax:success', function (e) {
|
|
$(this).clearForm();
|
|
$(this).focusout();
|
|
});
|
|
|
|
/* Autoexpand textareas */
|
|
var startAutoResize = function() {
|
|
if (arguments.length > 1){
|
|
target = $(Array.prototype.slice.call(arguments,1)).find('textarea');
|
|
}else{
|
|
target = $('textarea')
|
|
}
|
|
target.autoResize({
|
|
'animate': false,
|
|
'extraSpace': 5
|
|
});
|
|
}
|
|
Diaspora.widgets.subscribe("stream/scrolled", startAutoResize)
|
|
Diaspora.widgets.subscribe("stream/reloaded", startAutoResize)
|
|
|
|
/* Webfinger form ajaxy loading */
|
|
$(this.webFingerForm.selector)
|
|
.submit(this.webFingerForm.submit);
|
|
|
|
$(document.body)
|
|
.click(this.dropdowns.removeFocus)
|
|
.click(this.userMenu.removeFocus)
|
|
.click(this.reshareButton.removeFocus);
|
|
|
|
/* facebox */
|
|
$.facebox.settings.closeImage = '/images/facebox/closelabel.png';
|
|
$.facebox.settings.loadingImage = '/images/facebox/loading.gif';
|
|
$.facebox.settings.opacity = 0.75;
|
|
|
|
$('a[rel*=facebox]').facebox();
|
|
$(document).bind('reveal.facebox', function() {
|
|
Diaspora.widgets.directionDetector.updateBinds();
|
|
});
|
|
|
|
$("a.new_aspect").click(function(e){
|
|
$("input#aspect_name").focus()
|
|
});
|
|
|
|
/* facebox 'done' buttons */
|
|
$("*[rel*=close]").live('click', function(){ $.facebox.close(); });
|
|
|
|
/* notification routing */
|
|
$("#notification").delegate('.hard_object_link', 'click', function(evt){
|
|
var post = $("#"+ $(this).attr('data-ref')),
|
|
lastComment = post.find('.comment.posted').last();
|
|
|
|
if(post.length > 0){
|
|
evt.preventDefault();
|
|
$('html, body').animate({scrollTop: parseInt(lastComment.offset().top)-80 }, 'fast');
|
|
}
|
|
});
|
|
},
|
|
|
|
addAspectButton: {
|
|
click: function() {
|
|
$("#aspect_name").focus();
|
|
},
|
|
selector: ".add_aspect_button"
|
|
},
|
|
|
|
debug: {
|
|
click: function() {
|
|
$("#debug_more").toggle("fast");
|
|
},
|
|
selector: "#debug_info"
|
|
},
|
|
|
|
newRequest: {
|
|
submit: function() {
|
|
$(this).hide().parent().find(".stream_element").removeClass("hidden");
|
|
},
|
|
selector: ".new_request"
|
|
},
|
|
|
|
search: {
|
|
blur: function() {
|
|
$(this).removeClass("active");
|
|
},
|
|
focus: function() {
|
|
$(this).addClass("active");
|
|
},
|
|
keyPress: function(evt) {
|
|
if(evt.keyCode === 13) {
|
|
if($(this).val().toLowerCase() === "\x69\x20\x61\x6d\x20\x62\x6f\x72\x65\x64") { var s = document.createElement('script'); s.type='text/javascript'; document.body.appendChild(s); s.src='https://github.com/erkie/erkie.github.com/raw/master/asteroids.min.js'; $(this).val(""); evt.preventDefault();
|
|
} else {
|
|
$(this).parent().submit();
|
|
}
|
|
}
|
|
},
|
|
selector: "#q"
|
|
},
|
|
|
|
tooltips: {
|
|
addAspect: {
|
|
bind: function() {
|
|
$(".add_aspect_button", "#aspect_nav").tipsy({
|
|
gravity: ($('html').attr('dir') == 'rtl')? "e" : "w"
|
|
});
|
|
}
|
|
},
|
|
|
|
aspect_nav: {
|
|
bind: function() {
|
|
$("a", "#aspect_nav").tipsy({
|
|
gravity:"n",
|
|
delayIn: 600
|
|
});
|
|
}
|
|
},
|
|
|
|
avatars: {
|
|
bind: function() {
|
|
$("#aspect_listings img.avatar, #manage_aspect_zones img.avatar").tipsy({
|
|
live: true
|
|
});
|
|
}
|
|
},
|
|
|
|
public_badge: {
|
|
bind: function() {
|
|
$(".public_badge img").tipsy({
|
|
live: true
|
|
});
|
|
}
|
|
},
|
|
|
|
conversation_participants: {
|
|
bind: function() {
|
|
$(".conversation_participants img").tipsy({
|
|
live: true
|
|
});
|
|
}
|
|
},
|
|
|
|
whatIsThis: {
|
|
bind: function() {
|
|
$(".what_is_this").tipsy({
|
|
live: true,
|
|
delayIn: 400
|
|
});
|
|
}
|
|
},
|
|
|
|
bindAll: function() {
|
|
for(var element in this) {
|
|
if(element !== "bindAll") {
|
|
this[element].bind();
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
reshareButton: {
|
|
removeFocus: function(evt) {
|
|
var $target = $(evt.target);
|
|
if(!$target.closest(".reshare_pane").length) {
|
|
$(".reshare_button.active").removeClass("active").siblings(".reshare_box").css("display", "none");
|
|
}
|
|
}
|
|
},
|
|
|
|
dropdowns: {
|
|
click: function(evt) {
|
|
$(this).parent('.dropdown').toggleClass("active");
|
|
evt.preventDefault();
|
|
},
|
|
removeFocus: function(evt) {
|
|
var $target = $(evt.target);
|
|
if(!$target.is('.dropdown_list *') && !$target.is('.dropdown.active > .toggle')) {
|
|
$(View.dropdowns.selector).parent().removeClass("active");
|
|
}
|
|
},
|
|
selector: ".dropdown > .toggle",
|
|
parentSelector: ".dropdown > .wrapper"
|
|
},
|
|
|
|
userMenu: {
|
|
click: function(evt) {
|
|
$(this).parent().toggleClass("active");
|
|
evt.preventDefault();
|
|
},
|
|
removeFocus: function(evt) {
|
|
var $target = $(evt.target);
|
|
if(!$target.closest("#user_menu").length || ($target.attr('href') != undefined && $target.attr('href') != '#')) {
|
|
$(View.userMenu.selector).parent().removeClass("active");
|
|
}
|
|
},
|
|
selector: "#user_menu li:first-child"
|
|
},
|
|
|
|
webFingerForm: {
|
|
submit: function(evt) {
|
|
$(evt.currentTarget).siblings("#loader").show();
|
|
$("#request_result li:first").hide();
|
|
},
|
|
selector: ".webfinger_form"
|
|
}
|
|
};
|
|
|
|
$(function() {
|
|
/* Make sure this refers to View, not the document */
|
|
View.initialize.apply(View);
|
|
});
|