Created
January 21, 2012 02:07
-
-
Save hexgnu/1650777 to your computer and use it in GitHub Desktop.
How did we ever get so terrible at writing code?
This file contains hidden or 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
function initSpinner() { | |
var opts = { | |
lines: 16, // The number of lines to draw | |
length: 0, // The length of each line | |
width: 2, // The line thickness | |
radius: 7, // The radius of the inner circle | |
color: '#fff', // #rgb or #rrggbb | |
speed: 0.9, // Rounds per second | |
trail: 25, // Afterglow percentage | |
shadow: true // Whether to render a shadow | |
}; | |
var target = document.getElementById('ajax_spinner'); | |
var spinner = new Spinner(opts).spin(target); | |
} | |
function showLoader() { | |
$('#ajax_loader').show(); | |
} | |
function hideLoader() { | |
$('#ajax_loader').hide(); | |
} | |
function parseTimestamps() { | |
$('#content_wide > ul.bananaList li.status span.published_at').timeago(); | |
} | |
$(document).ready(function() { | |
$('.tipMe').tipTip(); | |
}); | |
$(function() { | |
$('#post_toggle').click(function(){ | |
$(this).toggleClass('toggled'); | |
$('#post_message, #post input[type=text]').val('').keyup().blur(); | |
$('#post_controls .visible').removeClass('visible'); | |
$("#post_networks .avatar.active").click(); | |
$('#post').toggleClass('visible'); | |
return false; | |
}); | |
$('form#network_toggles input[type=radio]').change(function(){ | |
$('form#network_toggles #networkActions li.active').removeClass('active'); | |
$(this).closest('li').addClass('active'); | |
$('form#network_toggles').submit(); | |
return true; | |
}); | |
$('form#network_toggles input[type=checkbox]').change(function(){ | |
$(this).closest('label').toggleClass('checked'); | |
$('form#network_toggles').submit(); | |
return true; | |
}); | |
$('#chart_as_line, #chart_as_column').click(function(){ | |
var button = $(this); | |
button.parents('ul:first').find('.active').removeClass('active') | |
button.addClass('active') | |
chart_type = button.attr('id').replace('chart_as_', ''); | |
$('form#network_toggles').submit(); | |
}); | |
if ($('body#statistics').length > 0) { | |
rangeUtilities.initialize(); | |
} | |
$('form').live('submit', function(){ | |
$(this).find('*[data-default_value]').each(function(){ | |
if ($(this).hasClass('on_default')) { | |
$(this).val(''); | |
} | |
}); | |
}); | |
$("a.disable_on_click").live('click', function () { | |
if(!$(this).data('clicked')) { | |
$(this).data('clicked', true); | |
$(this).parent().fadeTo("fast", .5).find('a').each(function(){ | |
$(this).click(function() { return false; }); | |
}); | |
} | |
}); | |
$('#post_controls li button.hide').click(function(){ | |
$(this).closest('li.visible').removeClass('visible'); | |
}); | |
$('#post_controls li a.show').click(function(){ | |
if($(this).closest('li.visible').length) { | |
$(this).closest('li').removeClass('visible'); | |
} else { | |
$('#post_controls li.visible').removeClass('visible'); | |
$(this).closest('li').addClass('visible'); | |
} | |
}); | |
$('form.submit_on_change select, form.submit_on_change input').change(function(){ | |
$(this).closest('form').submit(); | |
}); | |
$(document).ajaxStart(function() { | |
showLoader(); | |
}); | |
$(document).ajaxStop(function() { | |
hideLoader(); | |
}); | |
$('.remove_keyword').live('click', function(){ | |
var url = $(this).attr('href'); | |
var link = $(this); | |
$.post(url, function(r) { | |
if(r.success) { | |
$(link).closest('li').hide(slideRate); | |
} else { | |
alert('There was a problem deleting this keyword, please try again'); | |
} | |
}); | |
return false; | |
}); | |
$('#keywords_form').submit(function(e){ | |
e.preventDefault(); | |
$.post($(this).attr('action'), $(this).serialize(), function(r){ | |
var ul = $('#' + $("input[name=keyword_type]:checked").val() + '_list'); | |
ul.slideUp(slideRate, function(){ | |
ul.html(r.html).slideDown(slideRate); | |
}); | |
$('#keywords').val(''); | |
$('#keywords').blur(); | |
return false; | |
}); | |
return false; | |
}); | |
$('.bananaList li.status a.post_delete').live('ajax:success', function(e, data, success){ | |
if(data.success) { | |
notice(data.message, 'success'); | |
$(this).closest('li.status').slideUp(slideRate, function(){ | |
$(this).remove(); | |
}); | |
} else { | |
notice(data.message, 'error'); | |
} | |
}); | |
$('a.favorite_link').live('ajax:success', function(e,data,status){ | |
if(data.success) { | |
var replacee = 'favorite=false'; | |
var replacement = 'favorite=true'; | |
if($(this).attr('href').indexOf('favorite=true') != -1) { | |
var tmp = replacee; | |
replacee = replacement; | |
replacement = tmp; | |
} | |
$(this).attr('href', $(this).attr('href').replace(replacee, replacement)); | |
$(this).parent().toggleClass('favd'); | |
} | |
return(false); | |
}); | |
$('a.retweet_link').live('ajax:success', function(e,data,status){ | |
if(data.success) { | |
$(this).parent().addClass('retweeted'); | |
} | |
return(false); | |
}); | |
$('span.follow a').live('ajax:success', function(e,data,status){ | |
if(data.success) { | |
if($(this).hasClass('unfollow')) { | |
$(this).removeClass('unfollow').removeClass('delete').addClass('add').text('Follow'); | |
$(this).attr('href', $(this).attr('href').replace('follow=false', 'follow=true')); | |
} else { | |
$(this).addClass('unfollow').removeClass('add').addClass('delete').text('Unfollow'); | |
$(this).attr('href', $(this).attr('href').replace('follow=true', 'follow=false')); | |
} | |
} | |
}); | |
$('a.post_like').live('ajax:success', function(e,data,status){ | |
if(data.success) { | |
$(this).toggleClass('liked'); | |
if($(this).text() == 'Like') { | |
$(this).attr('href', $(this).attr('href').replace('like=true', 'like=false')); | |
$(this).text('Unlike'); | |
} else { | |
$(this).attr('href', $(this).attr('href').replace('like=false', 'like=true')); | |
$(this).text('Like'); | |
} | |
} | |
return(false); | |
}); | |
$('a.moop_user_profile, a.meep_user_profile').live('ajax:success', function(e,data,status){ | |
$('#sidebar').show().html(data.html); | |
}); | |
$('a.moop_user_posts, a.meep_user_posts').live('ajax:success', function(e,data,status){ | |
$('#sidebar .tabContent').html(data.html); | |
$('#sidebar .tabs li').removeClass('active'); | |
$('#sidebar .tabs li.posts').addClass('active'); | |
}); | |
$('a#load_more_posts').live('ajax:success', function(e,data,status){ | |
$('ul.bananaList').append(data.html); | |
parseTimestamps(); | |
if (data.next_page_url) { | |
$(this).attr('href', data.next_page_url); | |
} else { | |
var url = $(this).attr('href'); | |
var page_number = parseInt(url.match(/page=(\d*)/)[1]); | |
$(this).attr('href', url.replace('page=' + page_number, 'page=' + (page_number + 1))) | |
} | |
}); | |
$('a#load_more_users').live('ajax:success', function(e,data,status){ | |
$('ul.bananaList').append(data.html); | |
$(this).attr('href', data.next_page_url); | |
}); | |
$('label.brand_member input').change(function(){ | |
if ($(this).attr('checked')) { | |
$(this).closest('div.brand_fields').find('.brand_networks').slideDown(slideRate).addClass('brand_member'); | |
} else { | |
$(this).closest('div.brand_fields').find('.brand_networks').removeClass('brand_member').show().slideUp(slideRate); | |
} | |
}); | |
$('#show_all_networks').hover(function(){ | |
$('#concealed_networks').css({visibility: 'visible'}); | |
$('#concealed_networks').show('clip', {}, 150); | |
}, | |
function(){ | |
$('#concealed_networks').css({height: '100%'}); | |
$('#concealed_networks').hide('clip', {}, 150, function(){ | |
$('#concealed_networks').attr('style', ''); | |
$('#concealed_networks').css({visibility: 'hidden'}); | |
}); | |
}) | |
$('#post_message').simplyCountable({ | |
counter: '#meep_post_counter', | |
countType: 'characters', | |
maxCount: 140, | |
countDirection: 'down', | |
overClass: 'alert' | |
}); | |
$('#post_message').simplyCountable({ | |
counter: '#moop_post_counter', | |
countType: 'characters', | |
maxCount: 420, | |
countDirection: 'down', | |
overClass: 'alert' | |
}); | |
$('#reply.meep').simplyCountable({ | |
counter: '#meep_reply_counter', | |
countType: 'characters', | |
maxCount: 140, | |
countDirection: 'down', | |
overClass: 'alert' | |
}); | |
$('input[data-default_value], textarea[data-default_value]').each(function(){ | |
var default_val = $(this).data('default_value'); | |
if($(this).val() == '') { | |
$(this).addClass('on_default'); | |
$(this).val(default_val); | |
} | |
$(this).focus(function(){ | |
$(this).removeClass('on_default'); | |
if ($(this).val() == default_val) { | |
$(this).val(''); | |
} | |
}); | |
$(this).bind('blur change', function(){ | |
if ($(this).val() == '') { | |
$(this).val(default_val); | |
$(this).addClass('on_default'); | |
} else { | |
$(this).removeClass('on_default'); | |
} | |
}); | |
}); | |
$("#post_scheduled_at").focus(function(e){ | |
$("#post_scheduled_at_label").hide(); | |
}); | |
$("#post_scheduled_at").datetimepicker({ | |
ampm: true, | |
stepMinute: 5, | |
hourGrid: 6, | |
minuteGrid: 10, | |
minDate: new Date() | |
}); | |
$("#filters_report_start, #filters_report_end").datepicker({ | |
maxDate: new Date() | |
}); | |
$("#post_message").focus(function(){ | |
$(this).siblings(".whats_going_on").hide(); | |
}); | |
$("#report_user").change(function(){ | |
var root_url = $("meta[name=root_url]"); | |
var user = $(this).attr('value'); | |
var report_brand_id = $(this).data('report_brand_id') | |
$.post(root_url.attr("content") + 'organizations/reports/user_info', { user_id: user, report_brand_id: report_brand_id }, function(data) { | |
$('#report_ip').find('option').remove(); | |
$('#report_ip').append('<option value="">All</option>'); | |
$.each(data.ip_addresses, function(){ | |
$('#report_ip').append('<option value="' + this + '">' + this + '</option>'); | |
}); | |
$('#report_network').find('option').remove(); | |
$('#report_network').append('<option value="">All</option>'); | |
$.each(data.networks, function(){ | |
$('#report_network').append('<option value="' + this[0] + '">' + this[1] + '</option>'); | |
}); | |
}); | |
}); | |
//Add new fields to new form | |
$('#add_fields').click(function() { | |
var new_id = new Date().getTime(); | |
var regex = new RegExp('new_' + $(this).attr('association'), 'g'); | |
$(this).before($(this).attr('content').replace(regex, new_id)); | |
}); | |
//Toggle form to add Bit.ly credentials | |
$('#add_feep').click(function() { | |
$('#feep_form').toggle('fast'); | |
}); | |
$('ul.bananaList li.meep a.fetch_retweets').live('ajax:success', function(e, data){ | |
var elem = $(this).closest('li.status'); | |
var replacement = $('<li class="conversation retweets"><ul class="conversation">' + data.html + '</ul></li>'); | |
$(elem).after(replacement); | |
$(replacement).hide().slideDown(slideRate); | |
parseTimestamps(); | |
$(this).hide(slideRate); | |
return false; | |
}); | |
$('ul.bananaList li.meep a.fetch_conversation').live('ajax:success', function(e, data){ | |
$(this).closest('li.status').slideUp(slideRate, function(){ | |
var replacement = $('<li class="conversation"><ul class="conversation">' + data.html + '</ul></li>'); | |
$(this).after(replacement); | |
$(replacement).hide().slideDown(slideRate); | |
parseTimestamps(); | |
}); | |
return false; | |
}); | |
$('ul.bananaList li a.post_reply, ul.bananaList li a.post_comment').live('ajax:success', function(e, data){ | |
var post_container = $(this).closest('li.status'); | |
var status_container = $(post_container).closest('li.status'); | |
$(post_container).find('.reply_container').remove(); | |
var reply_container = $('<li class="reply_container"></li>').hide().html(data.html); | |
$(post_container).addClass('reply_mode').append(reply_container); | |
$(reply_container).fadeIn(slideRate); | |
$(reply_container).find('textarea.post_message').simplyCountable({ | |
counter: $(reply_container).find('.post_message_counter'), | |
countType: 'characters', | |
maxCount: 140, | |
countDirection: 'down', | |
overClass: 'alert' | |
}); | |
$(reply_container).find('textarea').focus(); | |
$(reply_container).find('form').submit(function(e){ | |
e.preventDefault(); | |
var form = this; | |
$.post($(this).attr('action'), $(this).serialize(), function(r){ | |
if (r.success) { | |
notice(r.message, 'success'); | |
closeReplyContainer(); | |
if (r.html) { | |
var comment = $('<li class="comment" />').html(r.html); | |
$(status_container).find('ul.comments').append($(comment).hide()); | |
$(comment).slideDown(slideRate); | |
} | |
} else { notice(r.message, 'error'); } | |
}); | |
return false; | |
}); | |
$(reply_container).find('a.cancel').click(function(){ | |
closeReplyContainer(); | |
return false; | |
}); | |
function closeReplyContainer() { | |
$(reply_container).fadeOut(slideRate, function(){ | |
$(this).remove() | |
$(post_container).removeClass('reply_mode'); | |
}); | |
} | |
}); | |
$('ul.bananaList li.status li.destroy').bind('ajax:success', function(e, data, status){ | |
if(data.success) { | |
notice(data.message, 'error'); | |
$(this).closest('li.status').slideUp(slideRate); | |
} | |
}); | |
$("#review_level_form input").click(function() { | |
$("#review_level_form").submit(); | |
}); | |
$(".filter_radio_button").click(function() { | |
$("#filter_level_form").submit(); | |
}); | |
$("#keywords_list").click(function() { | |
$("#keywords_form").submit(); | |
return false; | |
}); | |
$("#review_level_form, #filter_level_form, #keywords_form").bind('ajax:success', function(e, data, status){ | |
notice(data.message); | |
}); | |
$('tr.version.post').click(function(){ | |
var wrapper = $(this).next('tr.expanded_version').find('.wrapper'); | |
if ($(wrapper).is(':visible')) { | |
$(this).removeClass('expanded'); | |
$(wrapper).slideUp(); | |
} else { | |
$(this).addClass('expanded'); | |
$(wrapper).slideDown(); | |
} | |
}); | |
function post_author(name, url) | |
{ | |
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); | |
var regexS = "[\\?&]"+name+"=([^&#]*)"; | |
var regex = new RegExp( regexS ); | |
var results = regex.exec( url ); | |
if( results == null ) | |
return ""; | |
else | |
return results[1]; | |
} | |
$('a#apply_filters').click(function() { | |
$('form#audit_filters').toggle('blind') | |
return false | |
}) | |
var role_filter = $.getUrlVar('q%5Brole_eq%5D') | |
if (role_filter != null) { | |
$('#q_role_eq option[value="' + role_filter + '"]').attr('selected', 'selected') | |
} | |
}); | |
$(document).delegate(".tag-list","focus",function(){ | |
if ($(this).tagsInput) | |
initTagInput($(this)); | |
}); | |
function initTagInput(elements) { | |
$(elements).each(function(i,e){ | |
$(e).tagsInput({ | |
defaultText: "Click to Add", | |
width: "auto", | |
height: "auto" | |
}); | |
}); | |
} | |
$(function(){ | |
initTagInput(".tag-list"); // Initialize tags on page load | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment