Advertisement
KzDrew

load_mobile_resources php function

Jul 23rd, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.40 KB | None | 0 0
  1. <?php
  2.  
  3. function load_mobile_resources(){
  4.     global $config;
  5.     // this content is placed in the <head> .. </head> section of all mobile pages
  6.     // Note: this is a jquery mobile framework so this code will ever only load once; the first page that is initially browsed
  7.     //       so we need to include anything that any page might need here.
  8.     //       page specific resources are loaded in the <body> .. <body> section of the specific page !!
  9.     ?>
  10.     <meta name="viewport" content="width=device-width, initial-scale=1">
  11.     <meta charset="utf-8">
  12.  
  13.     <style type='text/css'>
  14.         label.error {
  15.             color: red;
  16.             font-size: 16px;
  17.             font-weight: normal;
  18.             line-height: 1.4;
  19.             margin-top: 0.5em;
  20.             width: 100%;
  21.             float: none;
  22.         }
  23.  
  24.         @media screen and (orientation: portrait){
  25.             label.error { margin-left: 0; display: block; }
  26.         }
  27.  
  28.         @media screen and (orientation: landscape){
  29.             label.error { display: inline-block; margin-left: 22%; }
  30.         }
  31.  
  32.         em { color: red; font-weight: bold; padding-right: .25em; }
  33.  
  34.  
  35.     </style>
  36.     <link rel="stylesheet" href="<?php echo $config['baseurlpath'];?>/resources/js/jquery.mobile-1.3.1.min.css" />
  37.     <link rel="stylesheet" href="<?php echo $config['baseurlpath'];?>/resources/css/jqm-icon-pack-2.0-original.css" />
  38.     <link rel="stylesheet" href="<?php echo $config['baseurlpath'];?>/resources/js/jquery.mobile.simpledialog.min.css" />
  39.     <link rel="stylesheet" href="<?php echo $config['baseurlpath'];?>/resources/js/image-picker.css" />
  40.  
  41.  
  42.  
  43.     <script src="<?php echo $config['baseurlpath'];?>/resources/js/json2.js"></script>
  44.     <script src="<?php echo $config['baseurlpath'];?>/resources/js/jquery-1.9.1.min.js"></script>
  45.     <script src="<?php echo $config['baseurlpath'];?>/resources/js/jstorage.js"></script>
  46.     <script src="<?php echo $config['baseurlpath'];?>/resources/js/jquery.validate-1.7.min.js"></script>
  47.     <script src="<?php echo $config['baseurlpath'];?>/resources/js/image-picker.min.js"></script>
  48.  
  49.  
  50.  
  51.  
  52. <script type="text/javascript">
  53.         console.log('head script');
  54.  
  55.  
  56.         $.validator.addMethod('require-one', function(value) {
  57.             return $('.require-one:checked').size() > 0;
  58.         }, 'Please check at least one box.');
  59.  
  60.  
  61.  
  62.         $(document).on('click', '#loginformSubmit', function(e){
  63.             e.preventDefault();
  64.             login_form_click_handler(e);
  65.         });
  66.  
  67.         $(document).on('click', '#addUserButton', function(e){
  68.             add_user_click_handler(e);
  69.         });
  70.  
  71.         $(document).on('click', '#deleteUserButton', function(e){
  72.             delete_user_click_handler();
  73.         });
  74.  
  75.         $(document).on('change', '.existing_user_role', function(e){
  76.             console.log('existing role changed -- saving change');
  77.             update_user_role(this.id);
  78.         });
  79.  
  80.         $(document).on('click', '.refresh_button', function(e){
  81.             convert_get_to_post($(location).attr('href'), true);
  82.         });
  83.  
  84.         $(document).on('change', '.new_user_role', function(e){
  85.             console.log('role changed. Validating form');
  86.             $('#addUserForm').validate().form();
  87.  
  88.         });
  89.  
  90.         $(document).on('change', '.delete_user', function(e){
  91.             console.log('checkbox options changed. Validating form');
  92.             validate_deleteUserForm();
  93.         });
  94.  
  95.         // -- mobileinit --
  96.         $(document).bind('mobileinit', function() {
  97.             console.log('mobileinit');
  98.             $.extend( $.mobile , {
  99.                 pageLoadErrorMessage: 'Either the page cannot be found or it cannot be loaded.'
  100.             });
  101.             //$.mobile.page.prototype.options.domCache = true;
  102.             var userAgent = navigator.userAgent.toUpperCase();
  103.             if(userAgent.indexOf('IPHONE')== -1 && userAgent.indexOf('IPOD')== -1){
  104.                 $.mobile.defaultPageTransition = 'none';
  105.             }
  106.         });
  107.  
  108.         $(function() {
  109.  
  110.  
  111.  
  112.             // =============================================
  113.             // ALL PAGES
  114.             // =============================================
  115.  
  116.  
  117.  
  118.             // -- pagebeforechange --
  119.             $(document).on( "pagebeforechange", function( event, data ){
  120.                 if ( typeof data.toPage === "string" ) {
  121.                     console.log('all pages - page before change');
  122.                     console.log(data);
  123.                     // intercept a page change request
  124.                     // can alter any aspect of this request, if needed
  125.  
  126.                     // remove all local storage for this session
  127.                     if(data.toPage.indexOf("logout.php") != -1){
  128.                         $.jStorage.flush();
  129.                         console.log('flushing local storage data');
  130.                     // ensure that the avsession value is always in every page request
  131.                     }else{
  132.  
  133.                         if ('options' in data) {
  134.                             if ('type' in data.options && data.options.type == 'post') {
  135.                                 console.log('type is already post -- NOT converting get to post (it probably just was)');
  136.                             }else{
  137.                                 // intercept this get request and make it a post request with the avsession value injected
  138.                                 if(! (data.toPage.indexOf('resources/') == -1) ){
  139.                                     console.log('this is a resources request -- NOT converting get to post');
  140.                                 }else if('role' in data.options && data.options.role == 'popup'){
  141.                                     console.log('this is a popup -- NOT converting get to post');
  142.                                 }else if(data.options.changeHash == false && data.options.fromHashChange == true){ //&& data.options.reverse == true
  143.                                     console.log('this is a popup being closed (or browser fwd/back) -- NOT converting get to post');
  144.                                 }else{
  145.                                     // -- stop the current process
  146.                                     console.log('converting get request to a post');
  147.                                     event.preventDefault();
  148.                                     convert_get_to_post(data.toPage, false);
  149.                                 }
  150.                             }
  151.                         }
  152.                     }
  153.                 }
  154.             });
  155.             //-- pageshow --
  156.  
  157.             $(document).on( "pageshow", function(){
  158.                 console.log('all pages - page show');
  159.  
  160.                 // display a popup dialog if the referring page requests it
  161.                 var tmp = $.jStorage.get('showDialog', '');
  162.                 if(tmp != ''){
  163.                     $.jStorage.deleteKey('showDialog'); // prevent loop when returning from dialog that is shown
  164.                     console.log('This dialog is about to be shown: '+tmp);
  165.                     $.mobile.changePage('<?php echo $config['baseurlpath'];?>/resources/dialogs/'+tmp, {transition: 'pop', role: 'dialog'});
  166.                 }
  167.  
  168.  
  169.  
  170.             });
  171.  
  172.  
  173.             // =============================================
  174.             // #page_manage-buildings
  175.             // =============================================
  176.             // -- pageshow --
  177.             $(document).on("pageshow","#page_manage-buildings", function() {
  178.                // $( "#manage_buildings_image_picker" ).popup( "open" );
  179.                $('.mng_bld_edit_btn').bind('click', mng_bld_edit_click_handler);
  180.                $('.mng_bld_delete_btn').bind('click', mng_bld_delete_click_handler);
  181.             });
  182.  
  183.             // =============================================
  184.             // #page_login
  185.             // =============================================
  186.             // -- pageshow --
  187.             $(document).on("pageshow","#page_login", function() {
  188.                 console.log('this page - page show - #page_login');
  189.                 $('#username').focus();
  190.                 $('#username').keypress(function(event){
  191.                     var keycode = (event.keyCode ? event.keyCode : event.which);
  192.                     if(keycode == '13'){
  193.                         console.log('enter key pressed in username - focus to password field');
  194.                         $('#password').focus();
  195.                     }
  196.                 });
  197.                 $('#password').keypress(function(event){
  198.                     var keycode = (event.keyCode ? event.keyCode : event.which);
  199.                     if(keycode == '13'){
  200.                         console.log('enter key pressed in password');
  201.                         if($('#username').val() == ''){
  202.                             console.log('username is empty -- sending focus there');
  203.                             $('#username').focus();
  204.                         }else{
  205.                             console.log('username is not empty -- submitting form');
  206.                             $('#loginformSubmit').trigger('click');
  207.                         }
  208.                     }
  209.                 });
  210.             });
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.             /* ** TEMPLATE **********************************************
  218.             // =============================================
  219.             // #page_index
  220.             // =============================================
  221.             // -- pageshow --
  222.             $(document).on("pageshow","#page_index", function() {
  223.                 console.log('this page - page show - #page_index');
  224.  
  225.             });
  226.             *************************************************************/
  227.  
  228.  
  229.  
  230.         }); // end function
  231.  
  232.  
  233.         function convert_get_to_post(urlStr, forceReload){
  234.             postData = new Object;
  235.             var urlObj = $.mobile.path.parseUrl(urlStr);
  236.  
  237.  
  238.             if(urlObj.search){
  239.                 // -- ensure any query string parameters are sent as post data
  240.                 var dataStr = urlObj.search.toString();
  241.                 dataStr = dataStr.replace(/^\?/,'');
  242.                 dataPairs = dataStr.split('&');
  243.                 //console.log('here is the dataPairs');
  244.                 //console.log(dataPairs);
  245.                 var avsessionFound=0;
  246.                 for (x in dataPairs) {
  247.                     dataPair = dataPairs[x];
  248.                     //console.log(dataPair);
  249.                     var dataSet = dataPair.split('=');
  250.                     //console.log('here is the dataSet');
  251.                     //console.log(dataSet);
  252.                     postData[dataSet[0]]=dataSet[1];
  253.                     if(dataSet[0]=='avsession'){
  254.                         avsessionFound=1;
  255.                         console.log('avsession found: '+dataSet[1]);
  256.                     }
  257.                 }
  258.                 if(avsessionFound==0){
  259.                     // inject the avsession value into the post data
  260.                     postData['avsession'] = $.jStorage.get('avsession', '');
  261.                 }
  262.                 //console.log('here is the postData');
  263.                 //console.log(postData);
  264.  
  265.                 // send this request as a post
  266.                 $.mobile.changePage(urlObj.hrefNoSearch, {data: postData, type: 'post', reloadPage: forceReload});
  267.  
  268.             }else{
  269.                 // no query string to worry about jsut send this as a post with the avsession value injected
  270.                 postData['avsession'] = $.jStorage.get('avsession', '');
  271.                 $.mobile.changePage(urlObj.hrefNoSearch, {data: postData, type: 'post'});
  272.             }
  273.  
  274.         }
  275.  
  276.         function showDialog(dialogName, dialogMsg){
  277.             if(dialogMsg){
  278.                 $.jStorage.set('dialogMessage', dialogMsg);
  279.             }
  280.             console.log('This dialog is about to be shown: '+dialogName);
  281.             $.mobile.changePage('<?php echo $config['baseurlpath'];?>/resources/dialogs/'+dialogName, {transition: 'pop', role: 'dialog'});
  282.         }
  283.  
  284.     </script>
  285.  
  286.  
  287.     <script src="<?php echo $config['baseurlpath'];?>/resources/js/jquery.mobile-1.3.1.min.js"></script>
  288.     <script src="<?php echo $config['baseurlpath'];?>/resources/js/jquery.mobile.simpledialog2.min.js"></script>
  289.  
  290.     <?php
  291. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement