mirror of
https://github.com/Hopiu/django-select2.git
synced 2026-03-28 10:50:24 +00:00
Now minifying CSS and JS files. During production they will be used intead.
The minification process has been automated too. When sdist command is given to setup.py then it will use web-service to minify the js n css files.
This commit is contained in:
parent
cfc291682c
commit
1aedde99d6
6 changed files with 65 additions and 83 deletions
1
django_select2/static/css/all.min.css
vendored
Normal file
1
django_select2/static/css/all.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
1
django_select2/static/js/heavy_data.min.js
vendored
Normal file
1
django_select2/static/js/heavy_data.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
if(!window.django_select2){var django_select2={MULTISEPARATOR:String.fromCharCode(0),get_url_params:function(c,e,b){var d=$(this).data("field_id"),a={term:c,page:e,context:b};if(d){a.field_id=d}return a},process_results:function(d,c,b){var a;if(d.err&&d.err.toLowerCase()==="nil"){a={results:d.results};if(b){a.context=b}if(d.more===true||d.more===false){a.more=d.more}}else{a={results:[]}}if(a.results){$(this).data("results",a.results)}else{$(this).removeData("results")}return a},onValChange:function(){django_select2.updateText($(this))},prepareValText:function(d,a,c){var b=[];$(d).each(function(e){b.push({id:this,text:a[e]})});if(c){return b}else{if(b.length>0){return b[0]}else{return null}}},updateText:function(b){var f=b.select2("val"),d=b.select2("data"),a=b.txt(),c=!!b.attr("multiple"),e;if(f||f===0){if(c){if(f.length!==a.length){a=[];$(f).each(function(g){var h,j=this,k;for(h in d){k=d[h].id;if(k instanceof String){k=k.valueOf()}if(k==j){a.push(d[h].text)}}})}}else{a=d.text}b.txt(a)}else{b.txt("")}},getValText:function(b){var g=b.select2("val"),c=b.data("results"),a=b.txt(),e=!!b.attr("multiple"),d,h=b.attr("id");if(g||g===0){if(!e){g=[g];if(a||a===0){a=[a]}}if(a===0||(a&&g.length===a.length)){return[g,a]}d=b.data("userGetValText");if(d){a=d(b,g,e);if(a||a===0){return[g,a]}}if(c){a=[];$(g).each(function(f){var j,k=this;for(j in c){if(c[j].id==k){g[f]=c[j].id;a.push(c[j].text)}}});if(a||a===0){return[g,a]}}}return null},onInit:function(b,f){b=$(b);var d=b.attr("id"),a=null,c=b.select2("val");if(!c&&c!==0){c=b.data("initVal")}if(c||c===0){a=django_select2.getValText(b);if(a&&a[0]){a=django_select2.prepareValText(a[0],a[1],!!b.attr("multiple"))}}if(!a){b.val(null)}f(a);django_select2.updateText(b)},onMultipleHiddenChange:function(){var b=$(this),d=b.data("valContainer"),a=b.data("name"),c=b.val();d.empty();if(c){c=c.split(django_select2.MULTISEPARATOR);$(c).each(function(){var e=$('<input type="hidden">').appendTo(d);e.attr("name",a);e.val(this)})}},initMultipleHidden:function(a){var b;a.data("name",a.attr("name"));a.attr("name","");b=$("<div>").insertAfter(a).css({display:"none"});a.data("valContainer",b);a.change(django_select2.onMultipleHiddenChange);if(a.val()){a.change()}},convertArrToStr:function(a){return a.join(django_select2.MULTISEPARATOR)},runInContextHelper:function(a,b){return function(){var c=Array.prototype.slice.call(arguments);return a.apply($("#"+b).get(0),c)}},logErr:function(){if(console&&console.error){args=Array.prototype.slice.call(arguments);console.error.apply(console,args)}},};(function(a){a.fn.txt=function(b){if(typeof(b)!=="undefined"){if(b){if(b instanceof Array){if(this.attr("multiple")){b=django_select2.convertArrToStr(b)}else{b=b[0]}}this.attr("txt",b)}else{this.removeAttr("txt")}return this}else{b=this.attr("txt");if(this.attr("multiple")){if(b){b=b.split(django_select2.MULTISEPARATOR)}else{b=[]}}return b}}})(jQuery)};
|
||||
83
django_select2/static/js/select2.min.js
vendored
Executable file → Normal file
83
django_select2/static/js/select2.min.js
vendored
Executable file → Normal file
File diff suppressed because one or more lines are too long
|
|
@ -35,6 +35,13 @@ def get_select2_heavy_js_libs():
|
|||
else:
|
||||
return libs + ('js/heavy_data.min.js', )
|
||||
|
||||
def get_select2_css_libs():
|
||||
from django.conf import settings
|
||||
if settings.configured and settings.DEBUG:
|
||||
return ('css/select2.css', 'css/extra.css', )
|
||||
else:
|
||||
return ('css/all.min.js', )
|
||||
|
||||
### Light mixin and widgets ###
|
||||
|
||||
class Select2Mixin(object):
|
||||
|
|
@ -207,7 +214,7 @@ class Select2Mixin(object):
|
|||
|
||||
class Media:
|
||||
js = get_select2_js_libs()
|
||||
css = {'screen': ('css/select2.css', 'css/extra.css', )}
|
||||
css = {'screen': get_select2_css_libs()}
|
||||
|
||||
|
||||
class Select2Widget(Select2Mixin, forms.Select):
|
||||
|
|
|
|||
47
setup.py
47
setup.py
|
|
@ -110,6 +110,53 @@ AUTHOR_EMAIL = "admin@applegrew.com"
|
|||
URL = "https://github.com/applegrew/django-select2"
|
||||
VERSION = __import__(PACKAGE).__version__
|
||||
|
||||
def getPkgPath():
|
||||
return __import__(PACKAGE).__path__[0] + '/'
|
||||
|
||||
def minify(files, outfile, ftype):
|
||||
import urllib, json
|
||||
|
||||
content = u''
|
||||
for filename in files:
|
||||
with open(getPkgPath() + filename) as f:
|
||||
for line in f.xreadlines():
|
||||
content = content + line
|
||||
|
||||
data = urllib.urlencode([
|
||||
('code', content),
|
||||
('type', ftype),
|
||||
])
|
||||
data.encode('utf-8')
|
||||
|
||||
f = urllib.urlopen('http://api.applegrew.com/minify', data)
|
||||
data = u''
|
||||
while 1:
|
||||
line = f.readline()
|
||||
if line:
|
||||
data = data + unicode(line)
|
||||
else:
|
||||
break
|
||||
f.close()
|
||||
|
||||
data = json.loads(data)
|
||||
for key in data:
|
||||
value = data[key]
|
||||
if isinstance(value, str) or isinstance(value, unicode):
|
||||
data[key] = unicode(value).decode("string-escape").replace(r'\/', '/')
|
||||
|
||||
if data['success']:
|
||||
with open(getPkgPath() + outfile, 'w') as f:
|
||||
f.write(data['compiled_code'])
|
||||
else:
|
||||
print data['error_code']
|
||||
print data['error']
|
||||
raise Exception('Could not minify.')
|
||||
|
||||
|
||||
if 'sdist' == sys.argv[1]:
|
||||
minify(['static/js/select2.js'], 'static/js/select2.min.js', 'js')
|
||||
minify(['static/js/heavy_data.js'], 'static/js/heavy_data.min.js', 'js')
|
||||
minify(['static/css/select2.css', 'static/css/extra.css'], 'static/css/all.min.css', 'css')
|
||||
|
||||
setup(
|
||||
name=NAME,
|
||||
|
|
|
|||
7
testapp/testapp/templates/500.html
Normal file
7
testapp/testapp/templates/500.html
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
Error 500
|
||||
</body>
|
||||
Loading…
Reference in a new issue