fmartingr
/
shelfzilla
Archived
1
0
Fork 0

Added pjax support

This commit is contained in:
Felipe Martin 2014-03-31 15:32:50 +02:00
parent 61451efede
commit 30c19c545c
12 changed files with 85 additions and 15 deletions

View File

@ -16,6 +16,8 @@
"dependencies": {
"bootflatv2": "470fde6d400cdcca9fdc8c0a699a6d006e5f46d3",
"jquery": "~2.1.0",
"vegas": "~1.3.4"
"vegas": "~1.3.4",
"jquery-pjax": "~1.8.1",
"nprogress": "~0.1.3"
}
}

View File

@ -23,6 +23,10 @@ module.exports = (grunt) ->
'fonts/glyphicons-halflings-regular.ttf',
'fonts/glyphicons-halflings-regular.woff',
]
nprogress:
files: [
'nprogress.css',
]
less:
options:
@ -47,6 +51,8 @@ module.exports = (grunt) ->
"static_components/js/vegas.js",
"static_components/js/bootstrap.min.js",
"static_components/js/icheck.min.js",
"static_components/js/jquery-pjax.js",
"static_components/js/nprogress.js",
"shelfzilla/themes/bootflat/static/js/main.full.js",
]
dest: "shelfzilla/themes/bootflat/static/js/site.js"
@ -55,6 +61,7 @@ module.exports = (grunt) ->
"shelfzilla/themes/bootflat/static/css/app.css",
"static_components/css/bootstrap.min.css",
"static_components/css/bootflat.min.css",
"static_components/css/nprogress.css",
]
dest: "shelfzilla/themes/bootflat/static/css/style.css"

View File

@ -0,0 +1,14 @@
def pjax(request):
"""
Determines if a request if a pjax request by the X-PJAX header
"""
template = '_layout.html'
is_pjax = request.META.get('HTTP_X_PJAX', False)
if is_pjax:
template = '_pjax.html'
return {
'is_pjax': is_pjax,
'extends_template': template,
}

View File

@ -68,6 +68,8 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request',
'shelfzilla.context_processors.pjax',
)
MIDDLEWARE_CLASSES = (

View File

@ -1,6 +1,31 @@
# Background
jQuery ->
jQuery.vegas
src: '/static/backgrounds/shelves.jpg'
fade: 1200
$('[data-toggle="tooltip"]').tooltip();
# PJAX
if jQuery.support.pjax
jQuery(document).on 'click', 'a[data-pjax]', (event) ->
elem = jQuery(@)
container = elem.data('container')
if not container
container = jQuery('[data-pjax-container="main"]')
if container == 'closest'
container = jQuery(@).closest('[data-pjax-container]')
else
container = jQuery(container)
jQuery.pjax.click event, {
container: container,
timeout: 1000
}
# Tooltips
jQuery('[data-toggle="tooltip"]').tooltip();
# Nprogress
jQuery(document).on 'pjax:start', -> NProgress.start()
jQuery(document).on 'pjax:end', -> NProgress.done()
#jQuery(document).on 'page:restore', -> NProgress.remove()

View File

@ -63,3 +63,8 @@
}
}
}
.alert-error {
background-color: #f2838f;
border: #ed5565
}

View File

@ -12,23 +12,23 @@
<nav class="navbar navbar-alternative" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{% url "homepage" %}">Shelfzilla</a>
<a class="navbar-brand" data-pjax href="{% url "homepage" %}">Shelfzilla</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<div class="collapse navbar-collapse" id="navbar-collapse">
<ul class="nav navbar-nav">
<li {% if navigation.section == "series" %}class="active"{% endif %}>
<a href="{% url "series.list" %}">{% trans "Series" %}</a>
<a data-pjax href="{% url "series.list" %}">{% trans "Series" %}</a>
</li>
<li {% if navigation.section == "publishers" %}class="active"{% endif %}>
<a href="#">{% trans "Publishers" %}</a>
<a data-pjax href="#">{% trans "Publishers" %}</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
@ -54,15 +54,19 @@
{% block messages %}
{% if messages %}
<ul class="messages">
<div class="messages container">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
<div{% if message.tags %} class="alert alert-{{ message.tags }}"{% endif %}>
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
{{ message }}
</div>
{% endfor %}
</ul>
</div>
{% endif %}
{% endblock %}
<div id="main_content" data-pjax-container="main">
{% block main_content %}{% endblock %}
</div>
{% block extra_js %}{% endblock %}
<script src="/static/js/site.js"></script>

View File

@ -0,0 +1,3 @@
<title>{% block page_title %}ShelfZilla{% endblock %}</title>
{% block main_content %}{% endblock %}

View File

@ -1,3 +1,3 @@
{% extends "_layout.html" %}
{% extends extends_template %}
{% block content %}asd{% endblock %}

View File

@ -1,6 +1,8 @@
{% extends "_layout.html" %}
{% extends extends_template %}
{% load i18n %}
{% block page_title %}{{ block.super }} | {{ item.name }}{% endblock %}
{% block main_content %}
<div class="container">
<div class="row">

View File

@ -1,4 +1,7 @@
{% extends "_layout.html" %}
{% extends extends_template %}
{% load i18n %}
{% block page_title %}{{ block.super }} | {% trans "Series" %}{% endblock %}
{% block main_content %}
{% regroup items by first_letter as letter_list %}
@ -20,7 +23,9 @@
</div>
<ul class="list-group">
{% for item in letter.list %}
<li class="list-group-item"><a href="{% url "series.detail" item.pk %}">{{ item.name }}</a></li>
<li class="list-group-item">
<a href="{% url "series.detail" item.pk %}" data-pjax>{{ item.name }}</a>
</li>
{% endfor %}
</ul>
</div>

View File

@ -1,6 +1,7 @@
{% extends "_layout.html" %}
{% load i18n %}
{% block navigation_bar %}{% endblock %}
{% block page_title %}{{ block.super }} | Login{% endblock %}
{% block main_content %}