Skip to content
Permalink
0b6cd7b04b
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
239 lines (208 sloc) 7.39 KB
<?php
/**
* COmanage Match jQuery onload JavaScript
* Applies jQuery widgets and flash messages
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/
?>
<script>
$(function() {
// Focus any designated form element
$('.focusFirst').focus();
// DESKTOP MENU DRAWER BEHAVIOR
// Check the drawer half-closed cookie on first load and set the drawer state appropriately
if (Cookies.get("desktop-drawer-state") == "half-closed") {
$("#navigation-drawer").addClass("half-closed");
$("#main").addClass("drawer-half-closed");
} else {
// Preserve the state of the most recently selected menu item if it is expandable (a "menuTop" item)
// (we only use this behavior when the the drawer is fully-open)
var mainMenuSelectedParentId = Cookies.get("main-menu-selected-parent-id");
if(mainMenuSelectedParentId != undefined && mainMenuSelectedParentId != "") {
$("#" + mainMenuSelectedParentId).addClass("active");
$("#" + mainMenuSelectedParentId + " > a.menuTop").attr("aria-expanded","true");
$("#" + mainMenuSelectedParentId + " > ul").addClass("in");
}
}
// Hamburger menu-drawer toggle
$('#co-hamburger').click(function () {
if($(window).width() < 768) {
// Mobile mode
$("#navigation-drawer").removeClass("half-closed").toggle();
} else {
// Desktop mode
if ($("#navigation-drawer").hasClass("half-closed")) {
$("#navigation-drawer").removeClass("half-closed");
$("#main").removeClass("drawer-half-closed");
// set a cookie to hold drawer half-open state between requests
Cookies.set("desktop-drawer-state", "open");
} else {
$("#navigation-drawer").addClass("half-closed");
$("#main").addClass("drawer-half-closed");
// ensure all the sub-menus collapse when half-closing the menu
$("#navigation .metismenu li ul").removeClass("in");
$("#navigation .metismenu li").removeClass("active");
// set a cookie to hold drawer half-open state between requests
Cookies.set("desktop-drawer-state", "half-closed");
}
}
});
// Catch the edge-case of browser resize causing menu-drawer
// to remain hidden and vice versa.
$(window).resize(function() {
if($( window ).width() > 767) {
$("#navigation-drawer").show();
} else {
$("#navigation-drawer").hide();
}
});
// Desktop half-closed drawer behavior & expandable menu items
$('#navigation-drawer a.menuTop').click(function () {
if (Cookies.get("desktop-drawer-state") == "half-closed") {
$("#navigation-drawer").toggleClass("half-closed");
}
// Save the ID of the most recently expanded menuTop item for use on reload
if ($(this).attr("aria-expanded") == "true") {
var parentId = $(this).parent().attr("id");
Cookies.set("main-menu-selected-parent-id", parentId);
} else {
Cookies.set("main-menu-selected-parent-id", "");
}
});
// END DESKTOP MENU DRAWER BEHAVIOR
// USER MENU BEHAVIORS
// Toggle the custom user panel in the user menu
$("#user-panel-toggle").click(function(e) {
e.stopPropagation();
if ($("#user-panel").is(":visible")) {
$("#user-panel").hide();
$("#user-panel").attr("aria-expanded","false");
} else {
$("#user-panel").show();
$("#user-panel").attr("aria-expanded","true");
}
});
// Hide custom user menu items on click outside
$(document).on('click', function (e) {
if ($(e.target).closest("#user-panel").length === 0) {
$("#user-panel").hide();
}
});
// Accordion
$(".accordion").accordion();
// Make all submit buttons pretty (Bootstrap)
$("input:submit").addClass("spin submit-button btn btn-primary");
// Make all select form controls Bootstrappy
$("select").addClass("form-control");
// Other buttons (jQuery)
$(".addbutton").button({
icons: {
primary: 'ui-icon-circle-plus'
},
text: true
});
$(".buildbutton").button({
icons: {
primary: 'ui-icon-gear'
},
text: true
});
$(".configurebutton").button({
icons: {
primary: 'ui-icon-pencil'
},
text: true
});
$(".copybutton").button({
icons: {
primary: 'ui-icon-copy'
},
text: true
});
$(".deletebutton").button({
icons: {
primary: 'ui-icon-circle-close'
},
text: true
});
$(".editbutton").button(
{ classes: {
"ui-button": "highlight"
},
icons: {
primary: 'ui-icon-pencil'
},
text: true
});
$(".linkbutton").button({
icons: {
primary: 'ui-icon-extlink'
},
text: true
});
$(".reconcilebutton").button({
icons: {
primary: 'ui-icon-transferthick-e-w'
},
text: true
});
// Dialog
// This generic dialog gets modified by the calling function
$("#dialog").dialog({
autoOpen: false,
resizable: false,
modal: true,
// XXX need to properly localize strings
buttons: {
'<?php print __('op.cancel'); ?>': function() {
$(this).dialog('close');
},
'<?php print __('op.ok'); ?>': function() {
$(this).dialog('close');
}
}
});
// Generic row click handling
$('.linked-row').click(function (e) {
location.href = $(this).find('a.row-link').attr('href');
});
// Add a spinner when a form is submitted or when any item is clicked with a "spin" class
$("input[type='submit'], .spin").click(function() {
var spinnerDiv = '<div id="coSpinner"></div>';
$("body").append(spinnerDiv);
var coSpinnerTarget = document.getElementById('coSpinner');
// coSpinnerOpts are set in js/comanage.js
var coSpinner = new Spinner(coSpinnerOpts).spin(coSpinnerTarget);
// Test for invalid fields (HTML5) and turn off spinner explicitly if found
if(document.querySelectorAll(":invalid").length) {
coSpinner.stop();
}
});
});
// Define default text for confirm dialog
var defaultConfirmOk = "<?php print __('op.ok'); ?>";
var defaultConfirmCancel = "<?php print __('op.cancel'); ?>";
var defaultConfirmTitle = "<?php print __('op.confirm'); ?>";
</script>
<?= $this->Flash->render() ?>