PageRenderTime 43ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/public_html/clfc/wp-content/plugins/wpmudev-updates/includes/js/dashboard.js

https://gitlab.com/Henaway/CLFC
JavaScript | 380 lines | 320 code | 42 blank | 18 comment | 45 complexity | 8e69c90d949d3616a61cf5925d6c3a3a MD5 | raw file
  1. jQuery(function($) { // DOM READY WRAPPER
  2. wpmudev.init();
  3. $('.main-community-topics ul li:first p a span.ui-hide-triangle').addClass('ui-show-triangle');
  4. // if clicked outside updatesPanel when it's expanded, collapse it
  5. $('html').on('click', function() {
  6. wpmudev.updatesPanel.hide();
  7. });
  8. // updatesPanes show / hide button handler
  9. $('a.updates-fold').on('click', function(e) {
  10. e.stopPropagation();
  11. e.preventDefault();
  12. ($('#updates-data').hasClass('updates-data-active')) ? wpmudev.updatesPanel.hide() : wpmudev.updatesPanel.show();
  13. });
  14. // ONLY ACTIVATE SUGGESTIVE SEARCH IF PLACAHOLDER VARS ARE DEFINED
  15. if ((typeof suggestedProjects) !== 'undefined') {
  16. $('#suggestive-dash-search')
  17. .attr("data-search", "plugin")
  18. .doubleSuggest({
  19. localSource : suggestedProjects,
  20. remoteSource : false,
  21. selectValue : "name",
  22. seekValue : "name",
  23. minChars : 2,
  24. onSelect: function (data) {
  25. if ("id" in data && "type" in data) {
  26. var url = window.location.pathname + '?page=wpmudev-' + data.type + 's#pid=' + data.id;
  27. window.location = url;
  28. } else if ("type" in data) $('#suggestive-dash-search').attr("data-search", data.type);
  29. },
  30. resultsComplete: function () {
  31. // Hide results if nothing to show
  32. if (!$(".ds-result-item").length) $("#ds-results-suggestive-dash-search").hide();
  33. else $("#ds-results-suggestive-dash-search").show();
  34. }
  35. })
  36. .on('keydown', function (e) {
  37. if (9 == e.keyCode || 39 == e.keyCode) {
  38. var $el = $(".ds-result-item:first");
  39. if ($el.length) {
  40. var data = $el.data();
  41. if ("type" in data) $('#suggestive-dash-search').attr("data-search", data.type);
  42. $("#suggestive-dash-search").val($el.text());
  43. return false;
  44. }
  45. } else if (13 == e.keyCode) {
  46. $("#project-search-go").click();
  47. }
  48. });
  49. }
  50. //handle forum search box
  51. $('#forum-search-go').click(function() {
  52. var searchUrl = 'http://premium.wpmudev.org/forums/search.php?q=' + $('#forum-search-q').val();
  53. window.open(searchUrl, '_blank');
  54. return false;
  55. });
  56. //catch the enter key
  57. $('#forum-search-q').keypress(function(e) {
  58. if(e.which == 13) {
  59. $(this).blur();
  60. $('#forum-search-go').focus().click();
  61. }
  62. });
  63. // Handle project search box
  64. $("#project-search-go").click(function () {
  65. var tmp = window.location;
  66. var scope = ("theme" == $('#suggestive-dash-search').attr("data-search")) ? '?page=wpmudev-themes' : '?page=wpmudev-plugins';
  67. tmp.hash = "#search=" + $("#suggestive-dash-search").val();
  68. tmp.search = scope || '?page=wpmudev-plugins';
  69. window.location = tmp;
  70. });
  71. // DASHBOARD API-KEY FORMS, handlers to toggle between 'create acc' & 'log-in'
  72. if ($('body').hasClass('toplevel_page_wpmudev')) {
  73. $('#already-member').on('click', function(){
  74. $('#api-signup').slideUp(600);
  75. $('#api-login').slideDown(750);
  76. return false;
  77. });
  78. $('#not-member').on('click', function(){
  79. $('#api-login').slideUp(600);
  80. $('#api-signup').slideDown(750);
  81. return false;
  82. });
  83. }
  84. // js fix to fill out height of #wpcontent (so that we don't get white background)
  85. function processHeight() {
  86. var browserHeight = document.body.offsetHeight,
  87. wpcontent = document.getElementById('wpcontent'),
  88. wpcontentHeight = wpcontent.offsetHeight;
  89. if ( wpcontentHeight < browserHeight ) {
  90. wpcontent.style.height = browserHeight + 'px';
  91. }
  92. }
  93. $('.layer').height($('.premium-content').height());
  94. processHeight();
  95. window.onresize = function(){
  96. processHeight();
  97. }
  98. // <button class="cta" data-href="..." /> clicks
  99. $("button.wpmu-button[data-href]").on("click", function () {
  100. var href = $(this).attr("data-href");
  101. if (href) window.location = href;
  102. return false;
  103. });
  104. }); // END OF DOM WRAPPER
  105. /* ===========================
  106. FUNCTION DECLARATIONS BELOW
  107. */
  108. var wpmudev = {
  109. tooltip: function(selector) {
  110. var tips = selector,
  111. tipsl = tips.length,
  112. i;
  113. for (i = 0; i < tipsl; i++) {
  114. jQuery(tips[i]).on('mouseenter mouseleave', function() {
  115. jQuery(this).has('section').toggleClass('tooltipHover');
  116. });
  117. }
  118. },
  119. expandOnHover: function(tableSelector) {
  120. var arg = arguments,
  121. l = arg.length,
  122. i = 0;
  123. for (i; i < l; i++) {
  124. var $parent = jQuery(arg[i]);
  125. $parent
  126. .on('mouseenter', 'tr:not(.hiddenrow)', function() {
  127. var $this = jQuery(this),
  128. w = $this.width(),
  129. h = $this.height()
  130. ;
  131. $parent.find(".reason").css("display", "none");
  132. $this.next().find('div.reason').css({
  133. 'top' : -1,
  134. 'left' : 0,
  135. 'width' : w,
  136. 'display' : 'block'
  137. });
  138. })
  139. .on('mouseleave', 'tr.hiddenrow', function() {
  140. jQuery(this).find('div.reason').css('display', 'none');
  141. })
  142. ;
  143. }
  144. },
  145. // need to fall-back on jQuery based animation if no CSS3 transition
  146. updatesPanel: {
  147. hide: function() {
  148. jQuery('#updates-data').removeClass('updates-data-active');
  149. jQuery('.overlay').animate({
  150. 'opacity': '0.1'
  151. }, 500, function() {
  152. jQuery('.overlay').css('display', 'none')
  153. });
  154. jQuery('a.updates-fold').html('<span class="symbol">{</span>&nbsp;&nbsp;&nbsp;show');
  155. },
  156. show: function() {
  157. jQuery('#updates-data').addClass('updates-data-active');
  158. jQuery('.overlay').css('display', 'block').animate({
  159. 'opacity': '0.8'
  160. }, 700);
  161. jQuery('a.updates-fold').html('<span class="symbol">}</span>&nbsp;&nbsp;hide');
  162. },
  163. init: function() {
  164. var that = wpmudev.updatesPanel;
  165. jQuery('#updates-data').on('click', function(e) {
  166. e.preventDefault();
  167. e.stopPropagation();
  168. that.show();
  169. });
  170. }
  171. },
  172. collapsableElements: function() {
  173. jQuery('.accordion-title p').on('click', function(e) {
  174. e.preventDefault();
  175. e.stopPropagation();
  176. var $_txtSpan = jQuery(this).find('span.ui-hide-triangle').prev(),
  177. $_triangle = jQuery(this).find('span.ui-hide-triangle'),
  178. $_content = jQuery(this).parent().find('ul');
  179. function show() {
  180. $_txtSpan.text('HIDE');
  181. $_content.slideDown( 'fast','swing' );
  182. }
  183. function hide() {
  184. $_txtSpan.text('SHOW');
  185. $_content.slideUp( 'fast','swing' );
  186. }
  187. if($_txtSpan.length){
  188. //$_txtSpan.text() === 'SHOW' ? show() : hide();
  189. $_content.is(":visible") ? hide() : show();
  190. $_triangle.toggleClass('ui-show-triangle');
  191. }
  192. });
  193. },
  194. hoverToExpand: function() {
  195. jQuery('ul.hover-to-expand').on('mouseenter', 'li', function() {
  196. var $_productSearchField = jQuery('#suggestive-dash-search'),
  197. $_productSearchPanel = jQuery('div#ds-results-suggestive-dash-search');
  198. if($_productSearchPanel.filter(':visible').length || $_productSearchField.is(':focus')){
  199. } else {
  200. jQuery(this).find('div.expanded-content').css({
  201. 'opacity': '1',
  202. 'z-index': '3'
  203. }).animate({
  204. 'top': '-50%'
  205. }, 'fast').find('ul').slideDown('fast');
  206. }
  207. }).on('mouseleave', 'li', function() {
  208. jQuery(this).find('div.expanded-content').css('z-index', '1').animate({
  209. 'top': '0%'
  210. }, 'fast').find('ul').slideUp('fast', function() {
  211. jQuery(this).parent().css('opacity', '0');
  212. });
  213. });
  214. },
  215. // panelContainerHeight prop. containing returned elem height.
  216. // i might need it later on, for comparison
  217. panelContainerHeight : undefined,
  218. layoutCalculations: function() {
  219. var $_spacer = jQuery('.spacer'),
  220. $_base = jQuery('#dash-main-content').height(),
  221. $_gradient = jQuery('#right-section-gradient'),
  222. that = this;
  223. jQuery(window).load(function() {
  224. $_spacer.css( 'padding-bottom', ( 80 + $_base) );
  225. $_gradient.css( 'padding-bottom', ( 60 + $_base) );
  226. return (that.panelContainerHeight = $_base);
  227. });
  228. },
  229. validate: function (what, $src) {
  230. wpmudev.validation_pending($src);
  231. if (!$src.val()) return wpmudev.clear_validation($src);
  232. return jQuery.post(ajaxurl, {
  233. "action": "wpmudev_validate_" + what,
  234. "value": $src.val(),
  235. }, function (data) {
  236. if ("status" in data && parseInt(data.status) == 0) return wpmudev.validation_ok($src);
  237. wpmudev.validation_failure(data.message, $src);
  238. }, 'json');
  239. },
  240. validate_first_name: function () {
  241. var $fn = jQuery("#first_name"),
  242. valid = !!($fn.length && $fn.val && $fn.val() && $fn.val().length),
  243. msg = ($fn.length ? $fn.attr("data-default_error") : '')
  244. ;
  245. return valid
  246. ? wpmudev.validation_ok($fn)
  247. : wpmudev.validation_failure(msg, $fn)
  248. ;
  249. },
  250. validate_email: function () { wpmudev.validate("email", jQuery("#email_addr")); },
  251. validate_password: function () { wpmudev.validate("password", jQuery("#password")); },
  252. validation_ok: function ($el) {
  253. var $validation = $el.nextAll(".validation");
  254. if (!$validation.length) return false;
  255. $validation
  256. .removeClass("error")
  257. .addClass("ok")
  258. .html('<span class="icon-ok"></span>')
  259. .show()
  260. ;
  261. },
  262. validation_failure: function (text, $el) {
  263. var $validation = $el.nextAll(".validation");
  264. if (!$validation.length) return false;
  265. $validation
  266. .removeClass("ok")
  267. .addClass("error")
  268. .html('<span class="icon-remove-sign"></span>' + text)
  269. .show()
  270. ;
  271. },
  272. validation_pending: function ($el) {
  273. wpmudev.clear_validation();
  274. var $validation = $el.nextAll(".validation");
  275. $validation
  276. .html('Waiting...')
  277. .show()
  278. ;
  279. },
  280. clear_validation: function ($el) {
  281. $el = $el && $el.nextAll ? $el : jQuery(this);
  282. var $validation = $el.nextAll(".validation");
  283. if (!$validation.length) return false;
  284. $validation
  285. .removeClass("error").removeClass("ok")
  286. .html('')
  287. .hide()
  288. ;
  289. },
  290. setup_validation: function () {
  291. jQuery(".validation").removeClass("error").hide();
  292. jQuery("#first_name")
  293. .on("blur", this.validate_first_name)
  294. .on("focus", this.clear_validation)
  295. ;
  296. jQuery("#email_addr")
  297. .on("blur", this.validate_email)
  298. .on("focus", this.clear_validation)
  299. ;
  300. jQuery("#password")
  301. .on("blur", this.validate_password)
  302. .on("focus", this.clear_validation)
  303. ;
  304. // Form submission validation
  305. jQuery("#api-signup").on("submit", function () {
  306. var safe_to_proceed = true; // Assume best case scenario
  307. var elements = [
  308. {"type": "first_name", "source": jQuery("#first_name")},
  309. {"type": "email", "source": jQuery("#email_addr")},
  310. {"type": "password", "source": jQuery("#password")}
  311. ];
  312. var promises = [];
  313. jQuery.each(elements, function () {
  314. var $validation = this.source.nextAll(".validation");
  315. if (!$validation.is(".ok")) {
  316. safe_to_proceed = false;
  317. if (!$validation.is(".error")) {
  318. var promise = wpmudev.validate(this.type, this.source);
  319. if ("object" == typeof promise) promises.push(promise);
  320. }
  321. }
  322. });
  323. if (promises.length) jQuery.when.apply(null, promises).done(function () {
  324. jQuery("#api-signup").submit();
  325. });
  326. return safe_to_proceed;
  327. });
  328. },
  329. init: function() {
  330. this.layoutCalculations();
  331. this.tooltip(jQuery('.tooltip'));
  332. this.expandOnHover('table.hoverExpand');
  333. this.updatesPanel.init();
  334. this.collapsableElements();
  335. this.hoverToExpand();
  336. this.setup_validation();
  337. }
  338. }; // end WPMU DEV obj