{"id":23553019,"url":"https://github.com/rhildred/jqueryproxymobilephonegapbuild","last_synced_at":"2025-11-01T13:30:30.071Z","repository":{"id":26811487,"uuid":"30270033","full_name":"rhildred/jQueryProxyMobilePhonegapBuild","owner":"rhildred","description":"example using jQuery moibile multi-screen with the index.js code from previous app","archived":false,"fork":false,"pushed_at":"2015-02-03T23:18:41.000Z","size":415,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-26T11:14:26.680Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhildred.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-03T23:17:41.000Z","updated_at":"2015-02-03T23:18:41.000Z","dependencies_parsed_at":"2022-07-16T04:30:33.044Z","dependency_job_id":null,"html_url":"https://github.com/rhildred/jQueryProxyMobilePhonegapBuild","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhildred%2FjQueryProxyMobilePhonegapBuild","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhildred%2FjQueryProxyMobilePhonegapBuild/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhildred%2FjQueryProxyMobilePhonegapBuild/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhildred%2FjQueryProxyMobilePhonegapBuild/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhildred","download_url":"https://codeload.github.com/rhildred/jQueryProxyMobilePhonegapBuild/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239293947,"owners_count":19615041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-26T11:13:51.316Z","updated_at":"2025-11-01T13:30:30.017Z","avatar_url":"https://github.com/rhildred.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"JQuery Mobile app object and events\n======\n\nYou will see a lot of code that looks like this:\n\n    var app = {\n        // Application Constructor\n        initialize: function() {\n            this.bindEvents();\n        },\n        // Bind Event Listeners\n        //\n        // Bind any events that are required on startup. Common events are:\n        // 'load', 'deviceready', 'offline', and 'online'.\n        bindEvents: function() {\n            document.addEventListener('deviceready', this.onDeviceReady, false);\n        },\n        // deviceready Event Handler\n        //\n        // The scope of 'this' is the event. In order to call the 'receivedEvent'\n        // function, we must explicity call 'app.receivedEvent(...);'\n        onDeviceReady: function() {\n            app.receivedEvent('deviceready');\n        },\n        // Update DOM on a Received Event\n        receivedEvent: function(id) {\n            var parentElement = document.getElementById(id);\n            var listeningElement = parentElement.querySelector('.listening');\n            var receivedElement = parentElement.querySelector('.received');\n\n            listeningElement.setAttribute('style', 'display:none;');\n            receivedElement.setAttribute('style', 'display:block;');\n\n            console.log('Received Event: ' + id);\n        }\n    };\n    app.initialize();\n    \nI thought that I would get fancy and move my initialize up a line `}.initialize();` I got an error when my deviceReady event was received, because there was no app yet when `initialize` was chained on. 1 fix was to just go back to the way that the example was. A better fix, I think, is to use jQuery.proxy to set the context for the app when the listener is bound to the event:\n\n    var app = {\n        // Application Constructor\n        initialize: function() {\n            this.bindEvents();\n        },\n        // Bind Event Listeners\n        //\n        // Bind any events that are required on startup. Common events are:\n        // 'load', 'deviceready', 'offline', and 'online'.\n        bindEvents: function() {\n            document.addEventListener('deviceready', jQuery.proxy(this.onDeviceReady, this), false);\n        },\n        // deviceready Event Handler\n        //\n        // The scope of 'this' is the event. In order to call the 'receivedEvent'\n        // function, we must explicity call 'app.receivedEvent(...);'\n        onDeviceReady: function() {\n            this.receivedEvent('deviceready');\n        },\n        // Update DOM on a Received Event\n        receivedEvent: function(id) {\n            console.log('Received Event: ' + id);\n        }\n    }.initialize();\n\nI think that this is a better fix, because we don't rely on a global app object to move forwards. In a big project we may have multiple objects listening for different events. jQuery.proxy seems to keep related events and objects together better then using a global identifier like `app`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhildred%2Fjqueryproxymobilephonegapbuild","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhildred%2Fjqueryproxymobilephonegapbuild","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhildred%2Fjqueryproxymobilephonegapbuild/lists"}