function ConfirmModal(parent) { this.parent = parent; this.submitButton = '.modal-confirm-submit'; this.cancelButton = '.modal-confirm-cancel'; this.holder = '#modal-confirm'; this.settings = { modalLabel: 'Confirmation', modalBody: 'Are you sure?', modalSubmit: 'Okay', modalCancel: 'Cancel', redirectUrl: '', ajax: '', snippet: '', success: function() { }, cancel: function() { } }; this.init = function(settings) { var modal = this; this.settings = $.extend(this.settings, settings ); this.setModal(); $('body').off('click', this.submitButton); $('body').on('click', this.submitButton, function(){ if(typeof $(modal.parent).data('invalid-snippet') != 'undefined') { sendAjax($(modal.parent)); } else { modal.settings.success(); } }); $('body').off('click', this.cancelButton); $('body').on('click', this.cancelButton, function(){ modal.settings.cancel(); }); $('body').off('click', this.submitButton+','+this.cancelButton); $('body').on('click', this.submitButton+','+this.cancelButton, function(){ $(modal.holder).modal('hide'); }); }; this.setModal = function(){ if ($(this.holder).length == 0){ this.generateModal(); } else { this.updateModal(); } $(this.holder).modal('show'); }; this.generateModal = function(){ $('#modal-confirm').remove(); $('body').append('' ); }; this.updateModal = function() { $('.modal-confirm-label').text(this.settings.modalLabel); $('.modal-confirm-text').text(this.settings.modalBody); $('.modal-confirm-submit').text(this.settings.modalSubmit); $('.modal-confirm-cancel').text(this.settings.modalCancel); } }; // FLASH MESSAGES $(document).ready(function(){ $(document).ajaxComplete(function(event, xhr, settings) { var ajax_response = isJSON(xhr.responseText); if(ajax_response.redirectUrl) { window.location = ajax_response.redirectUrl; } else if(ajax_response.flashMessages) { setFlash(ajax_response.flashMessages); } }); // if trial bar is displayed, move main content 88px from top if ( $('#trial-info-box').length ) { $('body #wrap').css('padding-top', '88px'); } // same but for job editor page if ( $('body.job-editor #trial-info-box').length ) { $('body > .container-fluid.full-height').css('margin-top', '38px'); } // if there are some flash messages after page is loaded, slide'em down if ( $('.flash-messages .messages > div').length > 0 ) { setFlash($('.flash-messages .flash-alert')); }; }); function isJSON(data) { var isJson = false try { // this works with JSON string and JSON object, not sure about others var json = $.parseJSON(data); isJson = typeof json === 'object' ; if (isJson) { return json; } } catch (ex) { } return isJson; } function showDialog(message, icon) { $('#dialog-text').html(message); $('#dialog-icon').attr('class', icon); $('body > .dialog').removeClass('hide'); $('body').addClass('dialog-active'); } function hideDialog() { $('body').removeClass('dialog-active'); } function hideFlashMessage() { $('.flash-messages .alert').hide(300); } function showFlash(type, message) { var flashMessage = $('
').addClass('flash-alert'); if (type == 'info') { flashMessage.addClass('type-info'); flashMessage.append($('').addClass('icon-exclamation-sign fa-space')); flashMessage.data('type', 'info'); } else if (type == 'warning') { flashMessage.addClass('type-warning'); flashMessage.append($('').addClass('icon-warning-sign fa-space')); flashMessage.data('type', 'warning'); } else if (type == 'error') { flashMessage.addClass('type-error'); flashMessage.append($('').addClass('fa fa-times icon-remove-sign fa-space')); flashMessage.data('type', 'error'); } else { flashMessage.addClass('type-success'); flashMessage.append($('').addClass('icon-ok-sign fa-space')); flashMessage.data('type', 'success'); } flashMessage.append(message); setFlash(flashMessage); } function setFlash(flashMessage) { // find out type of result success / error / ... var type = $(flashMessage).data('type'); // remove all type-* classes $(".flash-messages-container").removeClass(function (index, css) { return (css.match (/(^|\s)type-\S+/g) || []).join(' '); }); // add class defined type of result success / error / ... $('.flash-messages-container').addClass('type-' + type); // hide messages $('.flash-messages .messages-container').hide(); // fill messages $('.flash-messages .messages-container .messages').html(flashMessage); // display messages $('.flash-messages .messages-container').delay(1000).slideDown(300, function () { //$('body > #wrap').addClass('flash-message-indent'); }); } function hideNewFlashMessage() { $('.flash-messages .messages-container').slideUp(100, function () { $('body > #wrap').removeClass('flash-message-indent'); }); } // FLASH MESSAGES END // MAIN FUNCTION function setAnalytics(type, subtype, positionId, expires) { var data = {}; if(type) { data.type = type; } if(subtype) { data.subtype = subtype; } if(positionId) { data.positionId = positionId; } if(!expires) { expires = 1; } $.ajax({ url: "/analytics/default/create", dataType: 'json', data: data, success: function(response) { if(response.status) { $.cookie("analytics", response.data.id, { expires : expires }); } } }); } function antiSpam(element) { $('.contentMessage').val($.now()); } function showAjaxLoader() { $('#ajax-loader').show(); } function hideAjaxLoader() { $('#ajax-loader').hide(); } function uniqueId(prefix) { var uniqueId = parseInt(Math.random() * 100000); if(prefix && prefix.length > 0) { uniqueId = prefix+'-'+uniqueId; } return uniqueId; } function debug(object) { console.log(object); } function nl2br (str, is_xhtml) { var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '
' : '
'; return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2'); } function addGaEvent(category, action, label, value) { ga('send', 'event', category, action, label, value); } function ajaxSwitchCheckbox(element) { $.ajax({ url: $(element).attr('data-href') }); } function closeAttachmentModal() { $('#attachment-modal').modal('hide'); } $(document).ready(function() { $(window).off('shown.bs.modal'); $(window).on('shown.bs.modal', function() { hideFlashMessage(); }); $('body').off('click', '.confirmLink'); $("body").on("initAfterLoad", function() { $('._content-tab a').off('click'); $.each($('.add-scroll-bar'), function() { var windowHeight = $(window).height(), topHeight = $(this).offset().top, maxHeight = windowHeight - topHeight - 72, elementHeight = $(this).height(); if($(this).data('default-height')) { var defaultMaxHeight = $(this).data('default-height'); if(defaultMaxHeight > maxHeight) { maxHeight = defaultMaxHeight; } } if(elementHeight > maxHeight) { $(this).css('max-height', maxHeight+'px'); $(this).addClass('scroll-bar'); } }); $.each($('.add-tooltip'), function(){ var options = {}; if($(this).data('delay')) { options.delay = $(this).data('delay'); } // uncomment if want let tooltip open after mouse leave for example for debugging //$("a").on('mouseleave', function (event) { // event.stopImmediatePropagation(); //}).tooltip(); $(this).tooltip(options); }); $('.email-content a').attr('target', '_blank'); $.each($('time'), function(){ var type = $(this).data('type'), format = $(this).data('format'), text = '', serverTime = moment.tz($(this).data('date'), "Europe/Vienna"), localTime = serverTime.clone().tz("America/Los_Angeles"); if(typeof $(this).data('text') != 'undefined') { text = $(this).data('text')+' '; } if(type == 'days') { text += serverTime.fromNow(); } else if(type == 'daysWithOutAgo') { text += serverTime.fromNow(true); } else if(type == 'calendar') { text += serverTime.calendar(); } else if(type == 'format' && typeof format != 'undefined') { text += serverTime.format(format); } else { text += serverTime.format(); } $(this).text(text); }); $.each($('.add-datepicker'), function(){ activateDatepicker($(this)); }); //$.each($('.rails'), function(){ // var right = $(this).find('.rail-right'), // content = $(this).find('.rail-content'), // left = $(this).find('.rail-left'), // biggest = content.height(); // // if(right.height() > content.height()) { // biggest = right.height(); // } // if(left.height() > biggest) { // biggest = left.height(); // } // // right.height(biggest); // content.height(biggest); // left.height(biggest); //}); $.each($('.add-a4-height'), function(){ if($(this).length > 0) { $(this).height($(this).width()*1.4); } }); $.each($('.add-popover'), function(){ $(this).popover(); }); $('body').on('click', '.add-popover', function(e){ e.preventDefault(); }); $('body').off('keyup focus', '.autogrow'); $('body').on('keyup focus', '.autogrow', function(e){ $(this).autoGrow({ extraLine: typeof $(this).data('extra-line') != 'undefined' ? $(this).data('extra-line') : true }); }); $.each($('.add-table-sort'), function(){ var config = { searching: typeof $(this).data('table-sort-searching') != 'undefined' ? $(this).data('table-sort-searching') : false, paging: typeof $(this).data('table-sort-paging') != 'undefined' ? $(this).data('table-sort-paging') : false, info: typeof $(this).data('table-sort-info') != 'undefined' ? $(this).data('table-sort-info') : false, order: typeof $(this).data('table-sort') != 'undefined' ? [[$(this).data('table-sort').split('|')[0], $(this).data('table-sort').split('|')[1]]] : [[0,'asc']], deferRender: true }; if(typeof $(this).data('table-dom') != 'undefined') { config.dom = $(this).data('table-dom'); } $(this).DataTable(config); }); }); $("body").trigger("initAfterLoad"); $('body').off('click', '._show-table button'); $('body').on('click', '._show-table button', function (e) { e.preventDefault(); $(this).parents('._show-table').prev('table').find('.hide').removeClass('hide'); $(this).parents('._show-table').hide(); }); $('body').off('click', '.open-modal'); $('body').on('click', '.open-modal', function(e){ e.preventDefault(); var element = $(this).data('modal'), model = $(this).data('model'), form = $(element).find('form'); $('.modal').modal('hide'); if(form) { var data = $(this).data(); for(var key in data) { if(data.hasOwnProperty(key) && key.match("^input_")) { var name_of_input = ''; $.each(key.replace('input_', '').split('_'), function(index, value){ if(index == 0) { if(typeof model != 'undefined') { name_of_input = model+"["+value+"]"; } else { name_of_input = value; } } else { name_of_input += "["+value+"]"; } }); var element_of_input = form.find( "[name='"+name_of_input+"']"); if(element_of_input) { if(element_of_input.is(':checkbox')) { element_of_input.prop('checked', $(this).data(key)); } else { element_of_input.val($(this).data(key)); } } } } } $(element) .modal('show') .on('shown.bs.modal', function (e) { $('body').addClass('modal-open'); $(element).find('input, .form-control').get(0).focus(); }); }); $('body').off('click', '.confirmLink'); $('body').on('click', '.confirmLink', function(e){ e.preventDefault(); var url = $(this).attr('href'), confirmModel = new ConfirmModal(this); confirmModel.init({ modalLabel: $(confirmModel.parent).data('confirm-label'), modalBody: $(confirmModel.parent).data('confirm'), modalSubmit: $(confirmModel.parent).data('confirm-submit'), modalCancel: $(confirmModel.parent).data('confirm-cancel'), redirectUrl: url, success: function(){ if (confirmModel.settings.redirectUrl != ''){ window.location = confirmModel.settings.redirectUrl; } } }); }); $('body').on('keypress keydown keyup', '.no-submit-by-enter input, .no-submit-by-enter textarea, .no-submit-by-enter select', function(e){ if(e.keyCode == 13) { e.preventDefault(); return false; } }); $('body').off('click', '.checkall, #checkAllAuto'); $('body').on('click', '.checkall, #checkAllAuto', function (e) { if($(this).attr('id') == 'checkAllAuto') { $('.checkall').prop('checked', $(this).is(':checked')); } if($(".checkall:checked").length > 1) { $('.reply-icon').addClass('fa-mail-reply-all'); $('.reply-icon').removeClass('fa-mail-reply'); } else { $('.reply-icon').removeClass('fa-mail-reply-all'); $('.reply-icon').addClass('fa-mail-reply'); } }); if ((location.hash)) { $('.tab-switch a[href="'+location.hash+'"]').tab('show'); } $('body').off('click', '.tab-switch a'); $('body').on('click', '.tab-switch a', function (e) { e.preventDefault(); if($(this).hasClass('disabled')) { return false; } var href = $(this).attr('href'); $(this).tab('show'); $(".tab-switch li").removeClass('active'); $(".tab-switch a[href='"+href+"']").parents('li').addClass('active'); history.pushState(null, '', 'http://'+window.location.hostname + window.location.pathname+$(this).attr('href')); }); $('body').off("change", '.submit-on-change'); $('body').on('change', '.submit-on-change', function(e) { if($(this).is("form")) { $(this).submit(); } else { this.form.submit(); } if($(this).hasClass('spin-on-submit')) { var element = $(this).find('.btn-spin'), spinElement = $("").addClass('fa fa-circle-o-notch fa-spin'), text = 'loading ...'; if(element) { if(element.data('spin-text')) { text = element.data('spin-text'); } element.html(spinElement); element.append(" "+text); } } }); $('body').off('click', '.btn-spin'); $('body').on('click', '.btn-spin', function(e){ $(this).text($("").addClass('fa fa-circle-o-notch fa-spin')); }); $('body').off("click", '.fb-popup'); $('body').on('click', '.fb-popup', function(e){ e.preventDefault(); var url = $(this).attr('data-url'); if(url.length > 0 && url != '#') { FB.ui( { method: 'feed', link: url }, function(response) { if (response && response.post_id) { window.scrollTo(0,document.body.scrollHeight); } else { window.scrollTo(0,document.body.scrollHeight); } } ); } }); $('body').off("keydown", ''); $('body').on("keydown", '', function(e) { if(e.keyCode == 27) { closeAttachmentModal(); } }); $('body').off('click', '.pdf-open-btn'); $('body').on('click', '.pdf-open-btn', function (e) { e.preventDefault(); var file = $(this).attr('data-url'), height = $(window).height(), url = "/services/pdf-js/1.4.0/web/viewer.html?file="+file; $('.type-box').hide(); $('.pdf-type').show(); $('.pdf-holder').attr('height', height+'px'); $('.pdf-holder').attr('src', url); $('#attachment-modal').modal('show'); }); $('body').off('click', '.img-open-btn'); $('body').on('click', '.img-open-btn', function (e) { e.preventDefault(); var file = $(this).attr('data-url'), height = $(window).height(), width = $('#attachment-modal .container').width(); $('.type-box').hide(); $('.img-type ').show(); $('.img-holder').attr('src', file); $('.img-over-holder').css('height', height+'px'); $('.img-over-holder p img').css('max-height', (height-100)+'px'); $('.img-over-holder p').css('width', width+'px'); $('#attachment-modal').modal('show'); }); $('body').off('click', '.type-box'); $('body').on('click', '.type-box', function (e) { e.preventDefault(); if(!$(e.target).is('img')) { $('#attachment-modal').modal('hide'); } }); }); // MAIN FUNCTION // CANDIDATE FUNCTION function getCandidateIds() { var data = [] var source = $('.checkall:checked'); if (source.length > 0) { $.each(source, function () { data.push($(this).attr("data-candidate-id")); }); } if (data.length == 0) { showFlash("info", " No candidate has been selected. "); return false; } else { return data; } } // END CANDIDATE FUNCTION // TASK LIST FUNCTIONS function getTaskIds() { var data = [] var source = $('.checkall:checked'); if (source.length > 0) { $.each(source, function () { data.push($(this).attr("data-task-id")); }); } if (data.length == 0) { showFlash("info", " No tasks has been selected. "); return false; } else { return data; } } // END TASK LIST FUNCTIONS /** * Function creates url from array like php function http_build_query * * @param baseUrl * @param params - key => value * @returns {string} */ function buildUrl(baseUrl, params) { var url = $.url(baseUrl), urlParams = $.url(baseUrl).param(); return url.attr('path') + '?' + $.param($.extend(urlParams, params)); } function buildUrlQuery(obj, num_prefix, temp_key) { var output_string = []; Object.keys(obj).forEach(function (val) { var key = val; num_prefix && !isNaN(key) ? key = num_prefix + key : ''; var key = encodeURIComponent(key.replace(/[!'()*]/g, escape)); temp_key ? key = temp_key + '[' + key + ']' : ''; if (typeof obj[val] === 'object') { var query = buildUrlQuery(obj[val], null, key); output_string.push(query); } else { var value = encodeURIComponent(obj[val].replace(/[!'()*]/g, escape)); output_string.push(key + '=' + value); } }); return output_string.join('&') } /** * Function send ajax call to set content visibility settings */ function visibilitySettings() { $('body').off('click', '._set-visibility'); $('body').on('click', '._set-visibility', function (e) { e.preventDefault(); // clicked element var el = this; var id = $(this).data('id'); var type = $(this).data('type'); var option = $(this).data('option'); $.ajax({ type: 'GET', url: '/app/api/setVisibility', dataType: 'json', data: {id: id, type: type, option: option} }).done(function (result) { reloadContent(el); }); }); } function activateDatepicker(element) { var options = { firstDay: 1, beforeShow: function() { setTimeout(function(){ $('.ui-datepicker').css('z-index', 1987); }, 0); } }; if(element.data('format')) { options.dateFormat = element.data('format'); } if(element.data('format-time')) { options.timeFormat = element.data('format-time'); } if(typeof element.data('min-date') != 'undefined') { options.minDate = element.data('min-date'); } element.datepicker(options); element.css('z-index', 1000); // if no data dont setDate if ( element.val() !== '' ) { element.datepicker("setDate", new Date(element.val())); } } $.detectChromeExtension = function(extensionId, accesibleResource, callback){ if (typeof(chrome) !== 'undefined'){ var testUrl = 'chrome-extension://' +extensionId +'/' +accesibleResource; $.ajax({ url: testUrl, timeout: 1000, type: 'HEAD', success: function(){ if (typeof(callback) == 'function') callback.call(this, true); }, error: function(){ if (typeof(callback) == 'function') callback.call(this, false); } }); } else { if (typeof(callback) == 'function') callback.call(this, false); } };