/** * ProcessWire Admin common javascript * * Copyright 2016 by Ryan Cramer * */ var ProcessWireAdmin = { /** * Initialize all * */ init: function() { this.setupButtonStates(); this.setupTooltips(); this.setupDropdowns(); this.setupNotices(); }, setupNotices: function() { $(".pw-notice-group-toggle").click(function() { var $parent = $(this).closest('.pw-notice-group-parent'); var $children = $parent.nextUntil('.pw-notice-group-parent'); if($parent.hasClass('pw-notice-group-open')) { $parent.removeClass('pw-notice-group-open'); $children.slideUp('fast'); } else { $parent.addClass('pw-notice-group-open'); $children.slideDown('fast'); } $parent.find('i[data-toggle]').each(function() { $(this).toggleClass($(this).attr('data-toggle')); }); return false; }); }, /** * Enable jQuery UI tooltips * */ setupTooltips: function() { $("a.tooltip, .pw-tooltip").tooltip({ position: { my: "center bottom", // bottom-20 at: "center top" } }).hover(function() { var $a = $(this); if($a.is('a')) { $a.addClass('ui-state-hover'); } else { $a.data('pw-tooltip-cursor', $a.css('cursor')); $a.css('cursor', 'pointer'); } $a.addClass('pw-tooltip-hover'); $a.css('cursor', 'pointer'); }, function() { var $a = $(this); $a.removeClass('pw-tooltip-hover ui-state-hover'); if(!$a.is('a')) { $a.css('cursor', $a.data('pw-tooltip-cursor')); } }); }, /** * Make buttons utilize the jQuery button state classes * */ setupButtonStates: function() { // jQuery UI button states $(document).on('mouseover', '.ui-button', function() { var $t = $(this); $t.removeClass("ui-state-default").addClass("ui-state-hover"); if($t.hasClass('ui-priority-secondary')) $t.toggleClass('xui-priority-secondary ui-priority-secondary'); if($t.hasClass('pw-button-dropdown-main')) { $t.siblings('#pw-dropdown-toggle-' + $t.attr('id')).trigger('mouseover'); } }).on('mouseout', '.ui-button', function() { var $t = $(this); $t.removeClass("ui-state-hover").addClass("ui-state-default"); if($t.hasClass('xui-priority-secondary')) $t.toggleClass('xui-priority-secondary ui-priority-secondary'); if($t.hasClass('pw-button-dropdown-main')) { $t.siblings('#pw-dropdown-toggle-' + $t.attr('id')).trigger('mouseout'); } }).on('click', '.ui-button', function() { $(this).removeClass("ui-state-default").addClass("ui-state-active"); // .effect('highlight', {}, 100); }); /* .on('click', 'a > button', function() { var $a = $(this).parent(); var target = $a.attr('target'); if(typeof target != "undefined" && target == '_blank') { // skip } else { // make buttons with tags click to the href of the window.location = $a.attr('href'); } }); */ }, /** * Setup dropdown menus * */ setupDropdowns: function() { // whether or not dropdown positions are currently being monitored var dropdownPositionsMonitored = false; var hoveredDropdownAjaxItem; function setupDropdown() { var $a = $(this); var $ul; if($a.attr('data-pw-dropdown')) { // see if it is specifying a certain