$(document).ready(function() { $(document).on('click', '[data-toggle="lightbox"]', function(event) { event.preventDefault(); $(this).ekkoLightbox(); }); $(document).on('click', '.copyToClipboard', function(e) { var $temp = $("
').focus(); /* $('#' + id).html( '' + '
' + '
' + '' + '
').focus(); */ activateckeditor(id + '_text'); } else { swal('error', 'Something went wrong with your edit of the comment, please try again'); } } }); // $('#' + id).html('
'); activateckeditor(id + '_text'); //$('#cke_' + id + '_text').css({'width':'calc(100% -16px) !important'}); }); $(document).on('click', '.edit_comment_cancel', function(e) { id = $(e.target).data('id'); oldtext = $('#' + id + '_before').val().replace(/\n/g,"
"); $('#' + id).html(oldtext); }); $(document).on('click', '.edit_comment_save', function(e) { id = $(e.target).data('id'); var form_data = new FormData(); form_data.append('id', id); form_data.append('sid',$(e.target).data('shoutout')); form_data.append('oldtext', $('#' + id + '_before').val()); form_data.append('newtext', $('#' + id + '_text').val()); $.ajax({ type: 'post', dataType: 'text', cache: false, contentType: false, processData: false, data: form_data, url: '/data.php?slags=comment_edit&id=0', success: function(data) { data = data.split('|#|'); $('#' + id).html(data[1]); if (data[0] == 0) { swal('error', 'Something went wrong with your edit of the comment, please try again'); } } }); }); $(document).on('click','.comment_delete', function(e) { var id = $(e.target).data('id'); var mytype = $(e.target).data('type'); swal({ title: "Delete Comment", text: "Are you sure you want to delete the selected comment? Deleting a comment can result in losing eventually collected coins from the comment + risk of losing some of your rank because of the points you might have gotten from it?", type: "warning", showCancelButton: true, confirmButtonClass: "btn bg-success gradient-success", cancelButtonClass: "btn bg-danger gradient-danger", confirmButtonText: "Yeah who cares", cancelButtonText: "I regret big long time", }).then((result) => { if (result.value) { $.ajax({ url: '/data.php?slags=comment_delete&id=' + id + '&type=' + mytype, dataType: 'text', // what to expect back from the PHP script, if anything cache: false, contentType: false, processData: false, type: 'get', success: function(svar){ if (svar != 'success') { swal('Error', 'Something went wrong. Please try again. If the problem keeps comming up please contact us at support@compagelab.com with your problem', 'error'); } else { $('#' + mytype + '_' + id).hide(); } } }); } else { swal('Success', 'We all make mistakes once in a while. But next time we will remove the confirmation and just remove it, so be careful :p', 'success'); } }); }); $(document).on('click','.tenorgifmodal', function(e) { localStorage.mygifupload = ''; $('#tenor_modal').appendTo("body").modal('show'); localStorage.imagetype = 'tenor'; localStorage.loc = $(e.target).data('loc'); //window.uploadId = $(e.target).data('id'); //window.loc = $(e.target).data('loc'); $('#Tenor_Modal_Save_GIF').data('loc', $(e.target).data('loc')); $('#Tenor_Modal_Save_GIF').data('textarea', $(e.target).data('textarea')); $('#Tenor_Modal_Save_GIF').data('id', $(e.target).data('id')); $('#Tenor_Modal_Save_GIF').data('subid', $(e.target).data('subid')); $('#Tenor_Modal_Save_GIF').data('profile-owner', $(e.target).data('profile-owner')); $('#Tenor_Modal_Save_GIF').data('shoutout-owner', $(e.target).data('shoutout-owner')); $('#Tenor_Modal_Save_GIF').data('comment-owner', $(e.target).data('comment-owner')); }); $(document).on('click', '.tenorimage', function(e) { $width = $(e.target).data('width'); $height = $(e.target).data('height'); $picture = $(e.target).data('picture'); $selected = $(e.target).data('shareid'); $('#chosenimage').html('

Preview of selected GIF

'); $('#Tenor_Modal_Save_GIF').data('img-src', $picture); $('#Tenor_Modal_Save_GIF').data('img-width', $width); $('#Tenor_Modal_Save_GIF').data('img-height', $height); $('#Tenor_Modal_Save_GIF').data('img-id', $selected); $.ajax({ type: 'get', dataType: 'text', cache: false, contentType: false, processData: false, url: '/data.php?slags=tenor_share&id=' + $selected + '&tenorsearch=' + $('#searchtenor').val(), success: function(data) { // } }); }); $(document).on('click', '#Tenor_Modal_Save_GIF', function(e) { $gif = $(e.target); //'#Tenor_Modal_Save_GIF'); localStorage.mygifupload = $gif.data('loc') + '|!|' + $gif.data('textarea') + '|!|' + $gif.data('id') + '|!|' + $gif.data('subid') + '|!|' + $gif.data('profile-owner') + '|!|' + $gif.data('shoutout-owner') + '|!|' + $gif.data('comment-owner') + '|!|' + $gif.data('img-src') + '|!|' + $gif.data('img-width') + '|!|' + $gif.data('img-height') + '|!|' + $gif.data('img-id'); localStorage.comment_image = ''; }); $(document).on('keyup','#searchtenor', function(e) { $search = $(e.target).val(); if ($search.length >= 3) { $.ajax({ type: 'get', dataType: 'text', cache: false, contentType: false, processData: false, url: '/data.php?slags=tenor_search&id=' + $search, success: function(data) { $('#searchresult').html(data); } }); } }); /************************************ * SHOUTOUTS * ************************************/ $(document).on('click','.profile_shoutout_warning', function(e) { swal('success','As you are on the newsflow you won\'t be able to see the shoutout you just added. The Newsflow only shows news from the people you follow. You can see it in your profile','success'); }); $(document).on('click','.edit_news_privacy', function(e) { $('#news_privacy_' + $(e.target).data('nid')).toggle(); }); $(document).on('click', '.edit_shoutout', function(e) { id = $(e.target).data('id'); // var regex = //gi; // text = $('#' + id).html().replace(regex,"\r"); // id ======= shoutout-{id} / main-comment-text-{id} / sub-comment-text-{id} var idet = id.split('-'); dbid = idet[idet.length-1]; $.ajax({ type: 'post', dataType: 'text', cache: false, contentType: false, processData: false, // data: form_data, url: '/data.php?slags=shoutout_edit_begin&id=' + dbid + '&dbidk=' + idet[0], success: function(data) { //console.log(data); data = data.split('|#|'); if (data[0] == '1') { $('#' + id).html(data[1]); $('#' + id).html( '' + '
' + '
' + '' + '
').focus(); activateckeditor(id + '_text'); } else { swal('error', 'Something went wrong with your edit of the comment, please try again'); } } }); }); $(document).on('click', '.edit_shoutout_cancel', function(e) { id = $(e.target).data('id'); oldtext = $('#' + id + '_before').val().replace(/\n/g,"
"); $('#' + id).html(oldtext); }); $(document).on('click', '.edit_shoutout_save', function(e) { id = $(e.target).data('id'); oldtext = $('#' + id + '_before').val(); newtext = $('#' + id + '_text').val(); var form_data = new FormData(); form_data.append('id', id); form_data.append('oldtext', oldtext); form_data.append('newtext', newtext); $.ajax({ type: 'post', dataType: 'text', cache: false, contentType: false, processData: false, data: form_data, url: '/data.php?slags=shoutout_edit_done&id=0', success: function(data) { //console.log(data); data = data.split('|#|'); $('#' + id).html(data[1]); if (data[0] == 0) { swal('error', 'Something went wrong with your edit of the comment, please try again'); } } }); }); $(document).on('click', '.goto-reply', function(e) { $('#main-reply' + $(e.target).data('id')).focus(); }); $(document).on('click', '.shoutout_delete_image', function(e) { $id = $(e.target).data('id'); $('#myownimage_' + $id).remove(); $.ajax({ url: '/data.php?slags=delete_uploaded_image&id=' + $id, dataType: 'text', // what to expect back from the PHP script, if anything cache: false, contentType: false, processData: false, type: 'post', success: function(svar){ // } }); }); function addimage(id, src, uniqueid, type) { if (type == 'shoutout') { var str = "
"; str += ""; str += ""; str += "
"; str += ""; } else if (type == 'shoutout_comment') { var str = "
"; str += ""; str += ""; str += "
"; str += ""; } $('#' + id).html(str); //$('#troxa_copy').html()); } $(document).on('click', '.troxa_tilfoj', function(e) { $('#troxa_add').append($('#troxa_copy').html()); }); $(document).on('click','.troxa_fardig', function(e) { id = $(e.target).data('id'); pid = $(e.target).data('pid'); var form_data = new FormData(); if ( typeof window.uploadId !== 'undefined' ) { form_data.append('tempid', window.uploadId); } form_data.append('text', $('#userpost').val()); $.ajax({ url: '/data.php?slags=add_user_news&id=' + pid, dataType: 'text', cache: false, contentType: false, processData: false, data: form_data, type: 'post', success: function(svar){ if (svar != '') { $('#mynewsflow').prepend(svar); $('#troxa_add').html(''); $('#userpost').val(''); window.uploadId = ''; jQuery("time.timeago").timeago(); } } }); }); $(document).on('click', '.troxa_upload_billede', function(e){ e.preventDefault(); window.uploadId = $(e.target).data('id'); window.loc = $(e.target).data('loc'); $('#uploadfil').click(); }); $("#uploadfil").on('change', function (e) { localStorage.comment_image = ''; if (window.File && window.FileList && window.FileReader) { for (var i = 0; i < this.files.length; i++) { const file = this.files[i]; if (file.type.indexOf('image') != 0) continue var picReader = new FileReader(); picReader.onload = function (e) { var picFile = e.target; if (window.loc == 'troxa_add') { var loctype='shoutout'; var where_to_send = 'add_users_news_file'; } else { var loctype = 'shoutout_comment'; var where_to_send = 'add_users_comment_file'; } var file_data = file; // e.target.result; if (file_data != undefined) { var form_data = new FormData(); form_data.append('file', file_data); form_data.append('tempid', window.uploadId); $.ajax({ url: '/data.php?slags=' + where_to_send + '&id=0', dataType: 'text', // what to expect back from the PHP script, if anything cache: false, contentType: false, processData: false, data: form_data, type: 'post', success: function(svar){ addimage(window.loc, e.target.result, svar, loctype); localStorage.comment_image = svar; localStorage.mygifupload = ''; } }); }; }; picReader.readAsDataURL(file); //Read the image } } else { console.log("Your browser does not support File API"); } }); $(document).on('click', '.letshack2', function(e) { e.preventDefault(); $('#nyheds_billede').click(); }); $(document).on('click', '.letshack3', function(e) { e.preventDefault(); $('#nyheds_kommentar_billede').click(); }); $(document).on('click', '.shoutout_delete', function(e) { var id = $(e.target).data('id'); swal({ title: "Delete Shoutout", text: "Are you sure you want to delete the selected shoutout? Deleting a shoutout will result in losing eventually collected coins from the shoutout + risk of losing some of your rank because of the points you might have gotten from it?", type: "warning", showCancelButton: true, confirmButtonClass: "btn bg-success gradient-success", cancelButtonClass: "btn bg-danger gradient-danger", confirmButtonText: "Yeah who cares", cancelButtonText: "I regret big long time", }).then((result) => { if (result.value) { $.ajax({ url: '/data.php?slags=shoutout_delete&id=' + id, dataType: 'text', // what to expect back from the PHP script, if anything cache: false, contentType: false, processData: false, type: 'get', success: function(svar){ if (svar == 'success') { $('#news_' + id).hide(); swal('Success', 'The selected ShoutOut have been deleted', 'success'); } else { swal('Error', 'Something went wrong. Please try again. If the problem keeps comming up please contact us at support@compagelab.com with your problem', 'error'); } } }); } else { swal('Success', 'We all make mistakes once in a while. But next time we will remove the confirmation and just remove it, so be careful !', 'success'); } }); }); /************************************ * LIKE SYSTEM * ************************************/ $(document).on('click', '.img-react', function(e) { var form_data = new FormData(); var type = $(e.target).data('type'); var icon = $(e.target).data('react'); var id = $(e.target).data('id'); var ilike = $(e.target).data('ilike'); var profile = $(e.target).data('profile'); var owner = $(e.target).data('owner'); var shoutout = $(e.target).data('shoutout'); var comment = $(e.target).data('comment'); form_data.append('ilike', ilike); form_data.append('type', type); form_data.append('shoutout', shoutout); form_data.append('comment', comment); form_data.append('owner', owner); form_data.append('profile', profile); if (ilike == 'no') { form_data.append('icon', icon); } $.ajax({ type: 'post', dataType: 'text', cache: false, contentType: false, processData: false, data: form_data, url: '/data.php?slags=like_react&id=' + id, success: function(data) { // console.log(data); // alert('img-react: -' + type + '-' + id + '-'); $('#add-' + type + '-' + id).html(data); if (ilike == 'yes') { $('#like_' + type + '_' + id).html(''); $('#' + type + '-' + id).data('ilike', 'no').html('  Like'); } else { $('#like_' + type + '_' + id).html(''); $('#' + type + '-' + id).data('ilike', 'yes').html('  Remove Like'); } } }); }); $(document).on('click','.likelink', function(e) { var ilike = $(e.target).data('ilike'); $('#CPL-React').hide(); if (ilike == 'yes') { var form_data = new FormData(); var type = $(e.target).data('type'); var id = $(e.target).data('id'); form_data.append('ilike', ilike); form_data.append('type', type); var owner = $(e.target).data('owner'); var shoutout = $(e.target).data('shoutout'); var comment = $(e.target).data('comment'); var profile = $(e.target).data('profile'); form_data.append('profile', profile); form_data.append('shoutout', shoutout); form_data.append('comment', comment); form_data.append('owner', owner); $.ajax({ type: 'post', dataType: 'text', cache: false, contentType: false, processData: false, data: form_data, url: '/data.php?slags=like_react&id=' + id, success: function(data) { // console.log(data); // alert('Likelink: -' + type + '-' + id + '-'); $('#add-' + type + '-' + id).html(data); /* if (ilike == 'yes') { $('#' + type + '-' + id).data('ilike', 'no').html('  Like'); } else { $('#' + type + '-' + id).data('ilike', 'yes').html('  Remove Like'); } */ if (ilike == 'yes') { $('#like_' + type + '_' + id).html(''); $('#' + type + '-' + id).data('ilike', 'no').html('  Like'); } else { $('#like_' + type + '_' + id).html(''); $('#' + type + '-' + id).data('ilike', 'yes').html('  Remove Like'); } } }); } else { $('#CPL-React').css({'top':e.pageY-100,'left':e.pageX-100, 'position':'absolute', 'padding':'5px'}); $('.img-react').data('id', $(e.target).data('id')); $('.img-react').data('type', $(e.target).data('type')); $('.img-react').data('ilike', $(e.target).data('ilike')); $('.img-react').data('profile', $(e.target).data('profile')); $('.img-react').data('owner', $(e.target).data('owner')); $('.img-react').data('shoutout', $(e.target).data('shoutout')); $('.img-react').data('comment', $(e.target).data('comment')); $('#CPL-React').toggle(); // show(); } }); $('#CPL-React') .mouseout(function(e) { window.t = setTimeout(function() { $('#CPL-React').fadeOut("slow"); }, 250); }) .mouseover(function(e){ if(window.t){ clearTimeout(window.t); window.t = undefined; } else { /* Do your menu popup thing here */ } }); $(document).on('click', function (e) { if (!$(e.target).hasClass('likelink')) { if ($('#CPL-React').is(":visible")) { $('#CPL-React').fadeOut("slow"); } } }); $(document).on('click','.ilikedislike', function(e) { var slags = $(this).data('slags'); var id = $(this).data('id'); var vardi = $(this).data('like'); $.ajax({ type: 'post', url: '/data.php?slags=ilikedislike&id=' + id, data: {'slags':slags, 'vardi': vardi }, success: function(data) { if (data != '') { data = data.split('|||'); var mitid = '#likes_' + data[2] + '_' + data[1]; $(mitid).html(data[3]); } } }); }); /************************************ * SINGLE FUNCTIONS * ************************************/ /* .on('mouseout', function(e) { setTimeout(function() { $('#questionMarkId').hide(); }, 300); }); */ function GeoIP() { var test = ''; $.ajax({ url: "https://geoip-db.com/jsonp", jsonpCallback: "callback", dataType: "jsonp", success: function( location ) { test = location.country_name + '|!|' + location.state + '|!|' + location.city + '|!|' + location.latitude + '|!|' + location.longitude + '|!|' + location.IPv4; $.ajax({ url: '/data.php?slags=geoip&geoip=' + test + '&id=0', dataType: 'text', cache: false, contentType: false, processData: false, type: 'get', success: function(svar){ } }); } }); } $(document).on('click', '#change_sidebar_state', function(e) { if (window.menu_state == 'large') { window.menu_state = 'mini'; $('body').addClass('sidebar-xs'); //$('#top-bar').removeClass('fixed-top').hide(); $('#sidebar-menu-toggler').removeClass().addClass('icon-arrow-right16'); //$('#mysidebar_content').css('top', 50); } else { window.menu_state = 'large'; $('body').removeClass('sidebar-xs'); //$('#top-bar').addClass('fixed-top').show(); //$('body').addClass('sidebar-xs navbar-top navbar-bottom'); $('#sidebar-menu-toggler').removeClass().addClass('icon-arrow-left16'); // $('#mysidebar_content').css('top', 50); } $.ajax({ type: 'post', url: '/data.php?slags=sidebar_state_save&id=0', data: {'state':'state' }, success: function(data) { if (data != '') { // alert(data); } } }); }); }); function check_tagname(tag, ok_id) { if (tag != '') { $.ajax({ type: 'get', dataType: 'text', cache: false, contentType: false, processData: false, url: '/data.php?slags=check_availability&tagname=' + tag + '&id=' + ok_id, success: function(data) { return data; } }); } } function check_tagname_new(tag, ok_id = 0) { var answer = 0; if (tag != '') { $.ajax({ type: 'get', dataType: 'text', cache: false, contentType: false, processData: false, url: '/data.php?slags=check_tagname&tagname=' + tag + '&id=' + ok_id, success: function(data) { if (data == 'success') { answer = 1; } } }); } return answer; } function check_email(email) { var return_data = ''; if (email != '') { $.ajax({ type: 'get', dataType: 'text', cache: false, contentType: false, processData: false, url: '/data.php?slags=check_email&email=' + email + '&id=0', success: function(data) { return_data = data; } }); } return return_data; } function dataFeed( opts, callback ) { var matchProperty = 'username', data = users.filter( function( item ) { return item[ matchProperty ].indexOf( opts.query.toLowerCase() ) == 0; } ); data = data.sort( function( a, b ) { return a[ matchProperty ].localeCompare( b[ matchProperty ], undefined, { sensitivity: 'accent' } ); } ); callback( data ); } function dataFeed2( opts, callback ) { var matchProperty = 'fullname', data = users.filter( function( item ) { return item[ matchProperty ].indexOf( opts.query.toLowerCase() ) == 0; } ); data = data.sort( function( a, b ) { return a[ matchProperty ].localeCompare( b[ matchProperty ], undefined, { sensitivity: 'accent' } ); } ); callback( data ); } $(document).on('keyup', '.postnr', function(e) { var postnr = $(e.target).val(); var byfelt = $(e.target).data('byfelt'); if (postnr.toString().length == 4) { $.ajax( { url: '/data.php?slags=hent_by&id=' + postnr, cache: false, //success: function(data) { }, success: function(data) { $('#' + byfelt).val(data); } }); } }); $(document).on('click','#hentcvr', function (e) { var cvr = $('#cvr').val(); var byfelt = $(e.target).data('byfelt'); var size = cvr.length; if (size == 8) { $.ajax({ url: '/data.php?slags=hent_cvr&id=' + cvr, cache: false, success: function(data) { if (data == 'Error') { swal.fire({ icon: 'info', title: 'Fejl', html: 'Der kunne ikke hentes data ud fra det indtastede CVR nummer. Se venligst efter om du har skrevet det rigtigt', }); swal("Info", "Der kunne ikke hentes data ud af CVR nummeret.", "info"); } else { console.log('data: ' + data); data = data.split('|'); $('#cnr').val(cvr); $('#cvrnavn').val(data[0]); $('#cvradresse').val(data[1]); $('#cvrpostnr').val(data[2]); $('#cvrtelefon').val(data[3]); $('#cvremail').val(data[4]); $.ajax({ url: '/data.php?slags=hent_by&id=' + data[2], cache: false, success: function(data) { $('#' + byfelt).val(data); } }); $.ajax({ url: '/data.php?slags=hent_pnumre&id=' + cvr + '&pnr=' + data[5], cache: false, success: function(data) { data = data.split('|¤|'); $.each(data, function( index, value ) { value = value.split('|'); $('#pnummer').append(''); }); } }); $('#opret_card').show(); $('#cvr_card').hide(); } } }); } else { swal.fire({ icon: 'error', title: 'Fejl', html: 'CVR nummeret er ikke på 8 tal. Tjek venligst dit indtastede CVR nummer og prøv igen', }); } }); var users = [ ], tagsa = [ ]; function aktiver_editor(id) { $( '#' + id ).ckeditor( { startupFocus : true, extraPlugins: 'autogrow', autoGrow_minHeight: 180, autoGrow_maxHeight: 800, uiColor: '#FFFFFF', toolbarLocation: 'top', autoParagraph: false, allowedContent: true, // plugins: 'mentions,fullstyles,link,wysiwygarea,toolbar,smiley,colorbutton', contentsCss: [ 'https://fonts.googleapis.com/css?family=Roboto:400,300,100,500,700,900', '/assets/js/plugins/editors/ckeditor_test/contents.css?u=1787759368', //'https://sdk.ckeditor.com/samples/assets/mentions/contents.css', '/includes/ckeditor.css?u=1787759368' ], height: 180, /* toolbar: [ { name: 'document', items: [ 'Undo', 'Redo' ] }, { name: 'basicstyles', items: [ 'Bold', 'Italic', 'Underline' ] }, { name: 'links', items: [ 'Link', 'Unlink' ] }, { name: 'insert', items: [ 'Image', 'Table', 'HorizontalRule', 'SpecialChar' ] }, ], */ toolbarGroups: [{ "name": "basicstyles", "groups": ["basicstyles"] }, { "name": "links", "groups": ["links"] }, { "name": "paragraph", "groups": ["list", "blocks"] }, { "name": "document", "groups": ["mode"] }, { "name": "insert", "groups": ["insert"] }, { "name": "styles", "groups": ["styles"] }, { "name": "about", "groups": ["about"] } ], //removeDialogTabs: 'image:advanced;link:advanced;link:target', //removeButtons: 'Link,Unlink', mentions: [ { feed: dataFeed2, itemTemplate: '
  • ' + '' + '  {fullname}' + '
  • ', outputTemplate: '{fullname}  ', minChars: 0 }, { feed: tagsa, marker: '#', itemTemplate: '
  • {name}
  • ', outputTemplate: '{name}  ', minChars: 0 } ] } ); }