Browse files

Initial Commit; text-edit only, don't judge me

  • Loading branch information...
0 parents commit effed76bb6d84a5287a4db4405e23b668dca6c18 @jgable committed Jan 3, 2012
Showing with 206 additions and 0 deletions.
  1. +46 −0 .gitignore
  2. +62 −0 README.md
  3. +98 −0 jquery.mobile.mvc-1.0.js
46 .gitignore
@@ -0,0 +1,46 @@
+#OS junk files
+[Tt]humbs.db
+*.DS_Store
+
+#Visual Studio files
+*.[Oo]bj
+*.exe
+*.pdb
+*.user
+*.aps
+*.pch
+*.vspscc
+*.vssscc
+*_i.c
+*_p.c
+*.ncb
+*.suo
+*.tlb
+*.tlh
+*.bak
+*.[Cc]ache
+*.ilk
+*.log
+*.lib
+*.sbr
+*.sdf
+ipch/
+obj/
+[Bb]in
+[Dd]ebug*/
+[Rr]elease*/
+Ankh.NoLoad
+
+#Tooling
+_ReSharper*/
+*.resharper
+[Tt]est[Rr]esult*
+
+#Project files
+[Bb]uild/
+
+#Subversion files
+.svn
+
+# Office Temp Files
+~$*
62 README.md
@@ -0,0 +1,62 @@
+# jQuery Mobile MVC Plugin
+
+## Create MVC Style Handlers for your jQuery Mobile Pages
+
+### Examples
+
+(function($) {
+
+ // Create a base page...
+ var basePage = {
+ name: "default",
+ show: function($page) {
+ log("showing the " + this.name + " page");
+
+ disco.trackPage(this.name, "demo");
+ }
+ },
+ // Our welcome page inherits from the basePage and adds a "create" handler.
+ welcomePage = $.extend({}, basePage, {
+ name: "welcome",
+ trackClick: function(name) {
+ // Track a button click
+ disco.trackEvent(this.name, "demo");
+ },
+ create: function($page) {
+ var self = this;
+
+ this.$aboutLink = $page.find("#aboutLink");
+ this.$installLink = $page.find("#installLink");
+ this.$contactLink = $page.find("#contactLink");
+
+ this.$aboutLink.click(function() { self.trackClick("aboutLink"); });
+ this.$installLink.click(function() { self.trackClick("installLink"); });
+ this.$contactLink.click(function() { self.trackClick("contactLink"); });
+ }
+ }),
+ // The about page.
+ aboutPage = $.extend({}, basePage, {
+ name: "about"
+ }),
+ // The contact page.
+ contactPage = $.extend({}, basePage, {
+ name: "contact",
+ create: function($page) {
+ $page.find("#mailLink").click(function() {
+ disco.trackEvent("mailLink", "demo");
+ });
+ }
+ });
+
+ // Export our pages to the
+ $.extend($.mobile.mvc.pages, {
+ welcome: welcomePage,
+ about: aboutPage,
+ contact: contactPage
+ });
+
+})(jQuery);
+
+Packaged up by [Jacob Gable](http://jacob4u2.posterous.com).
+
+This project is licensed under the Microsoft Public License (Ms-PL) and MIT License.
98 jquery.mobile.mvc-1.0.js
@@ -0,0 +1,98 @@
+/* jquery.mobile.mvc.js
+ Website - http://github.com/jacob4u2/jquery-mobile-mvc
+ By: Jacob Gable - http://jacob4u2.posterous.com
+ License: Microsoft Public License / MIT
+*/
+
+(function ($, undefined) {
+
+ if(!$.mobile) {
+ throw "jquery-mobile-mvc must have jQuery Mobile to continue";
+ }
+
+ var pages = {},
+ defaults = {
+ pageNS: pages,
+ pageKeyAttr: "data-page-key"
+ },
+ pageEvents = "pagebeforecreate pagecreate pageinit pagebeforeshow pageshow pagebeforehide pagehide",
+ fromDialog = false,
+ dialogHandler = function (event) {
+ var type = event.type.slice(4) + "dialog";
+
+ // Using slice to cover both 'hidedialog' and 'beforehidedialog'.
+ fromDialog = type.slice(-10) === "hidedialog";
+
+ // Pass it down to our handlePageEvent.
+ handlePageEvent(this, type);
+ },
+ pageHandler = function (event) {
+ var evtType = event.type.slice(4);
+
+ handlePageEvent(this, evtType);
+ },
+ navLinkHandler = function (e) {
+ $.mobile.mvc.state = $.extend({}, $(this).data());
+ },
+ settings = $.extend(defaults, $.mobile.mvcOptions)
+
+
+ if($.fn.on) {
+ // Use .on if it's available (jQuery 1.7) for performance (http://jsperf.com/jquery-live-vs-delegate-vs-on)
+ $(document).on("div[data-role*='dialog']", pageEvents, dialogHandler);
+ $(document).on("div[data-role*='page']", pageEvents, pageHandler);
+ $(document).on(".navLink", "click", navLinkHandler);
+ } else {
+ $("div[data-role*='dialog']").live(pageEvents, dialogHandler);
+ $("div[data-role*='page']").live(pageEvents, pageHandler);
+
+ // Handle clicks on nav links by setting the navigation state
+ $(".navLink").live("click", navLinkHandler);
+ }
+
+ // page event handler
+ function handlePageEvent(page, evtName) {
+
+ // Bypass show events when coming back from a dialog
+ if (fromDialog && (evtName === "beforeshow" || evtName === "show")) {
+
+ if (evtName === "show") {
+ // Reset fromDialog after running the show event.
+ fromDialog = false;
+ }
+
+ evtName += "dialog";
+ }
+
+ // Get the id of our page from the page attribute, fall back to id if not found.
+ var $this = $(page),
+ thisId = $this.attr(settings.pageKeyAttr) || $this.attr("id");
+
+ if (!thisId) {
+ // Back out if no id defined...
+ return;
+ }
+
+ // Remove any sketchy characters...
+ thisId = thisId.replace(/\.html$/gi, "");
+
+ // Check for page in the namespace and fire off the corresponding function.
+ if (settings.pageNS[thisId] && ($.isFunction(settings.pageNS[thisId][evtName]))) {
+ // Set the current page in the pages namespace.
+ $.mobile.mvc.currPage = $this;
+
+ // Run the function with the jQuery'd page container and the html element.
+ settings.pageNS[thisId][evtName]($this, page);
+ }
+ };
+
+ // Export the mvc namespace to jQuery Mobile.
+ $.extend($.mobile, {
+ mvc: {
+ pages: settings.pageNS,
+ settings: settings,
+ state: undefined
+ }
+ });
+
+})(jQuery);

0 comments on commit effed76

Please sign in to comment.