admin-dashboard-widget.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. function MiWidget() {
  2. var self = this,
  3. $ = window.jQuery,
  4. $widget_element = $( document.getElementById( 'monsterinsights_reports_widget' ) ),
  5. $widget_title = $widget_element.find( '.hndle' ),
  6. $widget_controls = $widget_element.find( '.mi-dw-controls' ),
  7. $normal_sortables = $( document.getElementById( 'normal-sortables' ) ),
  8. $welcome_panel = $( document.getElementById( 'welcome-panel' ) ),
  9. $lite_content = $widget_element.find( '.mi-dw-lite-content' );
  10. this.init = function () {
  11. // Stop loading early if MI is not authenticated.
  12. if ( ! this.is_authed() ) {
  13. return false;
  14. }
  15. this.add_widget_toggle();
  16. this.add_events();
  17. this.tooltips();
  18. };
  19. this.add_widget_toggle = function () {
  20. $widget_controls.appendTo( $widget_title );
  21. $widget_element.addClass( 'mi-loaded' );
  22. };
  23. this.add_events = function () {
  24. $widget_controls.on( 'click', 'label,button', function ( e ) {
  25. e.stopPropagation();
  26. self.shake_content();
  27. } );
  28. };
  29. this.shake_content = function ( el ) {
  30. $lite_content.addClass( 'mi-animation-shake' );
  31. setTimeout( function () {
  32. $lite_content.removeClass( 'mi-animation-shake' );
  33. }, 1000 );
  34. };
  35. this.is_authed = function () {
  36. return ! (
  37. $widget_element.find( '.mi-dw-not-authed' ).length > 0
  38. );
  39. };
  40. this.tooltips = function () {
  41. $( '.mi-dw-styled-toggle' ).tooltip( {
  42. tooltipClass: 'mi-dw-ui-tooltip',
  43. position: {my: 'center bottom-12', at: 'center top', collision: 'flipfit'},
  44. } );
  45. };
  46. this.init();
  47. }
  48. new MiWidget();