(function($) { /* Tab session */ if(!config.tabSession) return; /** Store current tab id */ var _tid = ''; /** * Get current tab id * @returns {string} Tab id */ function getTid(){return _tid;} /** * Convert url with tab id * @param {string} url * @param {string} [tid] * @param {boolean} [force] * @returns {string} Tab id */ function convertUrlWithTid(url, tid, force) { var link = $.parseLink(url); if(!link.moduleName) return url; tid = tid || _tid; if(!force && link.tid === tid) return url; link.tid = tid; return $.createLink(link); } /** Init */ function init() { /* Check tid */ if(window.parent !== window) { if(window.parent.$.tabSession) _tid = window.parent.$.tabSession.getTid(); } else { var isIndexOrLoginPage = (config.currentModule === 'index' && config.currentMethod === 'index') || (config.currentModule === 'user' && config.currentMethod === 'login'); var link = $.parseLink(window.location.href); _tid = sessionStorage.getItem('TID'); if(!_tid) { if(link.tid && isIndexOrLoginPage) { _tid = link.tid } if(!_tid) { _tid = $.zui.uuid(); _tid = _tid.substr(_tid.length - 8); } } sessionStorage.setItem('TID', _tid); if(isIndexOrLoginPage && !link.tid) { window.location.href = convertUrlWithTid(window.location.href, _tid); } } $.tabSession = { getTid: getTid, convertUrlWithTid: convertUrlWithTid, }; /* Handle all links in page */ $('a').each(function() { var $a = $(this); var url = $a.attr('href'); var urlWithTid = convertUrlWithTid(url); if(urlWithTid !== url) $a.attr('href', urlWithTid); }); $('[data-url]').each(function() { var $e = $(this); var url = $e.attr('data-url'); var urlWithTid = convertUrlWithTid(url); if(urlWithTid !== url) $e.attr('data-url', urlWithTid); }); if(config.debug > 2) { $(function() { $('#tid').prepend('localtid=' + _tid + ''); }); } } init(); /* Hide context menu when window is scroll. */ $(window).on('scroll', function() { $.zui.ContextMenu.hide(); }); }(jQuery)); /** * Set the ping url. * * @access public * @return void */ function setPing() { $('#hiddenwin').attr('src', createLink('misc', 'ping')); } /** * Disable the submit button when submit form. * * @access public * @return void */ function setForm() { var formClicked = false; $('form').submit(function() { submitObj = $(this).find(':submit'); if($(submitObj).size() >= 1) { var isBtn = submitObj.prop('tagName') == "BUTTON"; submitLabel = isBtn ? $(submitObj).html() : $(submitObj).attr('value'); $(submitObj).attr('disabled', 'disabled'); var submitting = submitObj.attr('data-submitting') || lang.submitting; if(isBtn) submitObj.text(submitting); else $(submitObj).attr('value', submitting); formClicked = true; } }); $("body").click(function() { if(formClicked) { $(submitObj).removeAttr('disabled'); if(submitObj.prop('tagName') == "BUTTON") { submitObj.text(submitLabel); } else { $(submitObj).attr('value', submitLabel); } $(submitObj).removeClass('button-d'); } formClicked = false; }); } /** * Set form action and submit. * * @param url $actionLink * @param string $hiddenwin 'hiddenwin' * @access public * @return void */ function setFormAction(actionLink, hiddenwin, obj) { $form = typeof(obj) == 'undefined' ? $('form') : $(obj).closest('form'); if(hiddenwin) $form.attr('target', hiddenwin); else $form.removeAttr('target'); $form.attr('action', actionLink); // Check safari for bug #1000, see http://pms.zentao.net/bug-view-1000.html var userAgent = navigator.userAgent; var isSafari = userAgent.indexOf('AppleWebKit') > -1 && userAgent.indexOf('Safari') > -1 && userAgent.indexOf('Chrome') < 0; if(isSafari) { var idPreffix = 'checkbox-fix-' + $.zui.uuid(); $form.find('[data-fix-checkbox]').remove(); $form.find('input[type="checkbox"]:not(.rows-selector)').each(function() { var $checkbox = $(this); var checkboxId = idPreffix + $checkbox.val(); $checkbox.clone().attr('data-fix-checkbox', checkboxId).css('display', 'none').after('
').appendTo($form); }); } $form.submit(); } /** * Set the max with of image. * * @access public * @return void */ function setImageSize(image, maxWidth, maxHeight) { var $image = $(image); if($image.parent().prop('tagName').toLowerCase() == 'a') return; /* If not set maxWidth, set it auto. */ if(!maxWidth) { bodyWidth = $('body').width(); maxWidth = bodyWidth - 470; // The side bar's width is 336, and add some margins. } if(!maxHeight) maxHeight = $(top.window).height(); setTimeout(function() { maxHeightStyle = $image.height() > 0 ? 'max-height:' + maxHeight + 'px' : ''; if(!document.getElementsByClassName('xxc-embed').length && $image.width() > 0 && $image.width() > maxWidth) $image.attr('width', maxWidth); $image.wrap(''); if($image.height() > 0 && $image.height() > maxHeight) $image.closest('a').append("" + lang.expand + " "); }, 50); } /** * Show more image when image is too height. * * @param obj $obj * @access public * @return void */ function showMoreImage(obj) { $(obj).parents('a').css('max-height', 'none'); $(obj).remove(); } /** * add one option of a select to another select. * * @param string $SelectID * @param string $TargetID * @access public * @return void */ function addItem(SelectID,TargetID) { ItemList = document.getElementById(SelectID); Target = document.getElementById(TargetID); for(var x = 0; x < ItemList.length; x++) { var opt = ItemList.options[x]; if (opt.selected) { flag = true; for (var y=0;y=0;x--) { var opt = ItemList.options[x]; if (opt.selected) { ItemList.options[x] = null; } } } /** * move one selected option up from a select. * * @param string $SelectID * @access public * @return void */ function upItem(SelectID) { ItemList = document.getElementById(SelectID); for(var x=1;x=0;x--) { var opt = ItemList.options[x]; opt.selected = true; } } /** * Delete item use ajax. * * @param string url * @param string replaceID * @param string notice * @access public * @return void */ function ajaxDelete(url, replaceID, notice) { if(confirm(notice)) { $.ajax( { type: 'GET', url: url, dataType: 'json', success: function(data) { if(data.result == 'success') { var $table = $('#' + replaceID).closest('[data-ride="table"]'); if($table.length) { var table = $table.data('zui.table'); if(table) { table.options.replaceId = replaceID; return table.reload(); } } $.get(document.location.href, function(data) { if(!($(data).find('#' + replaceID).length)) location.reload(); $('#' + replaceID).html($(data).find('#' + replaceID).html()); if(typeof sortTable == 'function') sortTable(); $('#' + replaceID).find('[data-toggle=modal], a.iframe').modalTrigger(); if($('#' + replaceID).find('table.datatable').length) $('#' + replaceID).find('table.datatable').datatable(); $('.table-footer [data-ride=pager]').pager(); }); } else if(data.result == 'fail' && typeof(data.message) == 'string') { bootbox.alert(data.message); } } }); } } /** * Judge the string is a integer number * * @access public * @return bool */ function isNum(s) { if(s!=null) { var r, re; re = /\d*/i; r = s.match(re); return (r == s) ? true : false; } return false; } /** * Start cron. * * @access public * @return void */ function startCron(restart) { if(typeof(restart) == 'undefined') restart = 0; $.ajax({type:"GET", timeout:100, url:createLink('cron', 'ajaxExec', 'restart=' + restart)}); } function computePasswordStrength(password) { if(password.length == 0) return 0; var strength = 0; var length = password.length; var complexity = new Array(); for(i = 0; i < length; i++) { letter = password.charAt(i); var asc = letter.charCodeAt(); if(asc >= 48 && asc <= 57) { complexity[0] = 1; } else if((asc >= 65 && asc <= 90)) { complexity[1] = 2; } else if(asc >= 97 && asc <= 122) { complexity[2] = 4; } else { complexity[3] = 8; } } var sumComplexity = 0; for(i in complexity) sumComplexity += complexity[i]; if((sumComplexity == 7 || sumComplexity == 15) && password.length >= 6) strength = 1; if(sumComplexity == 15 && password.length >= 10) strength = 2; return strength; } /** * Check onlybody page when it is not open in modal then location to on onlybody page. * * @access public * @return void */ function checkOnlybodyPage() { if(self == parent) { href = location.href.replace('?onlybody=yes', ''); location.href = href.replace('&onlybody=yes', ''); } } /** * Fixed table head in list when scrolling. * * @param string $tableID * @access public * @return void */ function fixedTheadOfList(tableID) { if($(tableID).size() == 0) return false; if($(tableID).css('display') == 'none') return false; if($(tableID).find('thead').size() == 0) return false; fixTheadInit(); $(window).scroll(fixThead);//Fix table head when scrolling. $('.side-handle').click(function(){setTimeout(fixTheadInit, 300);});//Fix table head if module tree is hidden or displayed. var tableWidth, theadOffset, fixedThead, $fixedThead; function fixThead() { theadOffset = $(tableID).find('thead').offset().top; $fixedThead = $(tableID).parent().find('.fixedTheadOfList'); if($fixedThead.size() <= 0 &&theadOffset < $(window).scrollTop()) { tableWidth = $(tableID).width(); fixedThead = "" + $(tableID).find('thead').html() + '
'; $(tableID).before(fixedThead); $('.fixedTheadOfList').addClass($(tableID).attr('class')).width(tableWidth); } if($fixedThead.size() > 0 && theadOffset >= $(window).scrollTop()) $fixedThead.remove(); } function fixTheadInit() { $fixedThead = $(tableID).parent().find('.fixedTheadOfList'); if($fixedThead.size() > 0) $fixedThead.remove(); fixThead(); } } /** * Apply cs style to page * @return void */ function applyCssStyle(css, tag) { tag = tag || 'default'; var name = 'applyStyle-' + tag; var $style = $('style#' + name); if(!$style.length) { $style = $('