more JS formatting
This commit is contained in:
parent
4515ba631f
commit
77c102cce6
6 changed files with 70 additions and 58 deletions
|
|
@ -27,7 +27,7 @@ $(document).ready(function() {
|
|||
$('.edit_photo').bind('ajax:success', function(data, json, xhr) {
|
||||
json = $.parseJSON(json);
|
||||
$(".edit_photo input[type='text']").val(json['photo']['caption']);
|
||||
$("#caption").html(json['photo']['caption']);
|
||||
$("#caption").html(json.photo.caption);
|
||||
$("#show_photo").find("img").fadeTo(200,1);
|
||||
$("#photo_spinner").hide();
|
||||
});
|
||||
|
|
@ -42,7 +42,7 @@ $(document).ready(function() {
|
|||
$('.make_profile_photo').bind('ajax:success', function(data, json, xhr) {
|
||||
json = $.parseJSON(json);
|
||||
|
||||
$("img[data-person_id='" + json['person_id'] + "']").fadeTo(200, 1).attr('src', json.image_url_small);
|
||||
$("img[data-person_id='" + json.person_id + "']").fadeTo(200, 1).attr('src', json.image_url_small);
|
||||
});
|
||||
|
||||
$('.make_profile_photo').bind('ajax:failure', function(data, json, xhr) {
|
||||
|
|
|
|||
|
|
@ -2,19 +2,19 @@
|
|||
$.fn.clearForm = function() {
|
||||
return this.each(function() {
|
||||
var type = this.type, tag = this.tagName.toLowerCase();
|
||||
if (tag == 'form') {
|
||||
return $(':input',this).clearForm();
|
||||
if ($(this).is('form')) {
|
||||
return $(':input', this).clearForm();
|
||||
}
|
||||
if (type == 'text' || type == 'password' || tag == 'textarea') {
|
||||
this.value = '';
|
||||
} else if (type == 'checkbox' || type == 'radio') {
|
||||
this.checked = false;
|
||||
} else if (tag == 'select') {
|
||||
if ($(this).is(':text') || $(this).is(':password') || $(this).is('textarea')) {
|
||||
$(this).val('');
|
||||
} else if ($(this).is(':checkbox') || $(this).is(':radio')) {
|
||||
$(this).attr('checked', false);
|
||||
} else if ($(this).is('select')) {
|
||||
this.selectedIndex = -1;
|
||||
} else if (this.name == 'photos[]') {
|
||||
this.value = '';
|
||||
} else if ($(this).attr('name') == 'photos[]') {
|
||||
$(this).val('');
|
||||
}
|
||||
$(this).blur();
|
||||
$(this).blur();
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ jQuery(function ($) {
|
|||
e.preventDefault();
|
||||
});
|
||||
|
||||
$('a[data-method]:not([data-remote])').live('click', function (e){
|
||||
$('a[data-method]:not([data-remote])').live('click', function (e) {
|
||||
var link = $(this),
|
||||
href = link.attr('href'),
|
||||
method = link.attr('data-method'),
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ var Stream = {
|
|||
$stream.not(".show").delegate("a.show_post_comments", "click", Stream.toggleComments);
|
||||
|
||||
// publisher textarea reset
|
||||
$publisher.find("textarea").bind("blur", function(){
|
||||
$publisher.find("textarea").bind("blur", function() {
|
||||
$(this).css('height','42px');
|
||||
});
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ var Stream = {
|
|||
$(this).closest("form").children(".comment_box").attr("rows", 1);
|
||||
});
|
||||
|
||||
$stream.delegate("textarea.comment_box", "keydown", function(e){
|
||||
$stream.delegate("textarea.comment_box", "keydown", function(e) {
|
||||
if (e.shiftKey && e.keyCode === 13) {
|
||||
$(this).closest("form").submit();
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ var Stream = {
|
|||
$videoContainer = $this.parent().siblings("div.video-container");
|
||||
|
||||
if ($videoContainer.length > 0) {
|
||||
$videoContainer.slideUp('fast', function () {
|
||||
$videoContainer.slideUp('fast', function() {
|
||||
$videoContainer.detach();
|
||||
});
|
||||
return;
|
||||
|
|
@ -96,7 +96,7 @@ var Stream = {
|
|||
|
||||
$(".new_status_message").bind('ajax:success', function(data, json, xhr) {
|
||||
json = $.parseJSON(json);
|
||||
WebSocketReceiver.addPostToStream(json['post_id'], json['html']);
|
||||
WebSocketReceiver.addPostToStream(json.post_id, json.html);
|
||||
});
|
||||
$(".new_status_message").bind('ajax:failure', function(data, html, xhr) {
|
||||
alert('failed to post message!');
|
||||
|
|
@ -104,7 +104,7 @@ var Stream = {
|
|||
|
||||
$(".new_comment").live('ajax:success', function(data, json, xhr) {
|
||||
json = $.parseJSON(json);
|
||||
WebSocketReceiver.processComment(json['post_id'], json['comment_id'], json['html'], false);
|
||||
WebSocketReceiver.processComment(json.post_id, json.comment_id, json.html, false);
|
||||
});
|
||||
$(".new_comment").live('ajax:failure', function(data, html, xhr) {
|
||||
alert('failed to post message!');
|
||||
|
|
@ -126,7 +126,7 @@ var Stream = {
|
|||
|
||||
|
||||
if( commentBlockMore.hasClass("inactive") ) {
|
||||
commentBlockMore.fadeIn(150, function(){
|
||||
commentBlockMore.fadeIn(150, function() {
|
||||
commentBlockMore.removeClass("inactive");
|
||||
commentBlockMore.removeClass("hidden");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ var Validation = {
|
|||
},
|
||||
events: {
|
||||
usernameKeypress: function(evt) {
|
||||
if(evt.keyCode === 0) { return; }
|
||||
if(evt.keyCode === 0) {
|
||||
return;
|
||||
}
|
||||
if(!Validation.rules.username.characters.test(this.value + String.fromCharCode(evt.keyCode))) {
|
||||
evt.preventDefault();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ var View = {
|
|||
$(this.fancyBoxButtons.selectors.join(", "))
|
||||
.fancybox({
|
||||
'titleShow': false,
|
||||
'hideOnOverlayClick' : false
|
||||
'hideOnOverlayClick': false
|
||||
});
|
||||
|
||||
/* Autoexpand textareas */
|
||||
|
|
|
|||
|
|
@ -13,39 +13,43 @@ var WebSocketReceiver = {
|
|||
|
||||
onMessage: function(evt) {
|
||||
var obj = jQuery.parseJSON(evt.data);
|
||||
if(obj['notice']){
|
||||
WebSocketReceiver.processNotification(obj['notice']);
|
||||
if(obj.notice) {
|
||||
WebSocketReceiver.processNotification(obj.notice);
|
||||
|
||||
}else if (obj['class'] == 'people'){
|
||||
} else if (obj['class'] == 'people') {
|
||||
WSR.debug("got a " + obj['class']);
|
||||
WebSocketReceiver.processPerson(obj);
|
||||
|
||||
}else{
|
||||
WSR.debug("got a " + obj['class'] + " for aspects " + obj['aspect_ids']);
|
||||
} else {
|
||||
WSR.debug("got a " + obj['class'] + " for aspects " + obj.aspect_ids);
|
||||
|
||||
if (obj['class']=="retractions"){
|
||||
WebSocketReceiver.processRetraction(obj['post_id']);
|
||||
if (obj['class']=="retractions") {
|
||||
WebSocketReceiver.processRetraction(obj.post_id);
|
||||
|
||||
}else if (obj['class']=="comments"){
|
||||
WebSocketReceiver.processComment(obj['post_id'], obj['comment_id'], obj['html'], {'notification':obj['notification'], 'mine?':obj['mine?'], 'my_post?':obj['my_post?']})
|
||||
} else if (obj['class']=="comments") {
|
||||
WebSocketReceiver.processComment(obj.post_id, obj.comment_id, obj.html, {
|
||||
'notification': obj.notification,
|
||||
'mine?': obj['mine?'],
|
||||
'my_post?': obj['my_post?']
|
||||
});
|
||||
|
||||
}else{
|
||||
WebSocketReceiver.processPost(obj['class'], obj['post_id'], obj['html'], obj['aspect_ids'])
|
||||
} else {
|
||||
WebSocketReceiver.processPost(obj['class'], obj.post_id, obj.html, obj.aspect_ids);
|
||||
}
|
||||
}
|
||||
},
|
||||
processPerson: function(response){
|
||||
processPerson: function(response) {
|
||||
form = $('.webfinger_form');
|
||||
form.siblings('#loader').hide();
|
||||
result_ul = form.siblings('#request_result');
|
||||
if(response['status'] == 'fail'){
|
||||
if(response.status == 'fail') {
|
||||
result_ul.siblings('.error').show();
|
||||
result_ul.find('.error').text(response['response']).show();
|
||||
}else{
|
||||
$('#people_stream').prepend(response['html']).slideDown('slow', function(){});
|
||||
result_ul.find('.error').text(response.response).show();
|
||||
} else {
|
||||
$('#people_stream').prepend(response.html).slideDown('slow', function(){});
|
||||
var first_li = result_ul.find('li:first');
|
||||
first_li.hide()
|
||||
first_li.after(response['html']);
|
||||
first_li.after(response.html);
|
||||
result_ul.find("[name='request[into]']").val(result_ul.attr('aspect_id'));
|
||||
result_ul.children(':nth-child(2)').slideDown('fast', function(){});
|
||||
}
|
||||
|
|
@ -57,15 +61,17 @@ processPerson: function(response){
|
|||
},
|
||||
|
||||
processRetraction: function(post_id){
|
||||
$("*[data-guid='"+post_id+"']").fadeOut(400, function(){$(this).remove()});
|
||||
if($("#main_stream")[0].childElementCount == 0){
|
||||
$("*[data-guid='" + post_id + "']").fadeOut(400, function() {
|
||||
$(this).remove();
|
||||
});
|
||||
if($("#main_stream")[0].childElementCount == 0) {
|
||||
$("#no_posts").fadeIn(200);
|
||||
}
|
||||
},
|
||||
|
||||
processComment: function(postId, commentId, html, opts){
|
||||
processComment: function(postId, commentId, html, opts) {
|
||||
|
||||
if( $(".comment[data-guid='"+commentId+"']").length == 0 ){
|
||||
if( $(".comment[data-guid='"+commentId+"']").length == 0 ) {
|
||||
|
||||
post = $("*[data-guid='"+postId+"']'");
|
||||
$('.comments li:last', post ).before(
|
||||
|
|
@ -78,33 +84,34 @@ processPerson: function(response){
|
|||
toggler.html().replace(/\d+/,$('.comments', post).find('li').length -1)
|
||||
);
|
||||
|
||||
if( !$(".comments", post).is(':visible') ){
|
||||
if( !$(".comments", post).is(':visible') ) {
|
||||
toggler.click();
|
||||
}
|
||||
}
|
||||
|
||||
if( !opts['mine?'] && opts['my_post?']) {
|
||||
WebSocketReceiver.processNotification(opts['notification']);
|
||||
WebSocketReceiver.processNotification(opts.notification);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
processPost: function(className, postId, html, aspectIds){
|
||||
if(WebSocketReceiver.onPageForAspects(aspectIds)){
|
||||
processPost: function(className, postId, html, aspectIds) {
|
||||
if(WebSocketReceiver.onPageForAspects(aspectIds)) {
|
||||
WebSocketReceiver.addPostToStream(postId, html);
|
||||
}
|
||||
},
|
||||
|
||||
addPostToStream: function(postId, html){
|
||||
if( $(".message[data-guid='"+postId+"']").length == 0 ){
|
||||
var showMessage = function(){ $("#main_stream:not('.show')").prepend(
|
||||
$(html).fadeIn("fast", function(){
|
||||
addPostToStream: function(postId, html) {
|
||||
if( $(".message[data-guid='" + postId + "']").length == 0 ) {
|
||||
var showMessage = function() {
|
||||
$("#main_stream:not('.show')").prepend(
|
||||
$(html).fadeIn("fast", function() {
|
||||
$("#main_stream").find("label").first().inFieldLabels();
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
if( $("#no_posts").is(":visible") ){
|
||||
if( $("#no_posts").is(":visible") ) {
|
||||
$("#no_posts").fadeOut(400, showMessage()).hide();
|
||||
} else {
|
||||
showMessage();
|
||||
|
|
@ -112,22 +119,24 @@ processPerson: function(response){
|
|||
}
|
||||
},
|
||||
|
||||
onPageForClass: function(className){
|
||||
onPageForClass: function(className) {
|
||||
return (location.href.indexOf(className) != -1 );
|
||||
},
|
||||
|
||||
onPageForAspects: function(aspectIds){
|
||||
if(location.pathname == '/aspects' && WebSocketReceiver.onPageOne()){
|
||||
onPageForAspects: function(aspectIds) {
|
||||
if(location.pathname == '/aspects' && WebSocketReceiver.onPageOne()) {
|
||||
return true
|
||||
}
|
||||
var found = false;
|
||||
$.each(aspectIds, function(index, value) {
|
||||
if(WebSocketReceiver.onPageForAspect(value)){ found = true };
|
||||
if(WebSocketReceiver.onPageForAspect(value)) {
|
||||
found = true;
|
||||
};
|
||||
});
|
||||
return found;
|
||||
},
|
||||
|
||||
onPageForAspect: function(aspectId){
|
||||
onPageForAspect: function(aspectId) {
|
||||
return (location.href.indexOf(aspectId) != -1 )
|
||||
},
|
||||
|
||||
|
|
@ -135,8 +144,9 @@ processPerson: function(response){
|
|||
var c = document.location.search.charAt(document.location.search.length-1);
|
||||
return ((c =='') || (c== '1'));
|
||||
},
|
||||
debug: function(str){
|
||||
debug: function(str) {
|
||||
$("#debug").append("<p>" + str);
|
||||
}
|
||||
};
|
||||
var WSR = WebSocketReceiver
|
||||
var WSR = WebSocketReceiver;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue