$LOAD_PATH = ['/admin/javascripts']; $(document).ready(function() { $('a[data-method]').live('click', function(event) { event.preventDefault(); var link = $(this); var form = $('
').attr('action', this.href).attr('method', 'post'); form.append(''); var authenticityToken = $('meta[name=csrf-token]').attr('content'); form.append(''); $(document.body).append(form); form.submit(); }); $('a.expand').live('click', function(event) { event.preventDefault(); var link = $(this); var li = link.parents('li'); var ul = li.find('ul'); var add; if (li.hasClass('expanded')) { ul.css('display', 'block'); li.removeClass('expanded'); ul.slideUp(100); add = false; } else { ul.hide(); li.addClass('expanded'); ul.slideDown(100); add = true; } $.get('/admin/expand?add=' + (add ? 'yup' : 'nope') + '§ion=' + link.attr('rel')); }); $('#cover').click(function() { $(this).fadeOut(200); var pulldown = $('#pulldown'); if (pulldown.css('display') != 'none') { pulldown.animate({top: -(pulldown.height())}, 300, function() { pulldown.hide(); }); } }); $('#pulldown a.cancel').live('click', function(event) { event.preventDefault(); $('#cover').click(); }); $('.remote').live('click', function(event) { $('#cover').fadeIn(100); event.preventDefault(); $.get(this.href, function(response) { var pulldown = $('#pulldown'); pulldown.html(response); if (pulldown.css('display') == 'none') { pulldown.css('top', -(pulldown.height())).show().animate({top: 0}, 300); } }); }); $('.galleries.sortable').sortable({ handle: '.float-left', items: '.container', stop: function(event, ui) { $.post('/admin/galleries/reorder', $(this).sortable('serialize'), function() { Flash.show('notice', "Your changes have been saved!"); }); } }); $('.images.sortable').sortable({ handle: '.float-left', items: '.container', stop: function(event, ui) { $.post(window.location.toString() + '/images/reorder', $(this).sortable('serialize'), function() { Flash.show('notice', "Your changes have been saved!"); }); } }); $('.container.gallery a').mousemove(function(event) { var link = $(this); var width = link.width(); var images = link.parent().children('img'); var segment = width / images.length; var index = Math.max(Math.ceil(event.offsetX / segment), 1); var image = $(images[index - 1]); var active = link.find('img'); if (active.attr('src') != image.attr('src')) { active.attr('src', image.attr('src')); } }); $('#uploads').livequery(function() { var uploads = $(this); if (uploads.length > 0) { var form = uploads.parents('form'); var data = {} $.each(form.serializeArray(), function() { data[this.name] = this.value; }); form.find('.toolbar').empty().flash( { align: 'center', flashvars: {action: form.attr('action'), method: form.attr('method').toUpperCase(), data: $.param(data)}, height: 24, id: 'uploads-flash', src: '/admin/images/uploader.swf', width: 118, wmode: 'transparent' } ); Upload.element = document.getElementById('uploads-flash'); Upload.list = uploads; } }); $('.tabset').tabs(); $('.wysiwyg').dependency('wysiwyg', function() { this.wysiwyg('post', this.attr('id') == 'post_body' ? '.post' : null); }); $('.source a').live('click', function(event) { event.preventDefault(); var link = $(this); if (link.hasClass('active')) { return; } var source = link.parents('.source'); var destination = source.nextAll('.destination'); var active = source.find('a.active'); active.removeClass('active'); link.addClass('active'); $('#' + active.attr('rel')).hide(); $('#' + link.attr('rel')).show(); }); Flash.hideAll(); }); var Upload = { // Every file is done; move on with our lives allComplete: function() { window.location = window.location; }, // Called when someone clicks a "cancel this event" button cancel: function(event) { }, // Called AFTER we've successfully cancelled, but we initiate the cancelling. cancelled: function() { }, // Called for each file that's queued for upload fileAdded: function(file) { var item = $('