(function( document, jquery ) { 'use strict'; var newLink = document.createElement('link'), links = document.getElementsByTagName('link')[0]; newLink.rel = "stylesheet"; newLink.href = "//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" links.parentNode.insertBefore(newLink,links); /** * Shambhala Plus dialog toggler */ var spDialog = document.getElementById('shambhala-plus-dialog'), spDialogForms = document.querySelectorAll('.shambhala-plus-email-form'), spDialogClosers = spDialog.querySelectorAll('.shambhala-plus-dialog-closer'), spDialogTriggers = document.querySelectorAll('.shambhala-plus-dialog-trigger'); var notifier = document.getElementById('shambhala-plus-dialog-message'); if ( spDialogClosers ) { attachListener(spDialogClosers, 'click', function() { event.preventDefault(); var panelForm= document.getElementById('form-panel'); if ( panelForm ) { setActive(panelForm); resetSignupForm(); } spDialog.classList.remove( 'shambhala-plus-dialog-open' ); }); } if ( spDialogTriggers ) { attachListener(spDialogTriggers, 'click', function(event) { event.preventDefault(); spDialog.classList.add( 'shambhala-plus-dialog-open' ); }); } if ( spDialogForms ) { attachListener(spDialogForms, 'submit', function(event) { event.preventDefault(); //var ajaxurl = 'http://wordpress.localhost/wp-admin/admin-ajax.php'; var data = { 'action': 'api', 'endpoint': this.endpoint.value, 'verb': this.verb.value, 'first_name': this.firstname.value, 'last_name': this.lastname.value, 'email': this.email.value }; jquery.post( shambhalaPlus.ajaxUrl, data, function( result ) { var response = JSON.parse(result); if ('success'==response.status) { var panelConfirm= document.getElementById('confirm-panel'); notifier.textContent = ''; setActive(panelConfirm); } else { notifier.innerHTML = '' + response.responseText; //notifier.textContent = response.responseText; } }); }); } function attachListener( elements, event, handler ) { for (var i = 0; i < elements.length; i++) { elements[i].addEventListener( event, handler ); } } function setActive( newActivePanel ) { var oldActivePanel = spDialog.querySelector('.dialog-panel.active'); if ( oldActivePanel ) { oldActivePanel.classList.remove('active'); } if ( newActivePanel ) { newActivePanel.classList.add('active'); } } function resetSignupForm() { document.getElementById('firstname').value=''; document.getElementById('lastname').value=''; document.getElementById('email').value=''; notifier.innerHTML = ''; } })( document, jQuery );