Advertisement
rimi1

Untitled

Mar 14th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. /*
  2. * Javascript file to selectively load the WPMUDEV Pop Up
  3. */
  4.  
  5. var po_adminajax = popover_selective_custom.admin_ajax_url;
  6.  
  7. // Enable us to get some cookie information - from http://stackoverflow.com/questions/5639346/shortest-function-for-reading-a-cookie-in-javascript
  8. function po_get_cookie(name) {
  9.  
  10. var nameEQ = name + "=";
  11. var ca = document.cookie.split(';');
  12. for (var i = 0; i < ca.length; i++) {
  13. var c = ca[i];
  14. while (c.charAt(0) == ' ')
  15. c = c.substring(1, c.length);
  16. if (c.indexOf(nameEQ) == 0)
  17. return c.substring(nameEQ.length, c.length);
  18. }
  19. return null;
  20. }
  21.  
  22. function po_createCookie(name, value, days) {
  23. if (days) {
  24. var date = new Date();
  25. date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
  26. var expires = "; expires=" + date.toGMTString();
  27. }
  28. else
  29. var expires = "";
  30. document.cookie = name + "=" + value + expires + "; path=/";
  31. }
  32.  
  33. function po_removeMessageBoxForever() {
  34. jQuery('#darkbackground').remove();
  35. jQuery(this).parents(popovername).remove();
  36. po_createCookie('popover_never_view', 'hidealways', 365);
  37. return false;
  38. }
  39.  
  40. function po_removeMessageBox() {
  41. jQuery('#darkbackground').remove();
  42. jQuery(this).parents(popovername).remove();
  43. return false;
  44. }
  45.  
  46. function po_loadMessageBox( ) {
  47.  
  48. // move the data back to the data variable, from mydata so we can use it without changing a chunk of code :)
  49. data = mydata;
  50.  
  51. if (data['html'] != '') {
  52. // Set the name for other functions to use
  53. popovername = '#' + data['name'];
  54.  
  55. jQuery('<style type="text/css">' + data['style'] + '</style>').appendTo('head');
  56. jQuery(data['html']).appendTo('body');
  57.  
  58. if (data['usejs'] == 'yes') {
  59.  
  60. jQuery('#' + data['name']).width(jQuery('#message').width());
  61. jQuery('#' + data['name']).height(jQuery('#message').height());
  62.  
  63. jQuery('#' + data['name']).css('top', (jQuery(window).height() / 2) - (jQuery('#message').height() / 2));
  64. jQuery('#' + data['name']).css('left', (jQuery(window).width() / 2) - (jQuery('#message').width() / 2));
  65. }
  66.  
  67. jQuery('#' + data['name']).css('visibility', 'visible');
  68. jQuery('#darkbackground').css('visibility', 'visible');
  69.  
  70. jQuery('#clearforever').click(po_removeMessageBoxForever);
  71. jQuery('#closebox').click(po_removeMessageBox);
  72.  
  73. jQuery('#message').hover(function() {
  74. jQuery('.claimbutton').removeClass('hide');
  75. }, function() {
  76. jQuery('.claimbutton').addClass('hide');
  77. });
  78. }
  79.  
  80. }
  81.  
  82. function po_onsuccess(data) {
  83. // set the data to be a global variable so we can grab it after the timeout
  84. mydata = data;
  85.  
  86. if (data['name'] != 'nopoover') {
  87. window.setTimeout(po_loadMessageBox, data['delay']);
  88. }
  89.  
  90. }
  91.  
  92. function po_load_popover() {
  93.  
  94. var theajax = po_adminajax;
  95. var thefrom = window.location;
  96. var thereferrer = document.referrer;
  97.  
  98. // Check if we are forcing a popover - if not then set it to a default value of 0
  99. if (typeof force_popover === 'undefined') {
  100. force_popover = 0;
  101. }
  102.  
  103. jQuery.ajax({
  104. url: theajax,
  105. dataType: 'jsonp',
  106. jsonpCallback: 'po_onsuccess',
  107. data: {action: 'popover_selective_ajax',
  108. thefrom: thefrom.toString(),
  109. thereferrer: thereferrer.toString(),
  110. active_popover: force_popover.toString()
  111. },
  112. success: function(data) {
  113.  
  114. }
  115. }
  116. );
  117.  
  118. return false;
  119. }
  120.  
  121. // The main function
  122. function po_selectiveLoad() {
  123. po_load_popover();
  124. }
  125.  
  126. // Call when the page is fully loaded
  127. jQuery(window).load(po_selectiveLoad);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement