");
/******************************************************************
*
* We are specifically chosing empty alt-text below, because this
* image conveys no additional information, relative to the text
* that will *always* be there in any select2 list that is in use
* in Snipe-IT. If that changes, we would probably want to change
* some signatures of some functions, but right now, we don't want
* screen readers to say "HP SuperJet 5000, .... picture of HP
* SuperJet 5000..." and so on, for every single row in a list of
* assets or models or whatever.
*
*******************************************************************/
var img = $("
");
// console.warn("Img is: ");
// console.dir(img);
// console.warn("Strigularly, that's: ");
// console.log(img);
img.attr("src", datalist.image );
inner_div.append(img)
} else {
var inner_div=$("
");
}
left_pull.append(inner_div);
root_div.append(left_pull);
var name_div = $("
");
name_div.text(datalist.text);
root_div.append(name_div)
var safe_html = root_div.get(0).outerHTML;
var old_html = formatDatalist(datalist);
if(safe_html != old_html) {
//console.log("HTML MISMATCH: ");
//console.log("FormatDatalistSafe: ");
// console.dir(root_div.get(0));
//console.log(safe_html);
//console.log("FormatDataList: ");
//console.log(old_html);
}
return root_div;
}
function formatDataSelection (datalist) {
// This a heinous workaround for a known bug in Select2.
// Without this, the rich selectlists are vulnerable to XSS.
// Many thanks to @uberbrady for this fix. It ain't pretty,
// but it resolves the issue until Select2 addresses it on their end.
//
// Bug was reported in 2016 :{
// https://github.com/select2/select2/issues/4587
return datalist.text.replace(/>/g, '>')
.replace(/Click me
$('a[data-toggle="tab"]').click(function (e) {
var href = $(this).attr("href");
history.pushState(null, null, href);
e.preventDefault();
$('a[href="' + $(this).attr('href') + '"]').tab('show');
});
// ------------------------------------------------
// End Deep Linking for Bootstrap tabs
// ------------------------------------------------
// Image preview
function readURL(input, $preview) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$preview.attr('src', e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
}
function formatBytes(bytes) {
if(bytes < 1024) return bytes + " Bytes";
else if(bytes < 1048576) return(bytes / 1024).toFixed(2) + " KB";
else if(bytes < 1073741824) return(bytes / 1048576).toFixed(2) + " MB";
else return(bytes / 1073741824).toFixed(2) + " GB";
}
// File size validation
$('.js-uploadFile').bind('change', function() {
var $this = $(this);
var id = '#' + $this.attr('id');
var status = id + '-status';
var $status = $(status);
var delete_id = $(id + '-deleteCheckbox');
var preview_container = $(id + '-previewContainer');
$status.removeClass('text-success').removeClass('text-danger');
$(status + ' .goodfile').remove();
$(status + ' .badfile').remove();
$(status + ' .previewSize').hide();
preview_container.hide();
$(id + '-info').html('');
var max_size = $this.data('maxsize');
var total_size = 0;
for (var i = 0; i < this.files.length; i++) {
total_size += this.files[i].size;
$(id + '-info').append('' + htmlEntities(this.files[i].name) + ' (' + formatBytes(this.files[i].size) + ') ');
}
if (total_size > max_size) {
$status.addClass('text-danger').removeClass('help-block').prepend(' ').append(' Upload is ' + formatBytes(total_size) + '.');
} else {
$status.addClass('text-success').removeClass('help-block').prepend(' ');
var $preview = $(id + '-imagePreview');
readURL(this, $preview);
$preview.fadeIn();
preview_container.fadeIn();
delete_id.hide();
}
});
});
function htmlEntities(str) {
return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"');
}
/**
* Toggle disabled
*/
(function($){
$.fn.toggleDisabled = function(callback){
return this.each(function(){
var disabled, $this = $(this);
if($this.attr('disabled')){
$this.removeAttr('disabled');
disabled = false;
} else {
$this.attr('disabled', 'disabled');
disabled = true;
}
if(callback && typeof callback === 'function'){
callback(this, disabled);
}
});
};
})(jQuery);
/**
* Universal Livewire Select2 integration
*
* How to use:
*
* 1. Set the class of your select2 elements to 'livewire-select2').
* 2. Name your element to match a property in your Livewire component
* 3. Add an attribute called 'data-livewire-component' that points to $this->getId() (via `{{ }}` if you're in a blade,
* or just $this->getId() if not).
*/
document.addEventListener('livewire:init', () => {
$('.livewire-select2').select2()
$(document).on('select2:select', '.livewire-select2', function (event) {
var target = $(event.target)
if(!event.target.name || !target.data('livewire-component')) {
console.error("You need to set both name (which should match a Livewire property) and data-livewire-component on your Livewire-ed select2 elements!")
console.error("For data-livewire-component, you probably want to use $this->getId() or {{ $this->getId() }}, as appropriate")
return false
}
Livewire.find(target.data('livewire-component')).set(event.target.name, this.options[this.selectedIndex].value)
});
Livewire.hook('request', ({succeed}) => {
succeed(() => {
queueMicrotask(() => {
$('.livewire-select2').select2();
});
});
});
});