Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function load_mobile_resources(){
- global $config;
- // this content is placed in the <head> .. </head> section of all mobile pages
- // Note: this is a jquery mobile framework so this code will ever only load once; the first page that is initially browsed
- // so we need to include anything that any page might need here.
- // page specific resources are loaded in the <body> .. <body> section of the specific page !!
- ?>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <meta charset="utf-8">
- <style type='text/css'>
- label.error {
- color: red;
- font-size: 16px;
- font-weight: normal;
- line-height: 1.4;
- margin-top: 0.5em;
- width: 100%;
- float: none;
- }
- @media screen and (orientation: portrait){
- label.error { margin-left: 0; display: block; }
- }
- @media screen and (orientation: landscape){
- label.error { display: inline-block; margin-left: 22%; }
- }
- em { color: red; font-weight: bold; padding-right: .25em; }
- </style>
- <link rel="stylesheet" href="<?php echo $config['baseurlpath'];?>/resources/js/jquery.mobile-1.3.1.min.css" />
- <link rel="stylesheet" href="<?php echo $config['baseurlpath'];?>/resources/css/jqm-icon-pack-2.0-original.css" />
- <link rel="stylesheet" href="<?php echo $config['baseurlpath'];?>/resources/js/jquery.mobile.simpledialog.min.css" />
- <link rel="stylesheet" href="<?php echo $config['baseurlpath'];?>/resources/js/image-picker.css" />
- <script src="<?php echo $config['baseurlpath'];?>/resources/js/json2.js"></script>
- <script src="<?php echo $config['baseurlpath'];?>/resources/js/jquery-1.9.1.min.js"></script>
- <script src="<?php echo $config['baseurlpath'];?>/resources/js/jstorage.js"></script>
- <script src="<?php echo $config['baseurlpath'];?>/resources/js/jquery.validate-1.7.min.js"></script>
- <script src="<?php echo $config['baseurlpath'];?>/resources/js/image-picker.min.js"></script>
- <script type="text/javascript">
- console.log('head script');
- $.validator.addMethod('require-one', function(value) {
- return $('.require-one:checked').size() > 0;
- }, 'Please check at least one box.');
- $(document).on('click', '#loginformSubmit', function(e){
- e.preventDefault();
- login_form_click_handler(e);
- });
- $(document).on('click', '#addUserButton', function(e){
- add_user_click_handler(e);
- });
- $(document).on('click', '#deleteUserButton', function(e){
- delete_user_click_handler();
- });
- $(document).on('change', '.existing_user_role', function(e){
- console.log('existing role changed -- saving change');
- update_user_role(this.id);
- });
- $(document).on('click', '.refresh_button', function(e){
- convert_get_to_post($(location).attr('href'), true);
- });
- $(document).on('change', '.new_user_role', function(e){
- console.log('role changed. Validating form');
- $('#addUserForm').validate().form();
- });
- $(document).on('change', '.delete_user', function(e){
- console.log('checkbox options changed. Validating form');
- validate_deleteUserForm();
- });
- // -- mobileinit --
- $(document).bind('mobileinit', function() {
- console.log('mobileinit');
- $.extend( $.mobile , {
- pageLoadErrorMessage: 'Either the page cannot be found or it cannot be loaded.'
- });
- //$.mobile.page.prototype.options.domCache = true;
- var userAgent = navigator.userAgent.toUpperCase();
- if(userAgent.indexOf('IPHONE')== -1 && userAgent.indexOf('IPOD')== -1){
- $.mobile.defaultPageTransition = 'none';
- }
- });
- $(function() {
- // =============================================
- // ALL PAGES
- // =============================================
- // -- pagebeforechange --
- $(document).on( "pagebeforechange", function( event, data ){
- if ( typeof data.toPage === "string" ) {
- console.log('all pages - page before change');
- console.log(data);
- // intercept a page change request
- // can alter any aspect of this request, if needed
- // remove all local storage for this session
- if(data.toPage.indexOf("logout.php") != -1){
- $.jStorage.flush();
- console.log('flushing local storage data');
- // ensure that the avsession value is always in every page request
- }else{
- if ('options' in data) {
- if ('type' in data.options && data.options.type == 'post') {
- console.log('type is already post -- NOT converting get to post (it probably just was)');
- }else{
- // intercept this get request and make it a post request with the avsession value injected
- if(! (data.toPage.indexOf('resources/') == -1) ){
- console.log('this is a resources request -- NOT converting get to post');
- }else if('role' in data.options && data.options.role == 'popup'){
- console.log('this is a popup -- NOT converting get to post');
- }else if(data.options.changeHash == false && data.options.fromHashChange == true){ //&& data.options.reverse == true
- console.log('this is a popup being closed (or browser fwd/back) -- NOT converting get to post');
- }else{
- // -- stop the current process
- console.log('converting get request to a post');
- event.preventDefault();
- convert_get_to_post(data.toPage, false);
- }
- }
- }
- }
- }
- });
- //-- pageshow --
- $(document).on( "pageshow", function(){
- console.log('all pages - page show');
- // display a popup dialog if the referring page requests it
- var tmp = $.jStorage.get('showDialog', '');
- if(tmp != ''){
- $.jStorage.deleteKey('showDialog'); // prevent loop when returning from dialog that is shown
- console.log('This dialog is about to be shown: '+tmp);
- $.mobile.changePage('<?php echo $config['baseurlpath'];?>/resources/dialogs/'+tmp, {transition: 'pop', role: 'dialog'});
- }
- });
- // =============================================
- // #page_manage-buildings
- // =============================================
- // -- pageshow --
- $(document).on("pageshow","#page_manage-buildings", function() {
- // $( "#manage_buildings_image_picker" ).popup( "open" );
- $('.mng_bld_edit_btn').bind('click', mng_bld_edit_click_handler);
- $('.mng_bld_delete_btn').bind('click', mng_bld_delete_click_handler);
- });
- // =============================================
- // #page_login
- // =============================================
- // -- pageshow --
- $(document).on("pageshow","#page_login", function() {
- console.log('this page - page show - #page_login');
- $('#username').focus();
- $('#username').keypress(function(event){
- var keycode = (event.keyCode ? event.keyCode : event.which);
- if(keycode == '13'){
- console.log('enter key pressed in username - focus to password field');
- $('#password').focus();
- }
- });
- $('#password').keypress(function(event){
- var keycode = (event.keyCode ? event.keyCode : event.which);
- if(keycode == '13'){
- console.log('enter key pressed in password');
- if($('#username').val() == ''){
- console.log('username is empty -- sending focus there');
- $('#username').focus();
- }else{
- console.log('username is not empty -- submitting form');
- $('#loginformSubmit').trigger('click');
- }
- }
- });
- });
- /* ** TEMPLATE **********************************************
- // =============================================
- // #page_index
- // =============================================
- // -- pageshow --
- $(document).on("pageshow","#page_index", function() {
- console.log('this page - page show - #page_index');
- });
- *************************************************************/
- }); // end function
- function convert_get_to_post(urlStr, forceReload){
- postData = new Object;
- var urlObj = $.mobile.path.parseUrl(urlStr);
- if(urlObj.search){
- // -- ensure any query string parameters are sent as post data
- var dataStr = urlObj.search.toString();
- dataStr = dataStr.replace(/^\?/,'');
- dataPairs = dataStr.split('&');
- //console.log('here is the dataPairs');
- //console.log(dataPairs);
- var avsessionFound=0;
- for (x in dataPairs) {
- dataPair = dataPairs[x];
- //console.log(dataPair);
- var dataSet = dataPair.split('=');
- //console.log('here is the dataSet');
- //console.log(dataSet);
- postData[dataSet[0]]=dataSet[1];
- if(dataSet[0]=='avsession'){
- avsessionFound=1;
- console.log('avsession found: '+dataSet[1]);
- }
- }
- if(avsessionFound==0){
- // inject the avsession value into the post data
- postData['avsession'] = $.jStorage.get('avsession', '');
- }
- //console.log('here is the postData');
- //console.log(postData);
- // send this request as a post
- $.mobile.changePage(urlObj.hrefNoSearch, {data: postData, type: 'post', reloadPage: forceReload});
- }else{
- // no query string to worry about jsut send this as a post with the avsession value injected
- postData['avsession'] = $.jStorage.get('avsession', '');
- $.mobile.changePage(urlObj.hrefNoSearch, {data: postData, type: 'post'});
- }
- }
- function showDialog(dialogName, dialogMsg){
- if(dialogMsg){
- $.jStorage.set('dialogMessage', dialogMsg);
- }
- console.log('This dialog is about to be shown: '+dialogName);
- $.mobile.changePage('<?php echo $config['baseurlpath'];?>/resources/dialogs/'+dialogName, {transition: 'pop', role: 'dialog'});
- }
- </script>
- <script src="<?php echo $config['baseurlpath'];?>/resources/js/jquery.mobile-1.3.1.min.js"></script>
- <script src="<?php echo $config['baseurlpath'];?>/resources/js/jquery.mobile.simpledialog2.min.js"></script>
- <?php
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement