Skip to content

Commit

Permalink
use application css and built in jquery
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Christensen committed Mar 12, 2012
1 parent 2f48034 commit f745f1a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.pyc
*.egg-info
.DS_Store

11 changes: 7 additions & 4 deletions adminpreview/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from django.contrib import admin
from django.conf.urls.defaults import patterns, url
from django.views.generic.list_detail import object_detail

class PreviewAdmin(admin.ModelAdmin):
class Media:
js = ['js/jquery.adminpreview.js']
css = dict(
all = ['css/adminpreview.css']
)

def admin_slide_preview(self, obj):
"""
Add this to your ModelAdmin:
Expand All @@ -22,7 +29,3 @@ def get_urls(self):
url(r'^(?P<object_id>\d+)/preview/$', self.admin_site.admin_view(self.get_preview)),
)
return my_urls + super(PreviewAdmin, self).get_urls()

class Media:
js = ('js/jquery.js',
'js/jquery.adminpreview.js')
File renamed without changes.
36 changes: 19 additions & 17 deletions adminpreview/static/js/jquery.adminpreview.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
$(document).ready(function(){
$(".previewslide").click(function(){
$.ajax({
url:$(this).attr('id'),
context: $(this).parent().parent(),
success:function(data){
var $html = $(data);
$('.previewed').each(function(){
$(this).remove();
});
(function($){
$(document).ready(function(){
$(".previewslide").click(function(){
$.ajax({
url:$(this).attr('id'),
context: $(this).parent().parent(),
success:function(data){
var $html = $(data);
$('.previewed').each(function(){
$(this).remove();
});

if(!$html.hasClass('previewed')){
$html.addClass('previewed');
}
if(!$html.hasClass('previewed')){
$html.addClass('previewed');
}

$html.addClass($(this.context).attr('class'));
$(this.context).after($html);
}
$html.addClass($(this.context).attr('class'));
$(this.context).after($html);
}
});
});
});
});
})(django.jQuery);

0 comments on commit f745f1a

Please sign in to comment.