PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/common-js.php

https://gitlab.com/wuhang2003/typecho
PHP | 105 lines | 86 code | 17 blank | 2 comment | 18 complexity | 5cc557b2f4f1cbf4edfe270b45ac03f3 MD5 | raw file
  1. <?php if(!defined('__TYPECHO_ADMIN__')) exit; ?>
  2. <script src="<?php $options->adminStaticUrl('js', 'jquery.js?v=' . $suffixVersion); ?>"></script>
  3. <script src="<?php $options->adminStaticUrl('js', 'jquery-ui.js?v=' . $suffixVersion); ?>"></script>
  4. <script src="<?php $options->adminStaticUrl('js', 'typecho.js?v=' . $suffixVersion); ?>"></script>
  5. <script>
  6. (function () {
  7. $(document).ready(function() {
  8. // 处理消息机制
  9. (function () {
  10. var prefix = '<?php echo Typecho_Cookie::getPrefix(); ?>',
  11. cookies = {
  12. notice : $.cookie(prefix + '__typecho_notice'),
  13. noticeType : $.cookie(prefix + '__typecho_notice_type'),
  14. highlight : $.cookie(prefix + '__typecho_notice_highlight')
  15. },
  16. path = '<?php echo Typecho_Cookie::getPath(); ?>';
  17. if (!!cookies.notice && 'success|notice|error'.indexOf(cookies.noticeType) >= 0) {
  18. var head = $('.typecho-head-nav'),
  19. p = $('<div class="message popup ' + cookies.noticeType + '">'
  20. + '<ul><li>' + $.parseJSON(cookies.notice).join('</li><li>')
  21. + '</li></ul></div>'), offset = 0;
  22. if (head.length > 0) {
  23. p.insertAfter(head);
  24. offset = head.outerHeight();
  25. } else {
  26. p.prependTo(document.body);
  27. }
  28. function checkScroll () {
  29. if ($(window).scrollTop() >= offset) {
  30. p.css({
  31. 'position' : 'fixed',
  32. 'top' : 0
  33. });
  34. } else {
  35. p.css({
  36. 'position' : 'absolute',
  37. 'top' : offset
  38. });
  39. }
  40. }
  41. $(window).scroll(function () {
  42. checkScroll();
  43. });
  44. checkScroll();
  45. p.slideDown(function () {
  46. var t = $(this), color = '#C6D880';
  47. if (t.hasClass('error')) {
  48. color = '#FBC2C4';
  49. } else if (t.hasClass('notice')) {
  50. color = '#FFD324';
  51. }
  52. t.effect('highlight', {color : color})
  53. .delay(5000).slideUp(function () {
  54. $(this).remove();
  55. });
  56. });
  57. $.cookie(prefix + '__typecho_notice', null, {path : path});
  58. $.cookie(prefix + '__typecho_notice_type', null, {path : path});
  59. }
  60. if (cookies.highlight) {
  61. $('#' + cookies.highlight).effect('highlight', 1000);
  62. $.cookie(prefix + '__typecho_notice_highlight', null, {path : path});
  63. }
  64. })();
  65. // 导航菜单 tab 聚焦时展开下拉菜单
  66. (function () {
  67. $('#typecho-nav-list').find('.parent a').focus(function() {
  68. $('#typecho-nav-list').find('.child').hide();
  69. $(this).parents('.root').find('.child').show();
  70. });
  71. $('.operate').find('a').focus(function() {
  72. $('#typecho-nav-list').find('.child').hide();
  73. });
  74. })();
  75. if ($('.typecho-login').length == 0) {
  76. $('a').each(function () {
  77. var t = $(this), href = t.attr('href');
  78. if ((href && href[0] == '#')
  79. || /^<?php echo preg_quote($options->adminUrl, '/'); ?>.*$/.exec(href)
  80. || /^<?php echo substr(preg_quote(Typecho_Common::url('s', $options->index), '/'), 0, -1); ?>action\/[_a-zA-Z0-9\/]+.*$/.exec(href)) {
  81. return;
  82. }
  83. t.attr('target', '_blank');
  84. });
  85. }
  86. });
  87. })();
  88. </script>