Browse Source

Coffee -> JS

crawlers/norma
Felipe Martín 8 years ago
parent
commit
28db8180ba
  1. 1
      .gitignore
  2. 92
      shelfzilla/themes/bootflat/static/coffee/main.coffee
  3. 94
      shelfzilla/themes/bootflat/static/js/app.js
  4. 2
      shelfzilla/themes/bootflat/templates/_layout.html

1
.gitignore

@ -15,7 +15,6 @@ db.sqlite3
# Themes
# Bootflat
shelfzilla/themes/bootflat/static/css/*.css
shelfzilla/themes/bootflat/static/js/*.js
shelfzilla/themes/bootflat/static/bower/*
**/CACHE/*

92
shelfzilla/themes/bootflat/static/coffee/main.coffee

@ -1,92 +0,0 @@
# Toastr config
toastr.options =
"positionClass": "toast-top-left"
window._updateMessages = false
window.updateMessagesHTML = ->
$.pjax
url: '/messages/'
container: '[data-pjax-container="messages"]'
push: false
window._updateMessages = false
window.updateMessages = ->
$.getJSON "/messages/?format=json", (data) ->
for message in data
toastr[message.extra_tags](message.message)
window._updateMessages = false
if USE_PJAX
NProgress.start()
window.imageLoad = (element) ->
imgLoad = imagesLoaded(element)
imgLoad.on 'done', (event) ->
NProgress.done()
imgLoad.on 'progress', (instance, image) ->
inc = instance.images.length/1000
NProgress.inc(inc)
# Document ready
$ ->
# Update messages
window.updateMessages()
# Document load progress bar
window.imageLoad(document)
# Background
#$.vegas
# src: '/static/backgrounds/shelves.jpg'
# fade: 1200
# #complete: -> NProgress.done()
# PJAX
if $.support.pjax
$(document).on 'click', 'a[data-pjax]', (event) ->
elem = $(@)
pjax = elem.data('pjax')
push = true
nav_element = elem.closest('[data-pjax-nav]')
nav_element.siblings('.active').removeClass('active')
nav_element.addClass('active')
if elem.is('[data-pjax-unnav]')
$('[data-pjax-nav].active').removeClass('active')
if elem.is('[pjax-nopush]')
push = false
if not pjax
container = $('[data-pjax-container="main"]')
else if pjax == 'closest'
container = elem.closest('[data-pjax-container]')
else
container = $("[data-pjax-container='#{pjax}']")
$.pjax.click event, {
container: container,
timeout: 5000,
push: push,
scrollTo: false
}
if elem.is('[pjax-messages]')
window._updateMessages = true
# Nprogress
$(document).on 'pjax:start', -> NProgress.start()
$(document).on 'pjax:end', (event) ->
window.imageLoad(event.target)
if ga?
ga('send', 'pageview')
if window._updateMessages
window.updateMessages()
# Tooltips
$('[data-toggle="tooltip"]').tooltip();

94
shelfzilla/themes/bootflat/static/js/app.js

@ -0,0 +1,94 @@
toastr.options = {
"positionClass": "toast-top-left"
};
window._updateMessages = false;
window.updateMessagesHTML = function() {
$.pjax({
url: '/messages/',
container: '[data-pjax-container="messages"]',
push: false
});
return window._updateMessages = false;
};
window.updateMessages = function() {
$.getJSON("/messages/?format=json", function(data) {
var message, _i, _len, _results;
_results = [];
for (_i = 0, _len = data.length; _i < _len; _i++) {
message = data[_i];
_results.push(toastr[message.extra_tags](message.message));
}
return _results;
});
return window._updateMessages = false;
};
if (USE_PJAX) {
NProgress.start();
window.imageLoad = function(element) {
var imgLoad;
imgLoad = imagesLoaded(element);
imgLoad.on('done', function(event) {
return NProgress.done();
});
return imgLoad.on('progress', function(instance, image) {
var inc;
inc = instance.images.length / 1000;
return NProgress.inc(inc);
});
};
$(function() {
window.updateMessages();
window.imageLoad(document);
if ($.support.pjax) {
return $(document).on('click', 'a[data-pjax]', function(event) {
var container, elem, nav_element, pjax, push;
elem = $(this);
pjax = elem.data('pjax');
push = true;
nav_element = elem.closest('[data-pjax-nav]');
nav_element.siblings('.active').removeClass('active');
nav_element.addClass('active');
if (elem.is('[data-pjax-unnav]')) {
$('[data-pjax-nav].active').removeClass('active');
}
if (elem.is('[pjax-nopush]')) {
push = false;
}
if (!pjax) {
container = $('[data-pjax-container="main"]');
} else if (pjax === 'closest') {
container = elem.closest('[data-pjax-container]');
} else {
container = $("[data-pjax-container='" + pjax + "']");
}
$.pjax.click(event, {
container: container,
timeout: 5000,
push: push,
scrollTo: false
});
if (elem.is('[pjax-messages]')) {
return window._updateMessages = true;
}
});
}
});
$(document).on('pjax:start', function() {
return NProgress.start();
});
$(document).on('pjax:end', function(event) {
window.imageLoad(event.target);
if (typeof ga !== "undefined" && ga !== null) {
ga('send', 'pageview');
}
if (window._updateMessages) {
return window.updateMessages();
}
});
}
$('[data-toggle="tooltip"]').tooltip();

2
shelfzilla/themes/bootflat/templates/_layout.html

@ -106,7 +106,7 @@
<script type="text/javascript" src="{% static "bower/eventEmitter/EventEmitter.js" %}"></script>
<script type="text/javascript" src="{% static "bower/eventie/eventie.js" %}"></script>
<script type="text/javascript" src="{% static "bower/imagesloaded/imagesloaded.js" %}"></script>
<script type="text/coffeescript" src="{% static "coffee/main.coffee" %}"></script>
<script type="text/javascript" src="{% static "js/app.js" %}"></script>
{% endblock %}
{% endcompress %}
{% if not USER_CONFIG.use_pjax %}