new static files.
Signed-off-by: rscnt <rascnt@gmail.com>
This commit is contained in:
parent
83e792bcaa
commit
fe4f6c97d5
778 changed files with 71557 additions and 0 deletions
253
static/django_select2/js/heavy_data.js
Normal file
253
static/django_select2/js/heavy_data.js
Normal file
|
|
@ -0,0 +1,253 @@
|
|||
if (!window['django_select2']) {
|
||||
// This JS file can be included multiple times. So, as not to overwrite previous states, we run this only once.
|
||||
|
||||
window.django_select2 = {
|
||||
MULTISEPARATOR: String.fromCharCode(31), // We use this unprintable char as separator,
|
||||
// since this can't be entered by user.
|
||||
get_url_params: function (term, page, context) {
|
||||
var field_id = jQuery(this).data('field_id'),
|
||||
res = {
|
||||
'term': term,
|
||||
'page': page,
|
||||
'context': context
|
||||
};
|
||||
if (field_id) {
|
||||
res['field_id'] = field_id;
|
||||
}
|
||||
return res;
|
||||
},
|
||||
process_results: function (data, page, context) {
|
||||
var results;
|
||||
if (data.err && data.err.toLowerCase() === 'nil') {
|
||||
results = {
|
||||
'results': data.results
|
||||
};
|
||||
if (context) {
|
||||
results['context'] = context;
|
||||
}
|
||||
if (data.more === true || data.more === false) {
|
||||
results['more'] = data.more;
|
||||
}
|
||||
} else {
|
||||
results = {'results':[]};
|
||||
}
|
||||
if (results.results) {
|
||||
jQuery(this).data('results', results.results);
|
||||
} else {
|
||||
jQuery(this).removeData('results');
|
||||
}
|
||||
return results;
|
||||
},
|
||||
onValChange: function () {
|
||||
django_select2.updateText(jQuery(this));
|
||||
},
|
||||
prepareValText: function (vals, txts, isMultiple) {
|
||||
var data = []
|
||||
jQuery(vals).each(function (index) {
|
||||
data.push({id: this, text: txts[index]});
|
||||
});
|
||||
if (isMultiple) {
|
||||
return data;
|
||||
} else {
|
||||
if (data.length > 0) {
|
||||
return data[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
},
|
||||
updateText: function ($e) {
|
||||
var val = $e.select2('val'), data = $e.select2('data'), txt = $e.txt(), isMultiple = !!$e.attr('multiple'),
|
||||
diff;
|
||||
|
||||
if (val || val === 0) { // Means value is set. A numerical 0 is also a valid value.
|
||||
if (isMultiple) {
|
||||
if (val.length !== txt.length) {
|
||||
txt = [];
|
||||
jQuery(val).each(function (idx) {
|
||||
var i, value = this, id;
|
||||
|
||||
for (i in data) {
|
||||
id = data [i].id;
|
||||
if (id instanceof String) {
|
||||
id = id.valueOf();
|
||||
}
|
||||
if (id == value) {
|
||||
txt.push(data[i].text);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
txt = data.text;
|
||||
}
|
||||
$e.txt(txt);
|
||||
} else {
|
||||
$e.txt('');
|
||||
}
|
||||
},
|
||||
getValText: function ($e) {
|
||||
var val = $e.select2('val'), res = $e.data('results'), txt = $e.txt(), isMultiple = !!$e.attr('multiple'),
|
||||
f, id = $e.attr('id');
|
||||
if (val || val === 0) { // Means value is set. A numerical 0 is also a valid value.
|
||||
|
||||
if (!isMultiple) {
|
||||
val = [val];
|
||||
if (txt || txt === 0) {
|
||||
txt = [txt];
|
||||
}
|
||||
}
|
||||
|
||||
if (txt === 0 || (txt && val.length === txt.length)) {
|
||||
return [val, txt];
|
||||
}
|
||||
|
||||
f = $e.data('userGetValText');
|
||||
if (f) {
|
||||
txt = f($e, val, isMultiple);
|
||||
if (txt || txt === 0) {
|
||||
return [val, txt];
|
||||
}
|
||||
}
|
||||
|
||||
if (res) {
|
||||
txt = [];
|
||||
jQuery(val).each(function (idx) {
|
||||
var i, value = this;
|
||||
|
||||
for (i in res) {
|
||||
if (res[i].id == value) {
|
||||
val[idx] = res[i].id; // To set it to correct data type.
|
||||
txt.push(res[i].text);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (txt || txt === 0) {
|
||||
return [val, txt];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onInit: function (e, callback) {
|
||||
e = jQuery(e);
|
||||
var id = e.attr('id'), data = null, val = e.select2('val');
|
||||
|
||||
if (!val && val !== 0) {
|
||||
val = e.data('initVal');
|
||||
}
|
||||
|
||||
if (val || val === 0) {
|
||||
// Value is set so need to get the text.
|
||||
data = django_select2.getValText(e);
|
||||
if (data && data[0]) {
|
||||
data = django_select2.prepareValText(data[0], data[1], !!e.attr('multiple'));
|
||||
}
|
||||
}
|
||||
if (!data) {
|
||||
e.val(null); // Nulling out set value so as not to confuse users.
|
||||
}
|
||||
callback(data); // Change for 2.3.x
|
||||
django_select2.updateText(e);
|
||||
},
|
||||
createSearchChoice: function(term, data) {
|
||||
if (!data || jQuery(data).filter(function () {
|
||||
return this.text.localeCompare(term) === 0;
|
||||
}).length === 0) {
|
||||
return {
|
||||
id: term,
|
||||
text: term
|
||||
};
|
||||
}
|
||||
},
|
||||
onMultipleHiddenChange: function () {
|
||||
var $e = jQuery(this), valContainer = $e.data('valContainer'), name = $e.data('name'), vals = $e.val();
|
||||
valContainer.empty();
|
||||
if (vals) {
|
||||
vals = vals.split(django_select2.MULTISEPARATOR);
|
||||
jQuery(vals).each(function () {
|
||||
var inp = jQuery('<input type="hidden">').appendTo(valContainer);
|
||||
inp.attr('name', name);
|
||||
inp.val(this);
|
||||
});
|
||||
}
|
||||
},
|
||||
initMultipleHidden: function ($e) {
|
||||
var valContainer;
|
||||
|
||||
$e.data('name', $e.attr('name'));
|
||||
$e.attr('name', '');
|
||||
|
||||
valContainer = jQuery('<div>').insertAfter($e).css({'display': 'none'});
|
||||
$e.data('valContainer', valContainer);
|
||||
|
||||
$e.change(django_select2.onMultipleHiddenChange);
|
||||
if ($e.val()) {
|
||||
$e.change();
|
||||
}
|
||||
},
|
||||
convertArrToStr: function (arr) {
|
||||
return arr.join(django_select2.MULTISEPARATOR);
|
||||
},
|
||||
runInContextHelper: function (f, id) {
|
||||
return function () {
|
||||
var args = Array.prototype.slice.call(arguments, 0);
|
||||
return f.apply(jQuery('#' + id).get(0), args);
|
||||
}
|
||||
},
|
||||
logErr: function () {
|
||||
if (console && console.error) {
|
||||
args = Array.prototype.slice.call(arguments);
|
||||
console.error.apply(console, args);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
(function (isDebug) { // Only used for debugging.
|
||||
if (isDebug) {
|
||||
for (var i in django_select2) {
|
||||
var f = django_select2[i];
|
||||
if (typeof(f) == "function") {
|
||||
django_select2[i] = (function (i, f) {
|
||||
return function () {
|
||||
console.log('Function ' + i + ' called for object: ', this);
|
||||
return f.apply(this, arguments);
|
||||
};
|
||||
}(i, f));
|
||||
}
|
||||
}
|
||||
}
|
||||
}(false));
|
||||
|
||||
(function( $ ){
|
||||
// This sets or gets the text lables for an element. It merely takes care returing array or single
|
||||
// value, based on if element is multiple type.
|
||||
$.fn.txt = function(val) {
|
||||
if (typeof(val) !== 'undefined') {
|
||||
if (val) {
|
||||
if (val instanceof Array) {
|
||||
if (this.attr('multiple')) {
|
||||
val = django_select2.convertArrToStr(val);
|
||||
} else {
|
||||
val = val[0]
|
||||
}
|
||||
}
|
||||
this.attr('txt', val);
|
||||
} else {
|
||||
this.removeAttr('txt');
|
||||
}
|
||||
return this;
|
||||
} else {
|
||||
val = this.attr('txt');
|
||||
if (this.attr('multiple')) {
|
||||
if (val) {
|
||||
val = val.split(django_select2.MULTISEPARATOR);
|
||||
} else {
|
||||
val = [];
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
};
|
||||
})( jQuery );
|
||||
}
|
||||
1
static/django_select2/js/heavy_data.min.js
vendored
Normal file
1
static/django_select2/js/heavy_data.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
if(!window.django_select2){window.django_select2={MULTISEPARATOR:String.fromCharCode(31),get_url_params:function(c,e,b){var d=jQuery(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){jQuery(this).data("results",a.results)}else{jQuery(this).removeData("results")}return a},onValChange:function(){django_select2.updateText(jQuery(this))},prepareValText:function(d,a,c){var b=[];jQuery(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=[];jQuery(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=[];jQuery(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=jQuery(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)},createSearchChoice:function(a,b){if(!b||jQuery(b).filter(function(){return this.text.localeCompare(a)===0}).length===0){return{id:a,text:a}}},onMultipleHiddenChange:function(){var b=jQuery(this),d=b.data("valContainer"),a=b.data("name"),c=b.val();d.empty();if(c){c=c.split(django_select2.MULTISEPARATOR);jQuery(c).each(function(){var e=jQuery('<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=jQuery("<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,0);return a.apply(jQuery("#"+b).get(0),c)}},logErr:function(){if(console&&console.error){args=Array.prototype.slice.call(arguments);console.error.apply(console,args)}}};(function(b){if(b){for(var a in django_select2){var c=django_select2[a];if(typeof(c)=="function"){django_select2[a]=(function(d,e){return function(){console.log("Function "+d+" called for object: ",this);return e.apply(this,arguments)}}(a,c))}}}}(false));(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)};
|
||||
3541
static/django_select2/js/select2.js
Normal file
3541
static/django_select2/js/select2.js
Normal file
File diff suppressed because one or more lines are too long
1
static/django_select2/js/select2.min.js
vendored
Normal file
1
static/django_select2/js/select2.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue