This file contains 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
/** | |
* Execute a callback when all images have loaded. | |
* needed because .load() doesn't work on cached images | |
* | |
* Usage: | |
* $('img.photo').imagesLoaded(myFunction) | |
* -> myFunction() { this == [jQuery collection of 'img'] } | |
* | |
* $('img.photo').imagesLoaded(myFunction, myContext) | |
* -> myFunction() { this == myContext } |
This file contains 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
/** | |
* Simple Observer pattern mixin (custom event dispatching & listening) | |
* Doesn't requires any 3rd-party JS libs. It's pure JS | |
* | |
* Usage: | |
* | |
* var MyObject = {...}; // your custom object | |
* Observer.apply(MyObject); // you also can apply Observer to a prototype | |
* MyObject.on('inited', function() { console.log("I'm alive!"); }); | |
* MyObject.trigger('inited'); |
This file contains 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
/** | |
* Noty 2.2.2 Theme: Flat UI colors | |
* @author kottenator | |
*/ | |
.flat .noty_bar { | |
font: 16px/1.3 Arial, Liberation Sans, sans-serif; | |
text-align: center; | |
padding: 12px 15px 13px; | |
position: relative; | |
border: 2px solid #eee; |
This file contains 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
/** | |
* Setup jQuery AJAX | |
* | |
* Requires noty.js and 2 its layouts: noty/layouts/top.js, noty/layouts/topRight.js | |
*/ | |
$.ajaxSetup({ | |
error: function(xhr, status, error) { | |
// we ignore aborted XHR or when user press F5 while XHR is in progress | |
if (status == 'abort' || xhr.readyState == 0) | |
return; |
This file contains 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
/* | |
* Select2 v3.4.6 styles customization for Flat UI | |
*/ | |
/*----------------------------------------------- Main select element ------------------------------------------------*/ | |
.select2-container .select2-choice { | |
height: 41px; /* Jobsy form controls have 37px total height */ | |
border: 2px solid #bdc3c7; | |
border-radius: 6px; | |
outline: none; | |
font: 15px/38px "Lato", Liberation Sans, Arial, sans-serif; |
This file contains 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
""" | |
Field with multiple *static* choices (not via m2m) | |
Value is stored in DB as comma-separated values | |
Default widget is forms.CheckboxSelectMultiple | |
Python value: list of values | |
Original Django snippet: https://djangosnippets.org/snippets/1200/ | |
It's 6 years old and doesn't work with latest Django | |
Also it implements 'max_choices' functionality - I have removed it for simplicity |
This file contains 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
/** | |
* Specific error parser for django-rest-framework errors structure | |
* Tested on django-rest-framework v2.3.13 | |
* Live example at http://jsbin.com/wiqumo | |
* | |
* Error structure examples: | |
* | |
* // The most simple case | |
* { detail: "Authentication is required" } | |
* |
This file contains 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
// Implementation in ES6 | |
function pagination(c, m) { | |
var current = c, | |
last = m, | |
delta = 2, | |
left = current - delta, | |
right = current + delta + 1, | |
range = [], | |
rangeWithDots = [], | |
l; |
This file contains 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
""" | |
Django 'base' app - compressor filters. | |
""" | |
from compressor.filters.css_default import CssAbsoluteFilter | |
class CssRelativeFilter(CssAbsoluteFilter): | |
""" | |
``compressor.filters.css_default.CssAbsoluteFilter`` converts relative URLs to images, fonts, etc | |
in CSS code to absolute URLs like '/static/base/images/logo.svg'. |
This file contains 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
var button = document.createElement('button'); | |
button.textContent = 'Push'; | |
document.body.appendChild(button); | |
var x, title; | |
if (!history.state) { | |
x = 0; | |
title = document.title; | |
// Without this we can loose the initial page's title on browser navigation |
OlderNewer