Heimdall/resources/views/items/scripts.blade.php

196 lines
9.4 KiB
PHP
Raw Normal View History

2018-10-19 14:10:05 +00:00
<script src="{{ asset('js/select2.min.js') }}"></script>
2018-02-05 19:43:24 +00:00
<script>
$( function() {
2018-02-05 23:08:37 +00:00
var base = (document.querySelector('base') || {}).href;
2018-02-05 23:08:37 +00:00
var elem = $('.color-picker')[0];
var hueb = new Huebee( elem, {
// options
2018-10-28 20:41:46 +00:00
setBGColor: '.set-bg-elem'
});
2018-10-28 20:41:46 +00:00
hueb.on( 'change', function( color, hue, sat, lum ) {
$.get('{{ route('titlecolour') }}', {color}, function(data) {
$('#tile-preview .title').removeClass("black white");
$('#tile-preview .link').removeClass("black white");
$('#tile-preview .title').addClass(data);
$('#tile-preview .link').addClass(data);
});
})
var availableTags = @json(App\Application::autocomplete());
console.log(availableTags)
2018-02-05 19:43:24 +00:00
$( "#appname" ).autocomplete({
source: availableTags,
select: function( event, ui ) {
event.preventDefault();
// appload(ui.item.value);
$( "#appname" ).val(ui.item.label)
$('#apptype').val(ui.item.value).change()
2018-11-04 16:03:55 +00:00
}
});
// initial load
$('#tile-preview .title').html($('#appname').val());
$('#tile-preview .item').css('backgroundColor', $('#appcolour').val());
$('#tile-preview .app-icon').attr('src', $('#appimage img').attr('src'));
// Updates
2018-11-04 16:03:55 +00:00
$('#appname').on('keyup change', function(e) {
$('#tile-preview .title').html($(this).val());
})
$('#apptype').on('change', function(e) {
appload($(this).find('option:selected').val());
2018-11-04 16:03:55 +00:00
});
$('#appcolour').on('change', function(e) {
$('#tile-preview .item').css('backgroundColor', $(this).val());
})
2022-03-16 19:41:01 +00:00
$('#websiteiconoptions').on('click', '.iconbutton', function (e) {
const src = $('.selecticon', this).attr('src')
$('#appimage').html("<img src='"+src+"' /><input type='hidden' name='icon' value='"+src+"' />");
$('#tile-preview .app-icon').attr('src', src);
}).on('click', '.selectclose', function () {
$('#websiteiconoptions').html('')
})
2018-11-04 16:03:55 +00:00
$('.tags').select2();
if($('#appurl').val() !== '') {
if ($('#appurl').val().indexOf("://") !== -1) {
$('#appurl').parent().find('.help').hide()
}
}
if($('#website').val() !== '') {
if ($('#website').val().indexOf("://") !== -1) {
$('#website').parent().find('.help').hide()
}
}
$('#appurl, #website').on('input', function () {
if ($(this).val().indexOf("://") !== -1) {
$(this).parent().find('.help').hide()
}
})
2022-03-16 15:49:44 +00:00
$('#searchwebsite').on('click', 'button.btn', function (e) {
e.preventDefault()
let websiteurl = $('#searchwebsite input').val()
website = btoa(websiteurl)
$.get(base + 'items/websitelookup/' + website, function (data) {
const url = new URL(websiteurl)
const websitedata = {}
const parser = new DOMParser()
const document = parser.parseFromString(data, 'text/html')
const links = document.getElementsByTagName('link')
websitedata.title = document.getElementsByTagName('title')[0].innerText
const metas = document.getElementsByTagName('meta')
const icons = []
for (let i = 0; i < metas.length; i++) {
if (metas[i].getAttribute('name') === 'description') {
websitedata.description = metas[i].getAttribute('content')
}
}
for (let i = 0; i < links.length; i++) {
const link = links[i]
const rel = link.getAttribute('rel')
if (rel) {
if (rel.toLowerCase().indexOf('icon') > -1) {
const href = link.getAttribute('href')
// Make sure href is not null / undefined
if (href) {
if (href.toLowerCase().indexOf('https:') === -1 && href.toLowerCase().indexOf('http:') === -1 && href.indexOf('//') !== 0) {
let finalBase = ''
if (websiteurl.endsWith('/')) {
const baseurl = websiteurl.split('/')
baseurl.pop()
finalBase = baseurl.join('/')
} else {
finalBase = websiteurl
}
let absoluteHref = finalBase
if (href.indexOf('/') === 0) {
absoluteHref += href
} else {
const path = url.pathname.split('/')
path.pop()
const finalPath = path.join('/')
absoluteHref += finalPath + '/' + href
}
icons.push(encodeURI(absoluteHref))
} else if (href.indexOf('//') === 0) {
// Absolute url with no protocol
const absoluteUrl = url.protocol + href
icons.push(encodeURI(absoluteUrl))
} else {
// Absolute
icons.push(encodeURI(href))
}
}
}
}
}
websitedata.icons = icons
2022-03-16 19:41:01 +00:00
if ($('#appname').val() === '') $('#appname').val(websitedata.title)
if ($('#appurl').val() === '') $('#appurl').val(websiteurl)
$('input[name=pinned]').prop('checked', true);
// $('#appimage').html("<img src='"+websitedata.icons[0]+"' /><input type='hidden' name='icon' value='"+websitedata.icons[0]+"' />");
2022-03-16 15:49:44 +00:00
$('#tile-preview .app-icon').attr('src', $('#appimage img').attr('src'));
2022-03-16 19:41:01 +00:00
$('#tile-preview .title').text($('#appname').val());
$('#websiteiconoptions').html('<div class="header"><span>Select Icon</span><span class="selectclose">Close</span></div><div class="results"></div>')
icons.forEach(icon => {
$('#websiteiconoptions .results').append('<div class="iconbutton"><img class="selecticon" src="' + icon + '" /></div>')
})
2022-03-16 15:49:44 +00:00
console.log(websitedata)
})
console.log(website)
})
$('.optdetails button.dark').on('click', function (e) {
e.preventDefault()
$(this).parent().next().toggleClass('active')
})
2018-11-04 16:03:55 +00:00
function appload(appvalue) {
2022-03-15 18:19:01 +00:00
if(appvalue == 'null') {
$('#sapconfig').html('').hide();
2022-03-14 12:25:20 +00:00
$('#tile-preview .app-icon').attr('src', '/img/heimdall-icon-small.png');
$('#appimage').html("<img src='/img/heimdall-icon-small.png' />");
2022-03-15 18:19:01 +00:00
$('#sapconfig').html('').hide();
} else {
$.post('{{ route('appload') }}', { app: appvalue }, function(data) {
2018-10-28 20:41:46 +00:00
// Main details
2022-03-15 18:19:01 +00:00
$('#appimage').html("<img src='"+data.iconview+"' /><input type='hidden' name='icon' value='"+data.iconview+"' />");
2018-02-05 20:59:38 +00:00
$('input[name=colour]').val(data.colour);
2022-03-15 18:19:01 +00:00
$('select[name=appid]').val(data.appid);
2018-02-05 23:08:37 +00:00
hueb.setColor( data.colour );
$('input[name=pinned]').prop('checked', true);
2018-10-28 20:41:46 +00:00
// Preview details
$('#tile-preview .app-icon').attr('src', data.iconview);
2022-03-16 15:49:44 +00:00
$('#appdescription').val(data.description);
if($('#appname').val() === '') {
$('#appname').val(data.name)
}
$('#tile-preview .title').html($('#appname').val());
2022-03-15 18:19:01 +00:00
if(data.custom != null) {
$.get(base+'view/'+data.custom, function(getdata) {
2018-02-05 23:08:37 +00:00
$('#sapconfig').html(getdata).show();
});
} else {
$('#sapconfig').html('').hide();
2018-02-05 23:08:37 +00:00
}
2018-02-05 20:59:38 +00:00
}, "json");
}
2018-02-17 00:13:38 +00:00
2018-11-04 16:03:55 +00:00
}
2018-02-17 00:13:38 +00:00
2018-02-05 19:43:24 +00:00
});
</script>