script.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. jQuery(function(){
  2. var $extmgr = jQuery('#extension__manager');
  3. /**
  4. * Confirm uninstalling
  5. */
  6. $extmgr.find('button.uninstall').on('click', function(e){
  7. if(!window.confirm(LANG.plugins.extension.reallydel)){
  8. e.preventDefault();
  9. return false;
  10. }
  11. return true;
  12. });
  13. /**
  14. * very simple lightbox
  15. * @link http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/super-simple-lightbox-with-css-and-jquery/
  16. */
  17. $extmgr.find('a.extension_screenshot').on('click', function(e) {
  18. e.preventDefault();
  19. //Get clicked link href
  20. var image_href = jQuery(this).attr("href");
  21. // create lightbox if needed
  22. var $lightbox = jQuery('#plugin__extensionlightbox');
  23. if(!$lightbox.length){
  24. $lightbox = jQuery('<div id="plugin__extensionlightbox"><p>Click to close</p><div></div></div>')
  25. .appendTo(jQuery('body'))
  26. .hide()
  27. .on('click', function(){
  28. $lightbox.hide();
  29. });
  30. }
  31. // fill and show it
  32. $lightbox
  33. .show()
  34. .find('div').html('<img src="' + image_href + '" />');
  35. return false;
  36. });
  37. /**
  38. * Enable/Disable extension via AJAX
  39. */
  40. $extmgr.find('button.disable, button.enable').on('click', function (e) {
  41. e.preventDefault();
  42. var $btn = jQuery(this);
  43. // get current state
  44. var extension = $btn.attr('name').split('[')[2];
  45. extension = extension.substr(0, extension.length - 1);
  46. var act = ($btn.hasClass('disable')) ? 'disable' : 'enable';
  47. // disable while we wait
  48. $btn.attr('disabled', 'disabled');
  49. $btn.css('cursor', 'wait');
  50. // execute
  51. jQuery.get(
  52. DOKU_BASE + 'lib/exe/ajax.php',
  53. {
  54. call: 'plugin_extension',
  55. ext: extension,
  56. act: act,
  57. sectok: $btn.parents('form').find('input[name=sectok]').val()
  58. },
  59. function (data) {
  60. $btn.css('cursor', '')
  61. .removeAttr('disabled')
  62. .removeClass('disable')
  63. .removeClass('enable')
  64. .text(data.label)
  65. .addClass(data.reverse)
  66. .parents('li')
  67. .removeClass('disabled')
  68. .removeClass('enabled')
  69. .addClass(data.state);
  70. }
  71. ).fail(function() {
  72. $btn.css('cursor', '')
  73. .removeAttr('disabled');
  74. });
  75. });
  76. /**
  77. * AJAX detail infos
  78. */
  79. $extmgr.find('a.info').on('click', function(e){
  80. e.preventDefault();
  81. var $link = jQuery(this);
  82. var $details = $link.parent().find('dl.details');
  83. if($details.length){
  84. $link.toggleClass('close');
  85. $details.toggle();
  86. return;
  87. }
  88. $link.addClass('close');
  89. jQuery.get(
  90. DOKU_BASE + 'lib/exe/ajax.php',
  91. {
  92. call: 'plugin_extension',
  93. ext: $link.data('extid'),
  94. act: 'info'
  95. },
  96. function(data){
  97. $link.parent().append(data);
  98. }
  99. );
  100. });
  101. /**
  102. Create section for enabling/disabling viewing options
  103. */
  104. if ( $extmgr.find('.plugins, .templates').hasClass('active') ) {
  105. var $extlist = jQuery('#extension__list');
  106. $extlist.addClass('hasDisplayOptions');
  107. var $displayOpts = jQuery('<p>', { id: 'extension__viewoptions'} ).appendTo($extmgr.find( '.panelHeader' ));
  108. $displayOpts.append(LANG.plugins.extension.display_viewoptions);
  109. var displayOptionsHandler = function(){
  110. $extlist.toggleClass( this.name );
  111. DokuCookie.setValue('ext_'+this.name, $extlist.hasClass(this.name) ? '1' : '0');
  112. };
  113. jQuery(['enabled', 'disabled', 'updatable']).each(function(index, chkName){
  114. var $label = jQuery( '<label></label>' )
  115. .appendTo($displayOpts);
  116. var $input = jQuery( '<input />', { type: 'checkbox', name: chkName })
  117. .on('change', displayOptionsHandler)
  118. .appendTo($label);
  119. var previous = DokuCookie.getValue('ext_'+chkName);
  120. if(typeof previous === "undefined" || previous == '1') {
  121. $input.trigger('click');
  122. }
  123. jQuery( '<span/>' )
  124. .append(' '+LANG.plugins.extension['display_'+chkName])
  125. .appendTo($label);
  126. });
  127. }
  128. });