jqmobi-rails 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,7 +18,12 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Add these lines to the top of your app/assets/javascripts/application.js file:
22
+
23
+ ```javascript
24
+ //= require jq.mobi
25
+ //= require jq.mobi_ujs
26
+ ```
22
27
 
23
28
  ## Contributing
24
29
 
@@ -1,7 +1,7 @@
1
1
  module Jqmobi
2
2
  module Rails
3
- VERSION = "0.0.0"
4
- JQMOBI_VERSION = "1.02a"
5
- JQMOBI_UJS_VERSION = "707a0ee59efbe59d02b52efcf79f45fabc603305"
3
+ VERSION = "0.0.1"
4
+ JQMOBI_VERSION = "1.03"
5
+ JQMOBI_UJS_VERSION = "51f4668988122d5a915fa5a99ea55d9b2cb2a15e"
6
6
  end
7
7
  end
@@ -28,6 +28,34 @@ if (!window.jq || typeof (jq) !== "function") {
28
28
  fragementRE=/^\s*<(\w+)[^>]*>/,
29
29
  _attrCache={};
30
30
 
31
+
32
+ /**
33
+ * internal function to use domfragments for insertion
34
+ *
35
+ * @api private
36
+ */
37
+ function _insertFragments(jqm,container,insert){
38
+ var frag=document.createDocumentFragment();
39
+ if(insert){
40
+ for(var j=jqm.length-1;j>=0;j--)
41
+ {
42
+ frag.insertBefore(jqm[j],frag.firstChild);
43
+ }
44
+ container.insertBefore(frag,container.firstChild);
45
+
46
+ }
47
+ else {
48
+
49
+ for(var j=0;j<jqm.length;j++)
50
+ frag.appendChild(jqm[j]);
51
+ container.appendChild(frag);
52
+ }
53
+ frag=null;
54
+ }
55
+
56
+
57
+
58
+
31
59
 
32
60
  /**
33
61
  * Internal function to test if a class name fits in a regular expression
@@ -769,11 +797,11 @@ if (!window.jq || typeof (jq) !== "function") {
769
797
  element = $(element);
770
798
  var i;
771
799
 
800
+
772
801
  for (i = 0; i < this.length; i++) {
773
802
  if (element.length && typeof element != "string") {
774
803
  element = $(element);
775
- for (var j = 0; j < element.length; j++)
776
- insert != undefined ? this[i].insertBefore(element[j], this[i].firstChild) : this[i].appendChild(element[j]);
804
+ _insertFragments(element,this[i],insert);
777
805
  } else {
778
806
  var obj =fragementRE.test(element)?$(element):undefined;
779
807
  if (obj == undefined || obj.length == 0) {
@@ -782,10 +810,7 @@ if (!window.jq || typeof (jq) !== "function") {
782
810
  if (obj.nodeName != undefined && obj.nodeName.toLowerCase() == "script" && (!obj.type || obj.type.toLowerCase() === 'text/javascript')) {
783
811
  window.eval(obj.innerHTML);
784
812
  } else if(obj instanceof $jqm) {
785
- for(var k=0;k<obj.length;k++)
786
- {
787
- insert != undefined ? this[i].insertBefore(obj[k], this[i].firstChild) : this[i].appendChild(obj[k]);
788
- }
813
+ _insertFragments(obj,this[i],insert);
789
814
  }
790
815
  else {
791
816
  insert != undefined ? this[i].insertBefore(obj, this[i].firstChild) : this[i].appendChild(obj);
@@ -874,8 +899,8 @@ if (!window.jq || typeof (jq) !== "function") {
874
899
  return {
875
900
  left: obj.left + window.pageXOffset,
876
901
  top: obj.top + window.pageYOffset,
877
- width: parseInt(this[0].style.width),
878
- height: parseInt(this[0].style.height)
902
+ width: parseInt(obj.width),
903
+ height: parseInt(obj.height)
879
904
  };
880
905
  },
881
906
  /**
@@ -1214,6 +1239,9 @@ if (!window.jq || typeof (jq) !== "function") {
1214
1239
  if (!settings.headers)
1215
1240
  settings.headers = {};
1216
1241
 
1242
+ if(!('async' in settings)||settings.async!==false)
1243
+ settings.async=true;
1244
+
1217
1245
  if (!settings.dataType)
1218
1246
  settings.dataType = "text/html";
1219
1247
  else {
@@ -1291,7 +1319,7 @@ if (!window.jq || typeof (jq) !== "function") {
1291
1319
  settings.complete.call(context, xhr, error ? 'error' : 'success');
1292
1320
  }
1293
1321
  };
1294
- xhr.open(settings.type, settings.url, true);
1322
+ xhr.open(settings.type, settings.url, settings.async);
1295
1323
 
1296
1324
  if (settings.contentType)
1297
1325
  settings.headers['Content-Type'] = settings.contentType;
@@ -118,8 +118,7 @@
118
118
  // memoized value from clicked submit button
119
119
  var button = element.data('ujs:submit-button');
120
120
  if (button) {
121
- throw "not implemented";
122
- //data += '&' + encodeURIComponent(button);
121
+ data = data + '&' + encodeURIComponent(button.name) + '=' + encodeURIComponent(button.value);
123
122
  element.data('ujs:submit-button', null);
124
123
  }
125
124
  } else if (element.filter(rails.inputChangeSelector).length > 0) {
@@ -796,15 +796,16 @@
796
796
  </div></div>';
797
797
  $(this.container).append($(markup));
798
798
 
799
- $("#" + this.id).bind("close", function(){
799
+ var $el=$("#"+this.id);
800
+ $el.bind("close", function(){
800
801
  self.hide();
801
802
  })
802
803
 
803
804
  if (this.cancelOnly) {
804
- $("#" + this.id).find('A#action').hide();
805
- $("#" + this.id).find('A#cancel').addClass('center');
805
+ $el.find('A#action').hide();
806
+ $el.find('A#cancel').addClass('center');
806
807
  }
807
- $("#" + this.id).find('A').each(function() {
808
+ $el.find('A').each(function() {
808
809
  var button = $(this);
809
810
  button.bind('click', function(e) {
810
811
  if (button.attr('id') == 'cancel') {
@@ -820,8 +821,8 @@
820
821
  });
821
822
  self.positionPopup();
822
823
  $.blockUI(0.5);
823
- $('#' + self.id).removeClass('hidden');
824
- $('#' + self.id).bind("orientationchange", function() {
824
+ $el.removeClass('hidden');
825
+ $el.bind("orientationchange", function() {
825
826
  self.positionPopup();
826
827
  });
827
828
 
@@ -841,6 +842,7 @@
841
842
  remove: function() {
842
843
  var self = this;
843
844
  var $el=$("#"+self.id);
845
+ $el.unbind("close");
844
846
  $el.find('BUTTON#action').unbind('click');
845
847
  $el.find('BUTTON#cancel').unbind('click');
846
848
  $el.unbind("orientationchange").remove();
@@ -1354,1673 +1356,1723 @@
1354
1356
  };
1355
1357
  }
1356
1358
  })(jq);
1357
- /**
1358
- * jq.ui - A User Interface library for creating jqMobi applications
1359
- *
1360
- * @copyright 2011
1361
- * @author AppMobi
1362
- */(function($) {
1363
-
1364
- var hasLaunched = false;
1365
- var startPath = window.location.pathname;
1366
- var defaultHash = window.location.hash;
1367
- var previousTarget = defaultHash;
1368
-
1369
-
1370
- if(!("pushState" in window.history)){
1371
- window.history['pushState']=function(){}
1372
- }
1373
- var ui = function() {
1374
- // Init the page
1375
- var that = this;
1376
- if (window.AppMobi)
1377
- document.addEventListener("appMobi.device.ready", function() {
1378
- that.hasLaunched = true;
1379
- if (that.autoLaunch) {
1380
- that.launch();
1381
- }
1382
- }, false);
1383
- else if (document.readyState == "complete" || document.readyState == "loaded") {
1384
- that.hasLaunched = true;
1385
- if (that.autoLaunch) {
1386
- that.launch();
1387
- }
1388
- } else
1389
- document.addEventListener("DOMContentLoaded", function() {
1390
- that.hasLaunched = true;
1391
- if (that.autoLaunch) {
1392
- that.launch();
1393
- }
1394
- }, false);
1395
- if (!window.AppMobi)
1396
- AppMobi = {}, AppMobi.webRoot = "";
1397
- window.addEventListener("popstate", function() {
1398
- that.goBack();
1399
- }, false);
1400
-
1401
- /**
1402
- * Helper function to setup the transition objects
1403
- * Custom transitions can be added via $.ui.availableTransitions
1404
- ```
1405
- $.ui.availableTransitions['none']=function();
1406
- ```
1407
- */
1408
- (function(obj) {
1409
- obj.availableTransitions = {};
1410
- obj.availableTransitions['none'] = that.noTransition;
1411
- obj.availableTransitions['default'] = that.noTransition;
1412
- })(this);
1413
- };
1414
-
1415
-
1416
- ui.prototype = {
1417
- fixAndroidInputs:true,
1418
- isAjaxApp:false,
1419
- isAppMobi: false,
1420
- showLoading:true,
1421
- navbar: "",
1422
- header: "",
1423
- viewportContainer: "",
1424
- backButton: "",
1425
- remotePages: {},
1426
- history: [],
1427
- homeDiv: "",
1428
- screenWidth: "",
1429
- content: "",
1430
- modalWindow: "",
1431
- customFooter: false,
1432
- defaultFooter: "",
1433
- defaultHeader: null,
1434
- customMenu: false,
1435
- defaultMenu: "",
1436
- _readyFunc: null,
1437
- doingTransition: false,
1438
- passwordBox: new jq.passwordBox(),
1439
- selectBox: jq.selectBox,
1440
- ajaxUrl: "",
1441
- transitionType: "slide",
1442
- scrollingDivs: [],
1443
- firstDiv: "",
1444
- remoteJSPages: {},
1445
- hasLaunched: false,
1446
- launchCompleted: false,
1447
- activeDiv: "",
1448
-
1449
-
1450
- css3animate: function(el, opts) {
1451
- el = jq(el);
1452
- if (!el.__proto__["css3Animate"])
1453
- throw "css3Animate plugin is required";
1454
- return el.css3Animate(opts);
1455
- },
1456
- /**
1457
- * This is the time transitions will run for.
1458
- ```
1459
- $.ui.transitionTime='400ms';
1460
- ```
1461
- * @title $.ui.transitionTime;
1462
- */
1463
- transitionTime:"500",
1464
- /**
1465
- * this is a boolean when set to true (default) it will load that panel when the app is started
1466
- ```
1467
- $.ui.loadDefaultHash=false; //Never load the page from the hash when the app is started
1468
- $.ui.loadDefaultHash=true; //Default
1469
- ```
1470
- *@title $.ui.loadDefaultHash
1471
- */
1472
- loadDefaultHash: true,
1473
-
1474
- /**
1475
- * This is a boolean that when set to true will add "&cache=_rand_" to any ajax loaded link
1476
- ```
1477
- $.ui.useAjaxCacheBuster=true;
1478
- ```
1479
- *@title $.ui.useAjaxCacheBuster
1480
- */
1481
- useAjaxCacheBuster: false,
1482
- /**
1483
- * This is a shorthand call to the jq.actionsheet plugin. We wire it to the jQUi div automatically
1484
- ```
1485
- $.ui.actionsheet("<a href='javascript:;' class='button'>Settings</a> <a href='javascript:;' class='button red'>Logout</a>")
1486
- $.ui.actionsheet("[{
1487
- text: 'back',
1488
- cssClasses: 'red',
1489
- handler: function () { $.ui.goBack(); ; }
1490
- }, {
1491
- text: 'show alert 5',
1492
- cssClasses: 'blue',
1493
- handler: function () { alert("hi"); }
1494
- }, {
1495
- text: 'show alert 6',
1496
- cssClasses: '',
1497
- handler: function () { alert("goodbye"); }
1498
- }]");
1499
- ```
1500
- * @param {String,Array} links
1501
- * @title $.ui.actionsheet()
1502
- */
1503
- actionsheet: function(opts) {
1504
- el = jq("#jQUi");
1505
- if (!el.__proto__["actionsheet"])
1506
- throw "actionsheet plugin is required";
1507
- return el.actionsheet(opts);
1508
- },
1509
- /**
1510
- * This is a wrapper to jq.popup.js plugin. If you pass in a text string, it acts like an alert box and just gives a message
1511
- ```
1512
- $.ui.popup(opts);
1513
- $.ui.popup( {
1514
- title:"Alert! Alert!",
1515
- message:"This is a test of the emergency alert system!! Don't PANIC!",
1516
- cancelText:"Cancel me",
1517
- cancelCallback: function(){console.log("cancelled");},
1518
- doneText:"I'm done!",
1519
- doneCallback: function(){console.log("Done for!");},
1520
- cancelOnly:false
1521
- });
1522
- $.ui.popup('Hi there');
1523
- ```
1524
- * @param {Object|String} options
1525
- * @title $.ui.popup(opts)
1526
- */
1527
- popup: function(opts) {
1528
- el = jq("#jQUi");
1529
- if (!el.__proto__["popup"])
1530
- throw "popup plugin is required";
1531
- return el.popup(opts);
1532
- },
1533
-
1534
- /**
1535
- *This will throw up a mask and block the UI
1536
- ```
1537
- $.ui.blockUI(.9)
1538
- ````
1539
- * @param {Float} opacity
1540
- * @title $.ui.blockUI(opacity)
1541
- */
1542
- blockUI: function(opacity) {
1543
- $.blockUI(opacity);
1544
- },
1545
- /**
1546
- *This will remove the UI mask
1547
- ```
1548
- $.ui.unblockUI()
1549
- ````
1550
- * @title $.ui.unblockUI()
1551
- */
1552
- unblockUI: function() {
1553
- $.unblockUI();
1554
- },
1555
- /**
1556
- * Will remove the bottom nav bar menu from your application
1557
- ```
1558
- $.ui.removeFooterMenu();
1559
- ```
1560
- * @title $.ui.removeFooterMenu
1561
- */
1562
- removeFooterMenu: function() {
1563
- jq("#navbar").hide();
1564
- jq("#content").css("bottom", "0px");
1565
- this.showNavMenu = false;
1566
- },
1567
- /**
1568
- * Boolean if you want to show the bottom nav menu.
1569
- ```
1570
- $.ui.showNavMenu = false;
1571
- ```
1572
- * @title $.ui.showNavMenu
1573
- */
1574
- showNavMenu: true,
1575
- /**
1576
- * Boolean if you want to auto launch jqUi
1577
- ```
1578
- $.ui.autoLaunch = false; //
1579
- * @title $.ui.autoLaunch
1580
- */
1581
- autoLaunch: true,
1582
- /**
1583
- * Boolean if you want to show the back button
1584
- ```
1585
- $.ui.showBackButton = false; //
1586
- * @title $.ui.showBackButton
1587
- */
1588
- showBackbutton: true,
1589
- /**
1590
- * @api private
1591
- */
1592
- backButtonText: "",
1593
- /**
1594
- * Boolean if you want to reset the scroller position when navigating panels. Default is true
1595
- ```
1596
- $.ui.resetScrollers=false; //Do not reset the scrollers when switching panels
1597
- ```
1598
- * @title $.ui.resetScrollers
1599
- */
1600
- resetScrollers: true,
1601
- /**
1602
- * function to fire when jqUi is ready and completed launch
1603
- ```
1604
- $.ui.ready(function(){console.log('jqUi is ready');});
1605
- ```
1606
- * @param {Function} function to execute
1607
- * @title $.ui.ready
1608
- */
1609
- ready: function(param) {
1610
- if (this.launchCompleted)
1611
- param();
1612
- else
1613
- document.addEventListener("jq.ui.ready", param, false);
1614
- },
1615
- /**
1616
- * Override the back button class name
1617
- ```
1618
- $.ui.setBackButtonStyle('newClass');
1619
- ```
1620
- * @param {String} new class name
1621
- * @title $.ui.setBackButtonStyle(class)
1622
- */
1623
- setBackButtonStyle: function(className) {
1624
- $am("backButton").className = className;
1625
- },
1626
- /**
1627
- * Initiate a back transition
1628
- ```
1629
- $.ui.goBack()
1630
- ```
1631
-
1632
- * @title $.ui.goBack()
1633
- */
1634
- goBack: function() {
1635
-
1636
- if (this.history.length > 0) {
1637
- var tmpEl = this.history.pop();
1638
- this.loadContent(tmpEl.target + "", 0, 1, tmpEl.transition);
1639
- this.transitionType = tmpEl.transition;
1640
- }
1641
- },
1642
- /**
1643
- * Clear the history queue
1644
- ```
1645
- $.ui.clearHistory()
1646
- ```
1647
-
1648
- * @title $.ui.clearHistory()
1649
- */
1650
- clearHistory: function() {
1651
- this.history = [];
1652
- this.backButton.style.visibility = "hidden";
1653
- },
1654
- /**
1655
- * Update a badge on the selected target. Position can be
1656
- bl = bottom left
1657
- tl = top left
1658
- br = bottom right
1659
- tr = top right (default)
1660
- ```
1661
- $.ui.updateBadge('#mydiv','3','bl');
1662
- ```
1663
- * @param {String} target
1664
- * @param {String} Value
1665
- * @param {String} [position]
1666
- * @title $.ui.updateBadge(target,value,[position])
1667
- */
1668
- updateBadge: function(target, value, position) {
1669
- if (position === undefined)
1670
- position = "";
1671
-
1672
- if (target[0] != "#")
1673
- target = "#" + target;
1674
- var badge = jq(target).find("span.jq-badge");
1675
- if (badge.length == 0) {
1676
- if (jq(target).css("position") != "absolute")
1677
- jq(target).css("position", "relative");
1678
- badge = jq(target).append("<span class='jq-badge " + position + "'>" + value + "</span>");
1679
- } else
1680
- badge.html(value);
1681
- badge.data("ignore-pressed","true");
1682
-
1683
- },
1684
- /**
1685
- * Removes a badge from the selected target.
1686
- ```
1687
- $.ui.removeBadge('#mydiv');
1688
- ```
1689
- * @param {String} target
1690
- * @title $.ui.removeBadge(target)
1691
- */
1692
- removeBadge: function(target) {
1693
- jq(target).find("span.jq-badge").remove();
1694
- },
1695
- /**
1696
- * Toggles the bottom nav nav menu. Force is a boolean to force show or hide.
1697
- ```
1698
- $.ui.toggleNavMenu();//toggle it
1699
- $.ui.toggleNavMenu(true); //force show it
1700
- ```
1701
- * @param {Boolean} [force]
1702
- * @title $.ui.toggleNavMenu([force])
1703
- */
1704
- toggleNavMenu: function(force) {
1705
- if (!jq.ui.showNavMenu)
1706
- return;
1707
- if (jq("#navbar").css("display") != "none" && ((force !== undefined && force !== true) || force === undefined)) {
1708
- jq("#content").css("bottom", "0px");
1709
- jq("#navbar").hide();
1710
- } else if (force === undefined || (force !== undefined && force === true)) {
1711
- jq("#navbar").show();
1712
- jq("#content").css("bottom", jq("#navbar").css("height"));
1713
-
1714
- }
1715
- },
1716
- /**
1717
- * Toggles the top header menu.
1718
- ```
1719
- $.ui.toggleHeaderMenu();//toggle it
1720
- ```
1721
- * @param {Boolean} [force]
1722
- * @title $.ui.toggleHeaderMenu([force])
1723
- */
1724
- toggleHeaderMenu: function(force) {
1725
-
1726
- if (jq("#header").css("display") != "none" && ((force !== undefined && force !== true) || force === undefined)) {
1727
- jq("#content").css("top", "0px");
1728
- jq("#header").hide();
1729
- } else if (force === undefined || (force !== undefined && force === true)) {
1730
- jq("#header").show();
1731
- jq("#content").css("top", jq("#header").css("height"));
1732
-
1733
- }
1734
- },
1735
- /**
1736
- * Toggles the side menu. Force is a boolean to force show or hide.
1737
- ```
1738
- $.ui.toggleSideMenu();//toggle it
1739
- ```
1740
- * @param {Boolean} [force]
1741
- * @title $.ui.toggleSideMenu([force])
1742
- */
1743
- toggleSideMenu: function(force) {
1744
- var that = this;
1745
- if (!jq("#content").hasClass("hasMenu"))
1746
- return;
1747
- if (jq("#menu").css("display") != "block" && ((force !== undefined && force !== false) || force === undefined)) {
1748
- this.scrollingDivs["menu_scroller"].initEvents();
1749
- jq("#menu").show();
1750
- window.setTimeout(function() {
1751
- jq("#menu").addClass("on");
1752
- jq("#header").addClass("on");
1753
- jq("#navbar").addClass("on");
1754
- jq("#content").addClass("on");
1755
- }, 1); //needs to run after
1756
-
1757
- } else if (force === undefined || (force !== undefined && force === false)) {
1758
- this.scrollingDivs["menu_scroller"].removeEvents();
1759
-
1760
- jq("#header").removeClass("on");
1761
- jq("#menu").removeClass("on");
1762
- jq("#navbar").removeClass("on");
1763
- jq("#content").removeClass("on");
1764
- setTimeout(function() {
1765
- jq("#menu").hide();
1766
- }, 300); //lame I know
1767
- }
1768
- },
1769
- /**
1770
- * depricated
1771
- ```
1772
- $.ui.updateNavbar();//toggle it
1773
- ```
1774
- * @title $.ui.updateNavbar([force])
1775
- * @api private
1776
- */
1777
- updateNavbar: function() {
1778
- },
1779
- /**
1780
- * Updates the elements in the navbar
1781
- ```
1782
- $.ui.updateNavbarElements(elements);
1783
- ```
1784
- * @param {String|Object} Elements
1785
- * @title $.ui.updateNavbarElements(Elements)
1786
- */
1787
- updateNavbarElements: function(elems) {
1788
- var nb = jq("#navbar");
1789
- if (elems === undefined || elems == null)
1790
- return;
1791
- if (typeof (elems) == "string")
1792
- return nb.html(elems), null;
1793
- nb.html("");
1794
- for (var i = 0; i < elems.length; i++) {
1795
- var node = elems[i].cloneNode(true);
1796
- nb.append(node);
1797
- }
1798
- jq("#navbar a").data("ignore-pressed", "true").data("resetHistory", "true");
1799
- },
1800
- /**
1801
- * Updates the elements in the header
1802
- ```
1803
- $.ui.updateHeaderElements(elements);
1804
- ```
1805
- * @param {String|Object} Elements
1806
- * @title $.ui.updateHeaderElement(Elements)
1807
- */
1808
- updateHeaderElements: function(elems) {
1809
- var nb = jq("#header");
1810
- if (elems === undefined || elems == null)
1811
- return;
1812
- if (typeof (elems) == "string")
1813
- return nb.html(elems), null;
1814
- nb.html("");
1815
- for (var i = 0; i < elems.length; i++) {
1816
- var node = elems[i].cloneNode(true);
1817
- nb.append(node);
1818
- }
1819
- },
1820
-
1821
- /**
1822
- * Updates the elements in the side menu
1823
- ```
1824
- $.ui.updateSideMenu(elements);
1825
- ```
1826
- * @param {String|Object} Elements
1827
- * @title $.ui.updateSideMenu(Elements)
1828
- */
1829
- updateSideMenu: function(elems) {
1830
- var that = this;
1831
-
1832
- var nb = jq("#menu_scroller");
1833
-
1834
- if (elems === undefined || elems == null)
1835
- return;
1836
- if (typeof (elems) == "string")
1837
- return nb.html(elems), null;
1838
- nb.html('');
1839
- var close = document.createElement("a");
1840
- close.className = "closebutton jqMenuClose";
1841
- close.href = "javascript:;"
1842
- close.onclick = function() {
1843
- that.toggleSideMenu();
1844
- };
1845
- nb.append(close);
1846
- var tmp = document.createElement("div");
1847
- tmp.className = "jqMenuHeader";
1848
- tmp.innerHTML = "Menu";
1849
- nb.append(tmp);
1850
- for (var i = 0; i < elems.length; i++) {
1851
- var node = elems[i].cloneNode(true);
1852
- if (elems[i].oldhash) {
1853
- node.href = elems[i].oldhref;
1854
- node.onclick = elems[i].oldonclick;
1855
- }
1856
- nb.append(node);
1857
- }
1858
- //Move the scroller to the top and hide it
1859
- this.scrollingDivs['menu_scroller'].scrollTo({
1860
- x: 0,
1861
- y: 0
1862
- }, "0");
1863
- },
1864
- /**
1865
- * Set the title of the current panel
1866
- ```
1867
- $.ui.setTitle("new title");
1868
- ```
1869
-
1870
- * @param {String} value
1871
- * @title $.ui.setTitle(value)
1872
- */
1873
- setTitle: function(val) {
1874
- jq("#header #pageTitle").html(val);
1875
- },
1876
- /**
1877
- * Override the text for the back button
1878
- ```
1879
- $.ui.setBackButtonText("GO...");
1880
- ```
1881
-
1882
- * @param {String} value
1883
- * @title $.ui.setBackButtonText(value)
1884
- */
1885
- setBackButtonText: function(text) {
1886
- if (this.backButtonText.length > 0)
1887
- jq("#header #backButton").html(this.backButtonText);
1888
- else
1889
- jq("#header #backButton").html(text);
1890
- },
1891
- /**
1892
- * Show the loading mask
1893
- ```
1894
- $.ui.showMask()
1895
- $.ui.showMask(;Doing work')
1896
- ```
1897
-
1898
- * @param {String} [text]
1899
- * @title $.ui.showMask(text);
1900
- */
1901
- showMask: function(text) {
1902
- if (!text)
1903
- text = "Loading Content";
1904
- jq("#jQui_mask>h1").html(text);
1905
- $am("jQui_mask").style.display = "block";
1906
- },
1907
- /**
1908
- * Hide the loading mask
1909
- * @title $.ui.hideMask();
1910
- */
1911
- hideMask: function() {
1912
- $am("jQui_mask").style.display = "none";
1913
- },
1914
- /**
1915
- * Load a content panel in a modal window. We set the innerHTML so event binding will not work.
1916
- ```
1917
- $.ui.showModal("#myDiv");
1918
- ```
1919
- * @param {String|Object} panel to show
1920
- * @title $.ui.showModal();
1921
- */
1922
- showModal: function(id) {
1923
- var that = this;
1924
-
1925
- if ($am(id)) {
1926
- //jq("#modalContainer").html('<div style="width:1px;height:1px;-webkit-transform:translate3d(0,0,0);float:right"></div>' + $am(id).childNodes[0].innerHTML + '');
1927
- jq("#modalContainer").html($am(id).childNodes[0].innerHTML);
1928
- jq('#modalContainer').append("<a href='javascript:;' onclick='$.ui.hideModal();' class='closebutton modalbutton'></a>");
1929
- this.modalWindow.style.display = "block";
1930
-
1931
- button = null;
1932
- content = null;
1933
- this.scrollingDivs['modal_container'].initEvents();
1934
- this.scrollToTop('modal');
1935
- }
1936
-
1937
- },
1938
- /**
1939
- * Hide the modal window and remove the content
1940
- ```
1941
- $.ui.hideModal("#myDiv");
1942
- ```
1943
- * @title $.ui.hideModal();
1944
- */
1945
- hideModal: function() {
1946
- $am("modalContainer").innerHTML = "";
1947
- $am("jQui_modal").style.display = "none";
1948
-
1949
- this.scrollingDivs['modal_container'].removeEvents();
1950
- },
1951
-
1952
- /**
1953
- * Update the HTML in a content panel
1954
- ```
1955
- $.ui.updateContentDiv("#myDiv","This is the new content");
1956
- ```
1957
- * @param {String,Object} panel
1958
- * @param {String} html to update with
1959
- * @title $.ui.updateContentDiv(id,content);
1960
- */
1961
- updateContentDiv: function(id, content) {
1962
- var el = $am(id);
1963
- if (!el)
1964
- return;
1965
- if (el.getAttribute("scrolling") && el.getAttribute("scrolling").toLowerCase() == "no")
1966
- el.innerHTML = content;
1967
- else
1968
- el.childNodes[0].innerHTML = content;
1969
- },
1970
- /**
1971
- * Dynamically create a new panel on the fly. It wires events, creates the scroller, applies Android fixes, etc.
1972
- ```
1973
- $.ui.addContentDiv("myDiv","This is the new content","Title");
1974
- ```
1975
- * @param {String|Object} Element to add
1976
- * @param {String} Content
1977
- * @param {String} title
1978
- * @title $.ui.addContentDiv(id,content,title);
1979
- */
1980
- addContentDiv: function(el, content, title, refresh, refreshFunc) {
1981
- var myEl = $am(el);
1982
- if (!myEl) {
1983
- var newDiv = document.createElement("div");
1984
- newDiv.id = el;
1985
- newDiv.title = title;
1986
- newDiv.innerHTML = content;
1987
- } else {
1988
- newDiv = myEl;
1989
- }
1990
- newDiv.className = "panel";
1991
- var that = this;
1992
-
1993
- myEl = null;
1994
- that.addDivAndScroll(newDiv, refresh, refreshFunc);
1995
- newDiv = null;
1996
- return;
1997
- },
1998
- /**
1999
- * Takes a div and sets up scrolling for it..
2000
- ```
2001
- $.ui.addDivAndScroll(object);
2002
- ```
2003
- * @param {Object} Element
2004
- * @title $.ui.addDivAndScroll(element);
2005
- * @api private
2006
- */
2007
- addDivAndScroll: function(tmp, refreshPull, refreshFunc) {
2008
- var addScroller = true;
2009
- if (tmp.getAttribute("scrolling") && tmp.getAttribute("scrolling").toLowerCase() == "no")
2010
- addScroller = false;
2011
- if (!addScroller) {
2012
- this.content.appendChild(tmp);
2013
- tmp = null;
2014
- return;
2015
- }
2016
- //WE need to clone the div so we keep events
2017
- var myDiv = tmp.cloneNode(false);
2018
-
2019
-
2020
- tmp.title = null;
2021
- tmp.id = null;
2022
- tmp.removeAttribute("footer");
2023
- tmp.removeAttribute("nav");
2024
- jq(tmp).removeClass("panel");
2025
- tmp.style.width = "100%";
2026
- //tmp.style.height = "inherit";
2027
-
2028
- myDiv.appendChild(tmp);
2029
-
2030
- this.content.appendChild(myDiv);
2031
-
2032
- this.selectBox.getOldSelects(myDiv.id);
2033
- this.passwordBox.getOldPasswords(myDiv.id);
2034
-
2035
- if (addScroller) {
2036
- this.scrollingDivs[myDiv.id] = (jq(tmp).scroller({
2037
- scrollBars: true,
2038
- verticalScroll: true,
2039
- horizontalScroll: false,
2040
- vScrollCSS: "jqmScrollbar",
2041
- refresh: false
2042
- }));
2043
- this.scrollingDivs[myDiv.id].removeEvents();
2044
- }
2045
-
2046
-
2047
- myDiv = null;
2048
- tmp = null;
2049
- },
2050
-
2051
- /**
2052
- * This has been depricated, as it was a design flaw on my end. People were updating segments of the panel and not the whole part. It's counter intuitive to have to call
2053
- * $.ui.updateAnchors(object,reset) after each change.
2054
- * This will be removed in 1.1
2055
- * @title $.ui.updateAnchors(element,resetHistory);
2056
- * @api private
2057
- */
2058
- updateAnchors: function(domEl, reset) {
2059
- },
2060
- /**
2061
- * Scrolls a panel to the top
2062
- ```
2063
- $.ui.scrollToTop(id);
2064
- ```
2065
- * @param {String} id without hash
2066
- * @title $.ui.scrollToTop(id);
2067
- */
2068
- scrollToTop: function(id) {
2069
- if (this.scrollingDivs[id]) {
2070
- this.scrollingDivs[id].scrollTo({
2071
- x: 0,
2072
- y: 0
2073
- }, 0);
2074
- }
2075
- },
2076
- /**
2077
- * Scrolls all panels to the top and fixes position when orientation changes
2078
- ```
2079
- $.ui.updateOrientation(event);
2080
- ```
2081
- * @param {Event} event
2082
- * @title $.ui.updateOrientation(event);
2083
- * @api private
2084
- */
2085
- updateOrientation: function(event) {
2086
- for (var j in this.scrollingDivs) {
2087
- if (typeof (this.scrollingDivs[j]) !== "function")
2088
- this.scrollToTop(j);
2089
- }
2090
- },
2091
-
2092
- /**
2093
- * This is used when a transition fires to do helper events. We check to see if we need to change the nav menus, footer, and fire
2094
- * the load/onload functions for panels
2095
- ```
2096
- $.ui.parsePanelFunctions(currentDiv,oldDiv);
2097
- ```
2098
- * @param {Object} current div
2099
- * @param {Object} old div
2100
- * @title $.ui.parsePanelFunctions(currentDiv,oldDiv);
2101
- * @api private
2102
- */
2103
- parsePanelFunctions: function(what, oldDiv) {
2104
- var that = this;
2105
- var hasFooter = what.getAttribute("data-footer");
2106
- var hasHeader = what.getAttribute("data-header");
2107
- window.setTimeout(function() {
2108
- if (hasFooter && hasFooter.toLowerCase() == "none") {
2109
- that.toggleNavMenu(false);
2110
- } else {
2111
- that.toggleNavMenu(true);
2112
- }
2113
- if (hasFooter && that.customFooter != hasFooter) {
2114
- that.customFooter = hasFooter;
2115
- that.updateNavbarElements(jq("#" + hasFooter).children());
2116
- } else if (hasFooter != that.customFooter) {
2117
- if (that.customFooter)
2118
- that.updateNavbarElements(that.defaultFooter);
2119
- that.customFooter = false;
2120
- }
2121
-
2122
-
2123
- if (hasHeader && that.customHeader != hasHeader) {
2124
- that.customHeader = hasHeader;
2125
- that.updateHeaderElements(jq("#" + hasHeader).children());
2126
- } else if (hasHeader != that.customHeader) {
2127
- if (that.customHeader)
2128
- {
2129
- that.updateHeaderElements(that.defaultHeader);
2130
- that.setTitle(that.activeDiv.title);
2131
- }
2132
- that.customHeader = false;
2133
- }
2134
-
2135
- //Load inline footers
2136
- var inlineFooters = $(what).find("footer");
2137
- if (inlineFooters.length > 0)
2138
- {
2139
- that.customFooter = what.id;
2140
- that.updateNavbarElements(inlineFooters.children());
2141
- }
2142
- //load inline headers
2143
- var inlineHeader = $(what).find("header");
2144
-
2145
-
2146
- if (inlineHeader.length > 0)
2147
- {
2148
- that.customHeader = what.id;
2149
- that.updateHeaderElements(inlineHeader.children());
2150
- }
2151
- //check if the panel has a footer
2152
- if (what.getAttribute("data-tab")) { //Allow the dev to force the footer menu
2153
-
2154
- jq("#navbar a").removeClass("selected");
2155
- jq("#navbar #" + what.getAttribute("data-tab")).addClass("selected");
2156
- }
2157
- var hasMenu = what.getAttribute("data-nav");
2158
- if (hasMenu && that.customMenu != hasMenu) {
2159
- that.customMenu = hasMenu;
2160
- that.updateSideMenu(jq("#" + hasMenu).children());
2161
- } else if (hasMenu != that.customMenu) {
2162
- if (that.customMenu)
2163
- that.updateSideMenu(that.defaultMenu);
2164
- that.customMenu = false;
2165
- }
2166
-
2167
- }, 10);
2168
-
2169
-
2170
-
2171
- var fnc = what.getAttribute("data-load");
2172
- if (typeof fnc == "string" && window[fnc]) {
2173
- window[fnc](what);
2174
- }
2175
- if (oldDiv) {
2176
- fnc = oldDiv.getAttribute("data-unload");
2177
- if (typeof fnc == "string" && window[fnc]) {
2178
- window[fnc](oldDiv);
2179
- }
2180
- }
2181
- if (this.menu.style.display == "block")
2182
- this.toggleSideMenu(); //Close on phones to prevent orientation change bug.
2183
-
2184
- },
2185
- /**
2186
- * Helper function that parses a contents html for any script tags and either adds them or executes the code
2187
- * @api private
2188
- */
2189
- parseScriptTags: function(div) {
2190
- if (!div)
2191
- return;
2192
- var scripts = div.getElementsByTagName("script");
2193
- div = null;
2194
- for (var i = 0; i < scripts.length; i++) {
2195
- if (scripts[i].src.length > 0 && !that.remoteJSPages[scripts[i].src]) {
2196
- var doc = document.createElement("script");
2197
- doc.type = scripts[i].type;
2198
- doc.src = scripts[i].src;
2199
- document.getElementsByTagName('head')[0].appendChild(doc);
2200
- that.remoteJSPages[scripts[i].src] = 1;
2201
- doc = null;
2202
- } else {
2203
- window.eval(scripts[i].innerHTML);
2204
- }
2205
- }
2206
- },
2207
- /**
2208
- * This is called to initiate a transition or load content via ajax.
2209
- * We can pass in a hash+id or URL and then we parse the panel for additional functions
2210
- ```
2211
- $.ui.loadContent("#main",false,false,"up");
2212
- ```
2213
- * @param {String} target
2214
- * @param {Boolean} newtab (resets history)
2215
- * @param {Boolean} go back (initiate the back click)
2216
- * @param {String} transition
2217
- * @title $.ui.loadContent(target,newTab,goBack,transition);
2218
- * @api public
2219
- */
2220
- loadContent: function(target, newTab, back, transition, anchor) {
2221
-
2222
- if (this.doingTransition)
2223
- return;
2224
-
2225
-
2226
- what = null;
2227
- var that = this;
2228
- that.hideMask();
2229
- var loadAjax = true;
2230
- if (target.indexOf("#") == -1) {
2231
- var urlHash = "url" + crc32(target); //Ajax urls
2232
- if ($am(urlHash)) {
2233
-
2234
- //ajax div already exists. Let's see if we should be refreshing it.
2235
- loadAjax = false;
2236
- if (anchor.getAttribute("data-refresh-ajax") === 'true' || (anchor.refresh && anchor.refresh === true)||this.isAjaxApp) {
2237
- loadAjax = true;
2238
- } else
2239
- target = "#" + urlHash;
2240
- }
2241
- }
2242
-
2243
- if (target.indexOf("#") == -1 && anchor && loadAjax) {
2244
-
2245
- // XML Request
2246
- if (this.activeDiv.id == "jQui_ajax" && target == this.ajaxUrl)
2247
- return;
2248
- if (target.indexOf("http") == -1)
2249
- target = AppMobi.webRoot + target;
2250
-
2251
- var xmlhttp = new XMLHttpRequest();
2252
- xmlhttp.onreadystatechange = function() {
2253
- if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
2254
- this.doingTransition = false;
2255
-
2256
- var doReturn = false;
2257
-
2258
- //Here we check to see if we are retaining the div, if so update it
2259
- if ($am(urlHash) !== undefined) {
2260
- that.updateContentDiv(urlHash, xmlhttp.responseText);
2261
- $am(urlHash).title = anchor.title ? anchor.title : target;
2262
- } else if (anchor.getAttribute("data-persist-ajax")||that.isAjaxApp) {
2263
-
2264
- var refresh = (anchor.getAttribute("data-pull-scroller") === 'true') ? true : false;
2265
- refreshFunction = refresh ?
2266
- function() {
2267
- anchor.refresh = true;
2268
- that.loadContent(target, newTab, back, transition, anchor);
2269
- anchor.refresh = false;
2270
- } : null
2271
- that.addContentDiv(urlHash, xmlhttp.responseText, refresh, refreshFunction);
2272
- $am(urlHash).title = anchor.title ? anchor.title : target;
2273
- } else {
2274
- that.updateContentDiv("jQui_ajax", xmlhttp.responseText);
2275
- $am("jQui_ajax").title = anchor.title ? anchor.title : target;
2276
- that.loadContent("#jQui_ajax", newTab, back);
2277
- doReturn = true;
2278
- }
2279
- //Let's load the content now.
2280
- //We need to check for any script tags and handle them
2281
- var div = document.createElement("div");
2282
- div.innerHTML = xmlhttp.responseText;
2283
- that.parseScriptTags(div);
2284
- if (doReturn)
2285
- return;
2286
-
2287
- return that.loadContent("#" + urlHash);
2288
-
2289
- }
2290
- };
2291
- ajaxUrl = target;
2292
- var newtarget = this.useAjaxCacheBuster ? target + (target.split('?')[1] ? '&' : '?') + "cache=" + Math.random() * 10000000000000000 : target;
2293
- xmlhttp.open("GET", newtarget, true);
2294
- xmlhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
2295
- xmlhttp.send();
2296
- // show Ajax Mask
2297
- if(this.showLoading)
2298
- this.showMask();
2299
- return;
2300
- } else {
2301
- // load a div
2302
-
2303
- what = target.replace("#", "");
2304
-
2305
- var slashIndex = what.indexOf('/');
2306
- var hashLink = "";
2307
- if (slashIndex != -1) {
2308
- // Ignore everything after the slash for loading
2309
- hashLink = what.substr(slashIndex);
2310
- what = what.substr(0, slashIndex);
2311
- }
2312
-
2313
- what = $am(what);
2314
-
2315
- if (!what)
2316
- throw ("Target: " + target + " was not found");
2317
- if (what == this.activeDiv && !back)
2318
- return;
2319
-
2320
- if (what.getAttribute("data-modal") == "true" || what.getAttribute("modal") == "true") {
2321
- return this.showModal(what.id);
2322
- }
2323
-
2324
-
2325
-
2326
- this.transitionType = transition;
2327
- var oldDiv = this.activeDiv;
2328
- var currWhat = what;
2329
-
2330
-
2331
- if (oldDiv == currWhat) //prevent it from going to itself
2332
- return;
2333
-
2334
- if (newTab) {
2335
-
2336
- this.history = [];
2337
- if(("#" + this.firstDiv.id)!=target){
2338
- this.history.push({
2339
- target: "#" + this.firstDiv.id,
2340
- transition: transition
2341
- });
2342
- }
2343
- } else if (!back) {
2344
- this.history.push({
2345
- target: previousTarget,
2346
- transition: transition
2347
- });
2348
-
2349
- }
2350
- window.history.pushState(what.id, what.id, startPath + '#' + what.id + hashLink);
2351
- $(window).trigger("hashchange", {newUrl: startPath + '#' + what.id + hashLink,oldURL: startPath + "#" + this.activeDiv.id});
2352
-
2353
- previousTarget = '#' + what.id + hashLink;
2354
-
2355
- if (this.resetScrollers && this.scrollingDivs[what.id]) {
2356
- this.scrollingDivs[what.id].scrollTo({
2357
- x: 0,
2358
- y: 0
2359
- });
2360
- }
2361
- $(what).addClass("active");
2362
-
2363
- what.style.display = "block";
2364
- that.doingTransition = true;
2365
- if (that.availableTransitions[transition])
2366
- that.availableTransitions[transition].call(that, oldDiv, currWhat, back);
2367
- else
2368
- that.availableTransitions['default'].call(that, oldDiv, currWhat, back);
2369
-
2370
-
2371
-
2372
- this.activeDiv = what;
2373
-
2374
- if (this.scrollingDivs[this.activeDiv.id]) {
2375
- this.scrollingDivs[this.activeDiv.id].initEvents();
2376
- }
2377
- if (this.scrollingDivs[oldDiv.id]) {
2378
- this.scrollingDivs[oldDiv.id].removeEvents();
2379
- }
2380
- //Let's check if it has a function to run to update the data
2381
-
2382
-
2383
-
2384
- setTimeout(function(){
2385
- that.parsePanelFunctions(what, oldDiv);
2386
- },300);
2387
- setTimeout(function(){
2388
-
2389
- if (back) {
2390
- if (that.history.length > 0) {
2391
- var val = that.history[that.history.length - 1];
2392
-
2393
- var el = $am(val.target.replace("#", ""));
2394
- that.setBackButtonText(el.title)
2395
- }
2396
- } else if (that.activeDiv.title)
2397
- that.setBackButtonText(that.activeDiv.title)
2398
- else
2399
- that.setBackButtonText("Back");
2400
- if (what.title) {
2401
- that.setTitle(what.title);
2402
- }
2403
- if (newTab) {
2404
- that.setBackButtonText(that.firstDiv.title)
2405
- }
2406
-
2407
- //Update the back buttons
2408
- if (that.history.length == 0) {
2409
- jq("#header #backButton").css("visibility","hidden");
2410
- that.history = [];
2411
- } else if (that.showBackbutton){
2412
- jq("#header #backButton").css("visibility","visible");
2413
- }
2414
- },370);
2415
- window.scrollTo(1, 1);
2416
-
2417
- }
2418
- },
2419
-
2420
- /**
2421
- * This is callled when you want to launch jqUi. If autoLaunch is set to true, it gets called on DOMContentLoaded.
2422
- * If autoLaunch is set to false, you can manually invoke it.
2423
- ```
2424
- $.ui.autoLaunch=false;
2425
- $.ui.launch();
2426
- ```
2427
- * @title $.ui.launch();
2428
- */
2429
- launch: function() {
2430
-
2431
- if (this.hasLaunched == false || this.launchCompleted) {
2432
- this.hasLaunched = true;
2433
- return;
2434
- }
2435
- this.isAppMobi = (window.AppMobi && typeof (AppMobi) == "object" && AppMobi.app !== undefined) ? true : false;
2436
- var that = this;
2437
- this.viewportContainer = jq("#jQUi");
2438
- this.navbar = $am("navbar");
2439
- this.content = $am("content");
2440
- this.header = $am("header");
2441
- this.menu = $am("menu");
2442
- if (this.viewportContainer.length == 0) {
2443
- var container = document.createElement("div");
2444
- container.id = "jQUi";
2445
- var body = document.body;
2446
- while (body.firstChild) {
2447
- container.appendChild(body.firstChild);
2448
- }
2449
- jq(document.body).prepend(container);
2450
- this.viewportContainer = jq("#jQUi");
2451
- }
2452
- if (!this.navbar) {
2453
- this.navbar = document.createElement("div");
2454
- this.navbar.id = "navbar";
2455
- this.navbar.style.cssText = "display:none";
2456
- this.viewportContainer.append(this.navbar);
2457
- }
2458
- if (!this.header) {
2459
- this.header = document.createElement("div");
2460
- this.header.id = "header";
2461
- this.viewportContainer.prepend(this.header);
2462
- }
2463
- if (!this.menu) {
2464
- this.menu = document.createElement("div");
2465
- this.menu.id = "menu";
2466
- this.menu.style.overflow = "hidden";
2467
- this.menu.innerHTML = "<div id='menu_scroller'></div>";
2468
- this.viewportContainer.append(this.menu);
2469
- this.scrollingDivs["menu_scroller"] = jq("#menu_scroller").scroller({
2470
- scrollBars: true,
2471
- verticalScroll: true,
2472
- vScrollCSS: "jqmScrollbar"
2473
- });
2474
- }
2475
-
2476
-
2477
- if (!this.content) {
2478
- this.content = document.createElement("div");
2479
- this.content.id = "content";
2480
- this.viewportContainer.append(this.content);
2481
- }
2482
- this.header.innerHTML = '<a id="backButton" href="javascript:;"></a> <h1 id="pageTitle"></h1>' + this.header.innerHTML;
2483
- this.backButton = $am("backButton");
2484
- this.backButton.className = "button";
2485
-
2486
- jq(document).on("click", "#backButton", function() {
2487
- that.goBack();
2488
- });
2489
- this.backButton.style.visibility = "hidden";
2490
- this.addContentDiv("jQui_ajax", "");
2491
- var maskDiv = document.createElement("div");
2492
- maskDiv.id = "jQui_mask";
2493
- maskDiv.className = "ui-loader";
2494
- maskDiv.innerHTML = "<span class='ui-icon ui-icon-loading spin'></span><h1>Loading Content</h1>";
2495
- maskDiv.style.zIndex = 20000;
2496
- maskDiv.style.display = "none";
2497
- document.body.appendChild(maskDiv);
2498
- var modalDiv = document.createElement("div");
2499
- modalDiv.id = "jQui_modal";
2500
-
2501
- this.viewportContainer.append(modalDiv);
2502
- modalDiv.appendChild(jq("<div id='modalContainer'></div>").get());
2503
- this.scrollingDivs['modal_container'] = jq("#modalContainer").scroller({
2504
- scrollBars: true,
2505
- vertical: true,
2506
- vScrollCSS: "jqmScrollbar"
2507
- });
2508
-
2509
- this.modalWindow = modalDiv;
2510
- var defer = [];
2511
- var contentDivs = this.viewportContainer.get().querySelectorAll(".panel");
2512
- for (var i = 0; i < contentDivs.length; i++) {
2513
- var el = contentDivs[i];
2514
- var tmp = el;
2515
- var id;
2516
- if (el.parentNode && el.parentNode.id != "content") {
2517
- el.parentNode.removeChild(el);
2518
- var id = el.id;
2519
- this.addDivAndScroll(tmp);
2520
- if (tmp.getAttribute("selected"))
2521
- this.firstDiv = $am(id);
2522
- } else if (!el.parsedContent) {
2523
- el.parsedContent = 1;
2524
- el.parentNode.removeChild(el);
2525
- var id = el.id;
2526
- this.addDivAndScroll(tmp);
2527
- if (tmp.getAttribute("selected"))
2528
- this.firstDiv = $am(id);
2529
- }
2530
- if (el.getAttribute("data-defer")){
2531
- defer[id] = el.getAttribute("data-defer");
2532
- defer.length++;
2533
- }
2534
- el = null;
2535
- }
2536
- if(!this.firstDiv)
2537
- this.firstDiv=$("#content").children().get(0);
2538
- contentDivs = null;
2539
- var loadingDefer=false;
2540
- var toLoad=defer.length;
2541
- if(toLoad>0){
2542
- loadingDefer=true;
2543
- var loaded=0;
2544
- for (var j in defer) {
2545
- (function(j) {
2546
- jq.ajax({url:AppMobi.webRoot + defer[j], success:function(data) {
2547
- if (data.length == 0)
2548
- return;
2549
- $.ui.updateContentDiv(j, data);
2550
- that.parseScriptTags(jq(j).get());
2551
- loaded++;
2552
- if(loaded>=toLoad){
2553
- $(document).trigger("defer:loaded");
2554
- loadingDefer=false;
2555
-
2556
- }
2557
- },error:function(msg){
2558
- //still trigger the file as being loaded to not block jq.ui.ready
2559
- console.log("Error with deferred load "+AppMobi.webRoot+defer[j])
2560
- loaded++;
2561
- if(loaded>=toLoad){
2562
- $(document).trigger("defer:loaded");
2563
- loadingDefer=false;
2564
- }
2565
- }});
2566
- })(j);
2567
- }
2568
- }
2569
- if (this.firstDiv) {
2570
-
2571
- var that = this;
2572
- // Fix a bug in iOS where translate3d makes the content blurry
2573
- this.activeDiv = this.firstDiv;
2574
-
2575
- //window.setTimeout(function() {
2576
- var loadFirstDiv=function(){
2577
- //activeDiv = firstDiv;
2578
- if (defaultHash.length > 0 && that.loadDefaultHash&&defaultHash!=("#"+that.firstDiv.id))
2579
- {
2580
-
2581
- that.activeDiv=$(defaultHash).get();
2582
- jq("#header #backButton").css("visibility","visible");
2583
- that.setBackButtonText(that.activeDiv.title)
2584
- that.history=[{target:"#"+that.firstDiv.id}]; //Reset the history to the first div
2585
- }
2586
- else
2587
- previousTarget="#"+that.activeDiv.id;
2588
- if (that.scrollingDivs[that.activeDiv.id]) {
2589
- that.scrollingDivs[that.activeDiv.id].initEvents();
2590
- }
2591
- that.activeDiv.style.display = "block";
2592
-
2593
-
2594
- if (that.activeDiv.title)
2595
- that.setTitle(that.activeDiv.title);
2596
- that.parsePanelFunctions(that.activeDiv);
2597
- //Load the default hash
2598
-
2599
- that.history=[{target:"#"+that.firstDiv.id}]; //Reset the history to the first div
2600
- modalDiv = null;
2601
- maskDiv = null;
2602
- that.launchCompleted = true;
2603
-
2604
- if(jq("#navbar a").length>0){
2605
- jq("#navbar a").data("ignore-pressed", "true").data("resetHistory", "true");
2606
- that.defaultFooter = jq("#navbar").children();
2607
- that.updateNavbarElements(that.defaultFooter);
2608
- }
2609
- var firstMenu = jq("nav").get();
2610
- if(firstMenu){
2611
- that.defaultMenu = jq(firstMenu).children();
2612
- that.updateSideMenu(that.defaultMenu);
2613
- }
2614
- that.defaultHeader = jq("#header").children();
2615
- jq(document).trigger("jq.ui.ready");
2616
- jq("#splashscreen").remove();
2617
- };
2618
- if(loadingDefer){
2619
- $(document).one("defer:loaded",loadFirstDiv);
2620
- }
2621
- else
2622
- loadFirstDiv();
2623
- }
2624
-
2625
- },
2626
-
2627
- noTransition: function(oldDiv, currDiv, back) {
2628
- oldDiv.style.display = "block";
2629
- currDiv.style.display = "block";
2630
- var that = this
2631
- if (back) {
2632
- that.css3animate(currDiv, {
2633
- x: "0%",
2634
- time: "1ms"
2635
- });
2636
- that.css3animate(oldDiv, {
2637
- x: 0,
2638
- time: "1ms"
2639
- });
2640
-
2641
- } else {
2642
-
2643
- that.css3animate(oldDiv, {
2644
- x: 0,
2645
- y: 0,
2646
- time: "1ms"
2647
- });
2648
- that.css3animate(currDiv, {
2649
- x: "0%",
2650
- time: "1ms"
2651
- });
2652
- }
2653
- that.finishTransition(oldDiv);
2654
- currDiv.style.zIndex = 2;
2655
- oldDiv.style.zIndex = 1;
2656
- $(oldDiv).removeClass('active');
2657
- },
2658
-
2659
- /**
2660
- * This must be called at the end of every transition to hide the old div and reset the doingTransition variable
2661
- *
2662
- * @param {Object} Div that transitioned out
2663
- * @title $.ui.finishTransition(oldDiv)
2664
- */
2665
- finishTransition: function(oldDiv) {
2666
-
2667
- oldDiv.style.display = 'none';
2668
- this.doingTransition = false;
2669
-
2670
- }
2671
- /**
2672
- * END
2673
- * @api private
2674
- */
2675
- };
2676
-
2677
- function $am(el) {
2678
- el = el.indexOf("#") == -1 ? "#" + el : el;
2679
- return jq(el).get(0);
2680
- }
2681
-
2682
- var table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D"; /* Number */
2683
- var crc32 = function( /* String */str, /* Number */crc) {
2684
- if (crc == undefined)
2685
- crc = 0;
2686
- var n = 0; //a number between 0 and 255
2687
- var x = 0; //an hex number
2688
- crc = crc ^ (-1);
2689
- for (var i = 0, iTop = str.length; i < iTop; i++) {
2690
- n = (crc ^ str.charCodeAt(i)) & 0xFF;
2691
- x = "0x" + table.substr(n * 9, 8);
2692
- crc = (crc >>> 8) ^ x;
2693
- }
2694
- return crc ^ (-1);
2695
- };
2696
-
2697
-
2698
- $.ui = new ui;
2699
- })(jq);
2700
-
2701
- //The following functions are utilitiy functions for jqUi. They are not apart of the base class, but help with locking the page scroll,
2702
- //input box issues, remove the address bar on iOS and android, etc
2703
- (function() {
2704
- var jQUi;
2705
-
2706
- //Check to see if any <nav> items are found. If so, add the CSS classes
2707
- jq(document).ready(function() {
2708
- if (jq("nav").length > 0) {
2709
- jq("#jQUi #header").addClass("hasMenu");
2710
- jq("#jQUi #content").addClass("hasMenu");
2711
- jq("#jQUi #navbar").addClass("hasMenu");
2712
- }
2713
- jQUi = jq("#jQUi");
2714
- setTimeout(function(){
2715
- hideAddressBar();
2716
- },100);
2717
- });
2718
-
2719
- document.addEventListener("appMobi.device.ready", function() { //in AppMobi, we need to undo the height stuff since it causes issues.
2720
- setTimeout(function() {
2721
- jQUi.css("height", "100%"), document.body.style.height = "100%";
2722
- document.documentElement.style.minHeight = window.innerHeight;
2723
- }, 300);
2724
- });
2725
-
2726
-
2727
- window.addEventListener("orientationchange", function(e) {
2728
- jq.ui.updateOrientation()
2729
- window.setTimeout(function() {
2730
- hideAddressBar();
2731
- }, 200);
2732
- }, false);
2733
-
2734
- if (jq.os.android)
2735
- {
2736
- window.addEventListener("resize", function(e) {
2737
- window.scrollTo(0,1);
2738
- jq.ui.updateOrientation();
2739
- if(document.body.clientWidth>=700)
2740
- $.ui.toggleSideMenu(false);
2741
- window.setTimeout(function() {
2742
- hideAddressBar();
2743
- }, 100);
2744
- }, false);
2745
- }
2746
-
2747
-
2748
- function hideAddressBar() {
2749
- if (jq.os.desktop)
2750
- return jQUi.css("height", "100%");
2751
- if (jq.os.android) {
2752
- window.scrollTo(1, 1);
2753
- if (document.documentElement.scrollHeight < window.outerHeight / window.devicePixelRatio)
2754
- jQUi.css("height", (window.outerHeight / window.devicePixelRatio) + 'px');
2755
- }
2756
- else {
2757
- document.documentElement.style.height = "5000px";
2758
-
2759
- window.scrollTo(0, 1);
2760
- document.documentElement.style.height = window.innerHeight + "px";
2761
- jQUi.css("height", window.innerHeight + "px");
2762
- }
2763
- }
2764
- //The following is based on Cubiq.org - iOS no click delay. We use this to capture events to input boxes to fix Android...and fix iOS ;)
2765
- //We had to make a lot of fixes to allow access to input elements on android, etc.
2766
- function NoClickDelay(el) {
2767
- if (typeof (el) === "string")
2768
- el = document.getElementById(el);
2769
- el.addEventListener('touchstart', this, true);
2770
- }
2771
- var prevClickField;
2772
- var prevPanel;
2773
- var prevField;
2774
- NoClickDelay.prototype = {
2775
- dX: 0,
2776
- dY: 0,
2777
- cX: 0,
2778
- cY: 0,
2779
- handleEvent: function(e) {
2780
- switch (e.type) {
2781
- case 'touchstart':
2782
- this.onTouchStart(e);
2783
- break;
2784
- case 'touchmove':
2785
- this.onTouchMove(e);
2786
- break;
2787
- case 'touchend':
2788
- this.onTouchEnd(e);
2789
- break;
2790
- }
2791
- },
2792
-
2793
- onTouchStart: function(e) {
2794
-
2795
- this.dX = e.touches[0].pageX;
2796
- this.dY = e.touches[0].pageY;
2797
-
2798
- var theTarget = e.target;
2799
- if (theTarget.nodeType == 3)
2800
- theTarget = theTarget.parentNode;
2801
-
2802
- if(prevField){
2803
- prevField.blur();
2804
- prevField=null;
2805
- }
2806
- if(prevPanel){
2807
- //prevField.blur();
2808
- prevPanel.css("-webkit-transform","translate3d(0px,0px,0px)");
2809
- prevPanel.css("left","0");
2810
- prevField=null;
2811
- prevPanel=null;
2812
- }
2813
-
2814
- var tagname = theTarget.tagName.toLowerCase();
2815
- var type=theTarget.type||"";
2816
- if((tagname=="a"&& theTarget.href.indexOf("tel:")===0)||((tagname=="input")||tagname=="textarea"||tagname=="select")){
2817
- prevField=theTarget;
2818
- if(jq.os.android&&$.ui.fixAndroidInputs){
2819
- theTarget.focus();
2820
- prevField=theTarget;
2821
- prevPanel=$(theTarget).closest(".panel");
2822
- prevPanel.css("left","-100%");
2823
- prevPanel.css("-webkit-transition-duration","0ms");
2824
- prevPanel.css("-webkit-transform","translate3d(100%,0px,0px)");
2825
- prevPanel.css("position","absolute");
2826
- return;
2827
- }
2828
- }
2829
- else
2830
- e.preventDefault();
2831
- this.moved = false;
2832
- document.addEventListener('touchmove', this, true);
2833
- document.addEventListener('touchend', this, true);
2834
- },
2835
-
2836
- onTouchMove: function(e) {
2837
- this.moved = true;
2838
- this.cX = e.touches[0].pageX - this.dX;
2839
- this.cY = e.touches[0].pageY - this.dY;
2840
- // e.preventDefault();
2841
- },
2842
-
2843
- onTouchEnd: function(e) {
2844
-
2845
- document.removeEventListener('touchmove', this, false);
2846
- document.removeEventListener('touchend', this, false);
2847
-
2848
- if ((!jq.os.blackberry && !this.moved) || (jq.os.blackberry && (Math.abs(this.cX) < 5 || Math.abs(this.cY) < 5))) {
2849
- var theTarget = e.target;
2850
- if (theTarget.nodeType == 3)
2851
- theTarget = theTarget.parentNode;
2852
-
2853
- var theEvent = document.createEvent('MouseEvents');
2854
- theEvent.initEvent('click', true, true);
2855
- theTarget.dispatchEvent(theEvent);
2856
-
2857
- }
2858
- prevClickField = null;
2859
- this.dX = this.cX = this.cY = this.dY = 0;
2860
- }
2861
- };
2862
-
2863
-
2864
-
2865
- jq(document).ready(function() {
2866
- document.body.addEventListener('touchmove', function(e) {
2867
- e.preventDefault();
2868
- e.stopPropagation();
2869
- window.scrollTo(1, 1);
2870
- }, false);
2871
- if (!jq.os.desktop)
2872
- new NoClickDelay(document.getElementById("jQUi"));
2873
-
2874
- document.getElementById("jQUi").addEventListener("click", function(e) {
2875
-
2876
- var theTarget = e.target;
2877
- if (theTarget.nodeType == 3)
2878
- theTarget = theTarget.parentNode;
2879
- if (checkAnchorClick(theTarget)) {
2880
- e.preventDefault();
2881
- return false;
2882
- }
2883
- }, true);
2884
-
2885
- jq("#navbar").on("click", "a", function(e) {
2886
- jq("#navbar a").removeClass("selected");
2887
- setTimeout(function() {
2888
- $(e.target).addClass("selected");
2889
- }, 10);
2890
- });
2891
- });
2892
-
2893
- function checkAnchorClick(theTarget) {
2894
- var parent = false;
2895
- if (theTarget.tagName.toLowerCase() != "a" && theTarget.parentNode)
2896
- parent = true, theTarget = theTarget.parentNode; //let's try the parent so <a href="#foo"><img src="whatever.jpg"></a> will work
2897
- if (theTarget.tagName.toLowerCase() == "a") {
2898
- if (theTarget.href.toLowerCase().indexOf("javascript:") !== -1 || theTarget.getAttribute("data-ignore")) {
2899
- return false;
2900
- }
2901
-
2902
- if (theTarget.onclick && !jq.os.desktop) {
2903
- theTarget.onclick();
2904
- }
2905
-
2906
- if(theTarget.href.indexOf("tel:")===0)
2907
- return false;
2908
- if (theTarget.hash.indexOf("#") === -1 && theTarget.target.length > 0)
2909
- {
2910
-
2911
- if (theTarget.href.toLowerCase().indexOf("javascript:") != 0) {
2912
- if (jq.ui.isAppMobi)
2913
- AppMobi.device.launchExternal(theTarget.href);
2914
- else if (!jq.os.desktop)
2915
- brokerClickEventMobile(theTarget);
2916
- else
2917
- window.open(theTarget);
2918
- return true;
2919
- }
2920
- return false;
2921
- }
2922
- if ((theTarget.href.indexOf("#") !== -1 && theTarget.hash.length == 0) || theTarget.href.length == 0)
2923
- return true;
2924
-
2925
- var mytransition = theTarget.getAttribute("data-transition");
2926
- var resetHistory = theTarget.getAttribute("data-resetHistory");
2927
-
2928
- resetHistory = resetHistory && resetHistory.toLowerCase() == "true" ? true : false;
2929
-
2930
- var href = theTarget.hash.length > 0 ? theTarget.hash : theTarget.href;
2931
- jq.ui.loadContent(href, resetHistory, 0, mytransition, theTarget);
2932
- return true;
2933
- }
2934
- }
2935
- function brokerClickEventMobile(theTarget) {
2936
- if (jq.os.desktop)
2937
- return;
2938
- var clickevent = document.createEvent('Event');
2939
- clickevent.initEvent('click', true, false);
2940
- theTarget.target = "_blank";
2941
- theTarget.dispatchEvent(clickevent);
2942
- }
2943
- })();
2944
-
2945
- //Touch events are from zepto/touch.js
2946
-
2947
- (function($) {
2948
- var touch = {}, touchTimeout;
2949
-
2950
- function parentIfText(node) {
2951
- return 'tagName' in node ? node : node.parentNode;
2952
- }
2953
-
2954
- function swipeDirection(x1, x2, y1, y2) {
2955
- var xDelta = Math.abs(x1 - x2), yDelta = Math.abs(y1 - y2);
2956
- if (xDelta >= yDelta) {
2957
- return (x1 - x2 > 0 ? 'Left' : 'Right');
2958
- } else {
2959
- return (y1 - y2 > 0 ? 'Up' : 'Down');
2960
- }
2961
- }
2962
-
2963
- var longTapDelay = 750;
2964
- function longTap() {
2965
- if (touch.last && (Date.now() - touch.last >= longTapDelay)) {
2966
- touch.el.trigger('longTap');
2967
- touch = {};
2968
- }
2969
- }
2970
- $(document).ready(function() {
2971
- $(document.body).bind('touchstart', function(e) {
2972
- var now = Date.now(), delta = now - (touch.last || now);
2973
- touch.el = $(parentIfText(e.touches[0].target));
2974
- touchTimeout && clearTimeout(touchTimeout);
2975
- touch.x1 = e.touches[0].pageX;
2976
- touch.y1 = e.touches[0].pageY;
2977
- if (delta > 0 && delta <= 250)
2978
- touch.isDoubleTap = true;
2979
- touch.last = now;
2980
- setTimeout(longTap, longTapDelay);
2981
- if (!touch.el.data("ignore-pressed"))
2982
- touch.el.addClass("selected");
2983
- else
2984
- touch.el.closest(".selectable").addClass("selected");
2985
- }).bind('touchmove', function(e) {
2986
- touch.x2 = e.touches[0].pageX;
2987
- touch.y2 = e.touches[0].pageY;
2988
- }).bind('touchend', function(e) {
2989
- if (!touch.el) {
2990
- touch = {};
2991
- return;
2992
- }
2993
- if (!touch.el.data("ignore-pressed"))
2994
- touch.el.removeClass("selected");
2995
- else
2996
- touch.el.closest(".selectable").removeClass("selected");
2997
- if (touch.isDoubleTap) {
2998
- touch.el.trigger('doubleTap');
2999
- touch = {};
3000
- } else if (Math.abs(touch.x1 - touch.x2) > 5 || Math.abs(touch.y1 - touch.y2) > 5) {
3001
- (Math.abs(touch.x1 - touch.x2) > 30 || Math.abs(touch.y1 - touch.y2) > 30) &&
3002
- touch.el.trigger('swipe') &&
3003
- touch.el.trigger('swipe' + (swipeDirection(touch.x1, touch.x2, touch.y1, touch.y2)));
3004
- touch.x1 = touch.x2 = touch.y1 = touch.y2 = touch.last = 0;
3005
- } else if ('last' in touch) {
3006
- touch.el.trigger('tap');
3007
- touchTimeout = setTimeout(function() {
3008
- touchTimeout = null;
3009
- if (touch.el)
3010
- touch.el.trigger('singleTap');
3011
- touch = {};
3012
- }, 250);
3013
- }
3014
- }).bind('touchcancel', function() {
3015
- touch = {}
3016
- });
3017
- });
3018
-
3019
- ['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown', 'doubleTap', 'tap', 'singleTap', 'longTap'].forEach(function(m) {
3020
- $.fn[m] = function(callback) {
3021
- return this.bind(m, callback)
3022
- }
3023
- });
1359
+ /**
1360
+ * jq.ui - A User Interface library for creating jqMobi applications
1361
+ *
1362
+ * @copyright 2011
1363
+ * @author AppMobi
1364
+ */(function($) {
1365
+
1366
+ var hasLaunched = false;
1367
+ var startPath = window.location.pathname;
1368
+ var defaultHash = window.location.hash;
1369
+ var previousTarget = defaultHash;
1370
+
1371
+
1372
+ if(!("pushState" in window.history)){
1373
+ window.history['pushState']=function(){}
1374
+ }
1375
+ var ui = function() {
1376
+ // Init the page
1377
+ var that = this;
1378
+ if (window.AppMobi)
1379
+ document.addEventListener("appMobi.device.ready", function() {
1380
+ that.hasLaunched = true;
1381
+ if (that.autoLaunch) {
1382
+ that.launch();
1383
+ }
1384
+ }, false);
1385
+ else if (document.readyState == "complete" || document.readyState == "loaded") {
1386
+ that.hasLaunched = true;
1387
+ if (that.autoLaunch) {
1388
+ that.launch();
1389
+ }
1390
+ } else
1391
+ document.addEventListener("DOMContentLoaded", function() {
1392
+ that.hasLaunched = true;
1393
+ if (that.autoLaunch) {
1394
+ that.launch();
1395
+ }
1396
+ }, false);
1397
+ if (!window.AppMobi)
1398
+ AppMobi = {}, AppMobi.webRoot = "";
1399
+ window.addEventListener("popstate", function() {
1400
+ that.goBack();
1401
+ }, false);
1402
+
1403
+ /**
1404
+ * Helper function to setup the transition objects
1405
+ * Custom transitions can be added via $.ui.availableTransitions
1406
+ ```
1407
+ $.ui.availableTransitions['none']=function();
1408
+ ```
1409
+ */
1410
+ (function(obj) {
1411
+ obj.availableTransitions = {};
1412
+ obj.availableTransitions['none'] = that.noTransition;
1413
+ obj.availableTransitions['default'] = that.noTransition;
1414
+ })(this);
1415
+ };
1416
+
1417
+
1418
+ ui.prototype = {
1419
+ fixAndroidInputs:true,
1420
+ isAjaxApp:false,
1421
+ isAppMobi: false,
1422
+ showLoading:true,
1423
+ navbar: "",
1424
+ header: "",
1425
+ viewportContainer: "",
1426
+ backButton: "",
1427
+ remotePages: {},
1428
+ history: [],
1429
+ homeDiv: "",
1430
+ screenWidth: "",
1431
+ content: "",
1432
+ modalWindow: "",
1433
+ customFooter: false,
1434
+ defaultFooter: "",
1435
+ defaultHeader: null,
1436
+ customMenu: false,
1437
+ defaultMenu: "",
1438
+ _readyFunc: null,
1439
+ doingTransition: false,
1440
+ passwordBox: new jq.passwordBox(),
1441
+ selectBox: jq.selectBox,
1442
+ ajaxUrl: "",
1443
+ transitionType: "slide",
1444
+ scrollingDivs: [],
1445
+ firstDiv: "",
1446
+ remoteJSPages: {},
1447
+ hasLaunched: false,
1448
+ launchCompleted: false,
1449
+ activeDiv: "",
1450
+ customClickHandler:"",
1451
+
1452
+
1453
+ css3animate: function(el, opts) {
1454
+ el = jq(el);
1455
+ if (!el.__proto__["css3Animate"])
1456
+ throw "css3Animate plugin is required";
1457
+ return el.css3Animate(opts);
1458
+ },
1459
+ /**
1460
+ * This is the time transitions will run for.
1461
+ ```
1462
+ $.ui.transitionTime='400ms';
1463
+ ```
1464
+ * @title $.ui.transitionTime;
1465
+ */
1466
+ transitionTime:"500",
1467
+ /**
1468
+ * this is a boolean when set to true (default) it will load that panel when the app is started
1469
+ ```
1470
+ $.ui.loadDefaultHash=false; //Never load the page from the hash when the app is started
1471
+ $.ui.loadDefaultHash=true; //Default
1472
+ ```
1473
+ *@title $.ui.loadDefaultHash
1474
+ */
1475
+ loadDefaultHash: true,
1476
+
1477
+ /**
1478
+ * This is a boolean that when set to true will add "&cache=_rand_" to any ajax loaded link
1479
+ ```
1480
+ $.ui.useAjaxCacheBuster=true;
1481
+ ```
1482
+ *@title $.ui.useAjaxCacheBuster
1483
+ */
1484
+ useAjaxCacheBuster: false,
1485
+ /**
1486
+ * This is a shorthand call to the jq.actionsheet plugin. We wire it to the jQUi div automatically
1487
+ ```
1488
+ $.ui.actionsheet("<a href='javascript:;' class='button'>Settings</a> <a href='javascript:;' class='button red'>Logout</a>")
1489
+ $.ui.actionsheet("[{
1490
+ text: 'back',
1491
+ cssClasses: 'red',
1492
+ handler: function () { $.ui.goBack(); ; }
1493
+ }, {
1494
+ text: 'show alert 5',
1495
+ cssClasses: 'blue',
1496
+ handler: function () { alert("hi"); }
1497
+ }, {
1498
+ text: 'show alert 6',
1499
+ cssClasses: '',
1500
+ handler: function () { alert("goodbye"); }
1501
+ }]");
1502
+ ```
1503
+ * @param {String,Array} links
1504
+ * @title $.ui.actionsheet()
1505
+ */
1506
+ actionsheet: function(opts) {
1507
+ el = jq("#jQUi");
1508
+ if (!el.__proto__["actionsheet"])
1509
+ throw "actionsheet plugin is required";
1510
+ return el.actionsheet(opts);
1511
+ },
1512
+ /**
1513
+ * This is a wrapper to jq.popup.js plugin. If you pass in a text string, it acts like an alert box and just gives a message
1514
+ ```
1515
+ $.ui.popup(opts);
1516
+ $.ui.popup( {
1517
+ title:"Alert! Alert!",
1518
+ message:"This is a test of the emergency alert system!! Don't PANIC!",
1519
+ cancelText:"Cancel me",
1520
+ cancelCallback: function(){console.log("cancelled");},
1521
+ doneText:"I'm done!",
1522
+ doneCallback: function(){console.log("Done for!");},
1523
+ cancelOnly:false
1524
+ });
1525
+ $.ui.popup('Hi there');
1526
+ ```
1527
+ * @param {Object|String} options
1528
+ * @title $.ui.popup(opts)
1529
+ */
1530
+ popup: function(opts) {
1531
+ el = jq("#jQUi");
1532
+ if (!el.__proto__["popup"])
1533
+ throw "popup plugin is required";
1534
+ return el.popup(opts);
1535
+ },
1536
+
1537
+ /**
1538
+ *This will throw up a mask and block the UI
1539
+ ```
1540
+ $.ui.blockUI(.9)
1541
+ ````
1542
+ * @param {Float} opacity
1543
+ * @title $.ui.blockUI(opacity)
1544
+ */
1545
+ blockUI: function(opacity) {
1546
+ $.blockUI(opacity);
1547
+ },
1548
+ /**
1549
+ *This will remove the UI mask
1550
+ ```
1551
+ $.ui.unblockUI()
1552
+ ````
1553
+ * @title $.ui.unblockUI()
1554
+ */
1555
+ unblockUI: function() {
1556
+ $.unblockUI();
1557
+ },
1558
+ /**
1559
+ * Will remove the bottom nav bar menu from your application
1560
+ ```
1561
+ $.ui.removeFooterMenu();
1562
+ ```
1563
+ * @title $.ui.removeFooterMenu
1564
+ */
1565
+ removeFooterMenu: function() {
1566
+ jq("#navbar").hide();
1567
+ jq("#content").css("bottom", "0px");
1568
+ this.showNavMenu = false;
1569
+ },
1570
+ /**
1571
+ * Boolean if you want to show the bottom nav menu.
1572
+ ```
1573
+ $.ui.showNavMenu = false;
1574
+ ```
1575
+ * @title $.ui.showNavMenu
1576
+ */
1577
+ showNavMenu: true,
1578
+ /**
1579
+ * Boolean if you want to auto launch jqUi
1580
+ ```
1581
+ $.ui.autoLaunch = false; //
1582
+ * @title $.ui.autoLaunch
1583
+ */
1584
+ autoLaunch: true,
1585
+ /**
1586
+ * Boolean if you want to show the back button
1587
+ ```
1588
+ $.ui.showBackButton = false; //
1589
+ * @title $.ui.showBackButton
1590
+ */
1591
+ showBackbutton: true,
1592
+ /**
1593
+ * @api private
1594
+ */
1595
+ backButtonText: "",
1596
+ /**
1597
+ * Boolean if you want to reset the scroller position when navigating panels. Default is true
1598
+ ```
1599
+ $.ui.resetScrollers=false; //Do not reset the scrollers when switching panels
1600
+ ```
1601
+ * @title $.ui.resetScrollers
1602
+ */
1603
+ resetScrollers: true,
1604
+ /**
1605
+ * function to fire when jqUi is ready and completed launch
1606
+ ```
1607
+ $.ui.ready(function(){console.log('jqUi is ready');});
1608
+ ```
1609
+ * @param {Function} function to execute
1610
+ * @title $.ui.ready
1611
+ */
1612
+ ready: function(param) {
1613
+ if (this.launchCompleted)
1614
+ param();
1615
+ else
1616
+ document.addEventListener("jq.ui.ready", param, false);
1617
+ },
1618
+ /**
1619
+ * Override the back button class name
1620
+ ```
1621
+ $.ui.setBackButtonStyle('newClass');
1622
+ ```
1623
+ * @param {String} new class name
1624
+ * @title $.ui.setBackButtonStyle(class)
1625
+ */
1626
+ setBackButtonStyle: function(className) {
1627
+ $am("backButton").className = className;
1628
+ },
1629
+ /**
1630
+ * Initiate a back transition
1631
+ ```
1632
+ $.ui.goBack()
1633
+ ```
1634
+
1635
+ * @title $.ui.goBack()
1636
+ */
1637
+ goBack: function() {
1638
+
1639
+ if (this.history.length > 0) {
1640
+ var tmpEl = this.history.pop();
1641
+ this.loadContent(tmpEl.target + "", 0, 1, tmpEl.transition);
1642
+ this.transitionType = tmpEl.transition;
1643
+ }
1644
+ },
1645
+ /**
1646
+ * Clear the history queue
1647
+ ```
1648
+ $.ui.clearHistory()
1649
+ ```
1650
+
1651
+ * @title $.ui.clearHistory()
1652
+ */
1653
+ clearHistory: function() {
1654
+ this.history = [];
1655
+ this.backButton.style.visibility = "hidden";
1656
+ },
1657
+ /**
1658
+ * Update a badge on the selected target. Position can be
1659
+ bl = bottom left
1660
+ tl = top left
1661
+ br = bottom right
1662
+ tr = top right (default)
1663
+ ```
1664
+ $.ui.updateBadge('#mydiv','3','bl','green');
1665
+ ```
1666
+ * @param {String} target
1667
+ * @param {String} Value
1668
+ * @param {String} [position]
1669
+ * @param {String|Object} [color or CSS hash]
1670
+ * @title $.ui.updateBadge(target,value,[position],[color])
1671
+ */
1672
+ updateBadge: function(target, value, position,color) {
1673
+ if (position === undefined)
1674
+ position = "";
1675
+ if (target[0] != "#")
1676
+ target = "#" + target;
1677
+ var badge = jq(target).find("span.jq-badge");
1678
+
1679
+ if (badge.length == 0) {
1680
+ if (jq(target).css("position") != "absolute")
1681
+ jq(target).css("position", "relative");
1682
+ badge=jq("<span class='jq-badge " + position + "'>" + value + "</span>");
1683
+ jq(target).append(badge);
1684
+ } else
1685
+ badge.html(value);
1686
+
1687
+
1688
+ if(jq.isObject(color)){
1689
+ badge.css(color);
1690
+ }
1691
+ else if(color){
1692
+ badge.css("background",color);
1693
+ }
1694
+
1695
+ badge.data("ignore-pressed","true");
1696
+
1697
+ },
1698
+ /**
1699
+ * Removes a badge from the selected target.
1700
+ ```
1701
+ $.ui.removeBadge('#mydiv');
1702
+ ```
1703
+ * @param {String} target
1704
+ * @title $.ui.removeBadge(target)
1705
+ */
1706
+ removeBadge: function(target) {
1707
+ jq(target).find("span.jq-badge").remove();
1708
+ },
1709
+ /**
1710
+ * Toggles the bottom nav nav menu. Force is a boolean to force show or hide.
1711
+ ```
1712
+ $.ui.toggleNavMenu();//toggle it
1713
+ $.ui.toggleNavMenu(true); //force show it
1714
+ ```
1715
+ * @param {Boolean} [force]
1716
+ * @title $.ui.toggleNavMenu([force])
1717
+ */
1718
+ toggleNavMenu: function(force) {
1719
+ if (!jq.ui.showNavMenu)
1720
+ return;
1721
+ if (jq("#navbar").css("display") != "none" && ((force !== undefined && force !== true) || force === undefined)) {
1722
+ jq("#content").css("bottom", "0px");
1723
+ jq("#navbar").hide();
1724
+ } else if (force === undefined || (force !== undefined && force === true)) {
1725
+ jq("#navbar").show();
1726
+ jq("#content").css("bottom", jq("#navbar").css("height"));
1727
+
1728
+ }
1729
+ },
1730
+ /**
1731
+ * Toggles the top header menu.
1732
+ ```
1733
+ $.ui.toggleHeaderMenu();//toggle it
1734
+ ```
1735
+ * @param {Boolean} [force]
1736
+ * @title $.ui.toggleHeaderMenu([force])
1737
+ */
1738
+ toggleHeaderMenu: function(force) {
1739
+
1740
+ if (jq("#header").css("display") != "none" && ((force !== undefined && force !== true) || force === undefined)) {
1741
+ jq("#content").css("top", "0px");
1742
+ jq("#header").hide();
1743
+ } else if (force === undefined || (force !== undefined && force === true)) {
1744
+ jq("#header").show();
1745
+ jq("#content").css("top", jq("#header").css("height"));
1746
+
1747
+ }
1748
+ },
1749
+ /**
1750
+ * Toggles the side menu. Force is a boolean to force show or hide.
1751
+ ```
1752
+ $.ui.toggleSideMenu();//toggle it
1753
+ ```
1754
+ * @param {Boolean} [force]
1755
+ * @title $.ui.toggleSideMenu([force])
1756
+ */
1757
+ toggleSideMenu: function(force) {
1758
+ var that = this;
1759
+ if (!jq("#content").hasClass("hasMenu"))
1760
+ return;
1761
+ if (jq("#menu").css("display") != "block" && ((force !== undefined && force !== false) || force === undefined)) {
1762
+ this.scrollingDivs["menu_scroller"].initEvents();
1763
+ jq("#menu").show();
1764
+ window.setTimeout(function() {
1765
+ jq("#menu").addClass("on");
1766
+ jq("#header").addClass("on");
1767
+ jq("#navbar").addClass("on");
1768
+ jq("#content").addClass("on");
1769
+ }, 1); //needs to run after
1770
+
1771
+ } else if (force === undefined || (force !== undefined && force === false)) {
1772
+ this.scrollingDivs["menu_scroller"].removeEvents();
1773
+
1774
+ jq("#header").removeClass("on");
1775
+ jq("#menu").removeClass("on");
1776
+ jq("#navbar").removeClass("on");
1777
+ jq("#content").removeClass("on");
1778
+ setTimeout(function() {
1779
+ jq("#menu").hide();
1780
+ }, 300); //lame I know
1781
+ }
1782
+ },
1783
+ /**
1784
+ * depricated
1785
+ ```
1786
+ $.ui.updateNavbar();//toggle it
1787
+ ```
1788
+ * @title $.ui.updateNavbar([force])
1789
+ * @api private
1790
+ */
1791
+ updateNavbar: function() {
1792
+ },
1793
+ /**
1794
+ * Updates the elements in the navbar
1795
+ ```
1796
+ $.ui.updateNavbarElements(elements);
1797
+ ```
1798
+ * @param {String|Object} Elements
1799
+ * @title $.ui.updateNavbarElements(Elements)
1800
+ */
1801
+ updateNavbarElements: function(elems) {
1802
+ var nb = jq("#navbar");
1803
+ if (elems === undefined || elems == null)
1804
+ return;
1805
+ if (typeof (elems) == "string")
1806
+ return nb.html(elems), null;
1807
+ nb.html("");
1808
+ for (var i = 0; i < elems.length; i++) {
1809
+ var node = elems[i].cloneNode(true);
1810
+ nb.append(node);
1811
+ }
1812
+ jq("#navbar a").data("ignore-pressed", "true").data("resetHistory", "true");
1813
+ },
1814
+ /**
1815
+ * Updates the elements in the header
1816
+ ```
1817
+ $.ui.updateHeaderElements(elements);
1818
+ ```
1819
+ * @param {String|Object} Elements
1820
+ * @title $.ui.updateHeaderElement(Elements)
1821
+ */
1822
+ updateHeaderElements: function(elems) {
1823
+ var nb = jq("#header");
1824
+ if (elems === undefined || elems == null)
1825
+ return;
1826
+ if (typeof (elems) == "string")
1827
+ return nb.html(elems), null;
1828
+ nb.html("");
1829
+ for (var i = 0; i < elems.length; i++) {
1830
+ var node = elems[i].cloneNode(true);
1831
+ nb.append(node);
1832
+ }
1833
+ },
1834
+
1835
+ /**
1836
+ * Updates the elements in the side menu
1837
+ ```
1838
+ $.ui.updateSideMenu(elements);
1839
+ ```
1840
+ * @param {String|Object} Elements
1841
+ * @title $.ui.updateSideMenu(Elements)
1842
+ */
1843
+ updateSideMenu: function(elems) {
1844
+ var that = this;
1845
+
1846
+ var nb = jq("#menu_scroller");
1847
+
1848
+ if (elems === undefined || elems == null)
1849
+ return;
1850
+ if (typeof (elems) == "string")
1851
+ return nb.html(elems), null;
1852
+ nb.html('');
1853
+ var close = document.createElement("a");
1854
+ close.className = "closebutton jqMenuClose";
1855
+ close.href = "javascript:;"
1856
+ close.onclick = function() {
1857
+ that.toggleSideMenu();
1858
+ };
1859
+ nb.append(close);
1860
+ var tmp = document.createElement("div");
1861
+ tmp.className = "jqMenuHeader";
1862
+ tmp.innerHTML = "Menu";
1863
+ nb.append(tmp);
1864
+ for (var i = 0; i < elems.length; i++) {
1865
+ var node = elems[i].cloneNode(true);
1866
+ if (elems[i].oldhash) {
1867
+ node.href = elems[i].oldhref;
1868
+ node.onclick = elems[i].oldonclick;
1869
+ }
1870
+ nb.append(node);
1871
+ }
1872
+ //Move the scroller to the top and hide it
1873
+ this.scrollingDivs['menu_scroller'].scrollTo({
1874
+ x: 0,
1875
+ y: 0
1876
+ }, "0");
1877
+ },
1878
+ /**
1879
+ * Set the title of the current panel
1880
+ ```
1881
+ $.ui.setTitle("new title");
1882
+ ```
1883
+
1884
+ * @param {String} value
1885
+ * @title $.ui.setTitle(value)
1886
+ */
1887
+ setTitle: function(val) {
1888
+ jq("#header #pageTitle").html(val);
1889
+ },
1890
+ /**
1891
+ * Override the text for the back button
1892
+ ```
1893
+ $.ui.setBackButtonText("GO...");
1894
+ ```
1895
+
1896
+ * @param {String} value
1897
+ * @title $.ui.setBackButtonText(value)
1898
+ */
1899
+ setBackButtonText: function(text) {
1900
+ if (this.backButtonText.length > 0)
1901
+ jq("#header #backButton").html(this.backButtonText);
1902
+ else
1903
+ jq("#header #backButton").html(text);
1904
+ },
1905
+ /**
1906
+ * Show the loading mask
1907
+ ```
1908
+ $.ui.showMask()
1909
+ $.ui.showMask(;Doing work')
1910
+ ```
1911
+
1912
+ * @param {String} [text]
1913
+ * @title $.ui.showMask(text);
1914
+ */
1915
+ showMask: function(text) {
1916
+ if (!text)
1917
+ text = "Loading Content";
1918
+ jq("#jQui_mask>h1").html(text);
1919
+ $am("jQui_mask").style.display = "block";
1920
+ },
1921
+ /**
1922
+ * Hide the loading mask
1923
+ * @title $.ui.hideMask();
1924
+ */
1925
+ hideMask: function() {
1926
+ $am("jQui_mask").style.display = "none";
1927
+ },
1928
+ /**
1929
+ * Load a content panel in a modal window. We set the innerHTML so event binding will not work.
1930
+ ```
1931
+ $.ui.showModal("#myDiv");
1932
+ ```
1933
+ * @param {String|Object} panel to show
1934
+ * @title $.ui.showModal();
1935
+ */
1936
+ showModal: function(id) {
1937
+ var that = this;
1938
+
1939
+ if ($am(id)) {
1940
+ //jq("#modalContainer").html('<div style="width:1px;height:1px;-webkit-transform:translate3d(0,0,0);float:right"></div>' + $am(id).childNodes[0].innerHTML + '');
1941
+ jq("#modalContainer").html($am(id).childNodes[0].innerHTML);
1942
+ jq('#modalContainer').append("<a href='javascript:;' onclick='$.ui.hideModal();' class='closebutton modalbutton'></a>");
1943
+ this.modalWindow.style.display = "block";
1944
+
1945
+ button = null;
1946
+ content = null;
1947
+ this.scrollingDivs['modal_container'].initEvents();
1948
+ this.scrollToTop('modal');
1949
+ }
1950
+
1951
+ },
1952
+ /**
1953
+ * Hide the modal window and remove the content
1954
+ ```
1955
+ $.ui.hideModal("#myDiv");
1956
+ ```
1957
+ * @title $.ui.hideModal();
1958
+ */
1959
+ hideModal: function() {
1960
+ $am("modalContainer").innerHTML = "";
1961
+ $am("jQui_modal").style.display = "none";
1962
+
1963
+ this.scrollingDivs['modal_container'].removeEvents();
1964
+ },
1965
+
1966
+ /**
1967
+ * Update the HTML in a content panel
1968
+ ```
1969
+ $.ui.updateContentDiv("#myDiv","This is the new content");
1970
+ ```
1971
+ * @param {String,Object} panel
1972
+ * @param {String} html to update with
1973
+ * @title $.ui.updateContentDiv(id,content);
1974
+ */
1975
+ updateContentDiv: function(id, content) {
1976
+ var el = $am(id);
1977
+ if (!el)
1978
+ return;
1979
+
1980
+ var newDiv = document.createElement("div");
1981
+ newDiv.innerHTML = content;
1982
+ if($(newDiv).children('.panel') && $(newDiv).children('.panel').length > 0) newDiv = $(newDiv).children('.panel').get();
1983
+
1984
+
1985
+
1986
+ if (el.getAttribute("scrolling") && el.getAttribute("scrolling").toLowerCase() == "no")
1987
+ el.innerHTML = newDiv.innerHTML;
1988
+ else
1989
+ el.childNodes[0].innerHTML = newDiv.innerHTML;
1990
+
1991
+ if($(newDiv).title) el.title = $(newDiv).title;
1992
+ },
1993
+ /**
1994
+ * Dynamically create a new panel on the fly. It wires events, creates the scroller, applies Android fixes, etc.
1995
+ ```
1996
+ $.ui.addContentDiv("myDiv","This is the new content","Title");
1997
+ ```
1998
+ * @param {String|Object} Element to add
1999
+ * @param {String} Content
2000
+ * @param {String} title
2001
+ * @title $.ui.addContentDiv(id,content,title);
2002
+ */
2003
+ addContentDiv: function(el, content, title, refresh, refreshFunc) {
2004
+ var myEl = $am(el);
2005
+ if (!myEl) {
2006
+ var newDiv = document.createElement("div");
2007
+ newDiv.innerHTML = content;
2008
+ if($(newDiv).children('.panel') && $(newDiv).children('.panel').length > 0) newDiv = $(newDiv).children('.panel').get();
2009
+
2010
+ if(!newDiv.title&&title) newDiv.title = title;
2011
+ var newId = (newDiv.id)? newDiv.id : el; //figure out the new id - either the id from the loaded div.panel or the crc32 hash
2012
+ newDiv.id = newId;
2013
+ } else {
2014
+ newDiv = myEl;
2015
+ }
2016
+ newDiv.className = "panel";
2017
+ var that = this;
2018
+
2019
+ myEl = null;
2020
+ that.addDivAndScroll(newDiv, refresh, refreshFunc);
2021
+ newDiv = null;
2022
+ return newId;
2023
+ },
2024
+ /**
2025
+ * Takes a div and sets up scrolling for it..
2026
+ ```
2027
+ $.ui.addDivAndScroll(object);
2028
+ ```
2029
+ * @param {Object} Element
2030
+ * @title $.ui.addDivAndScroll(element);
2031
+ * @api private
2032
+ */
2033
+ addDivAndScroll: function(tmp, refreshPull, refreshFunc) {
2034
+ var addScroller = true;
2035
+ if (tmp.getAttribute("scrolling") && tmp.getAttribute("scrolling").toLowerCase() == "no")
2036
+ addScroller = false;
2037
+ if (!addScroller) {
2038
+ this.content.appendChild(tmp);
2039
+ tmp = null;
2040
+ return;
2041
+ }
2042
+ //WE need to clone the div so we keep events
2043
+ var myDiv = tmp.cloneNode(false);
2044
+
2045
+
2046
+ tmp.title = null;
2047
+ tmp.id = null;
2048
+ tmp.removeAttribute("footer");
2049
+ tmp.removeAttribute("nav");
2050
+ jq(tmp).removeClass("panel");
2051
+ tmp.style.width = "100%";
2052
+ //tmp.style.height = "inherit";
2053
+
2054
+ myDiv.appendChild(tmp);
2055
+
2056
+ this.content.appendChild(myDiv);
2057
+
2058
+ this.selectBox.getOldSelects(myDiv.id);
2059
+ this.passwordBox.getOldPasswords(myDiv.id);
2060
+
2061
+ if (addScroller) {
2062
+ this.scrollingDivs[myDiv.id] = (jq(tmp).scroller({
2063
+ scrollBars: true,
2064
+ verticalScroll: true,
2065
+ horizontalScroll: false,
2066
+ vScrollCSS: "jqmScrollbar",
2067
+ refresh: false
2068
+ }));
2069
+ this.scrollingDivs[myDiv.id].removeEvents();
2070
+ }
2071
+
2072
+
2073
+ myDiv = null;
2074
+ tmp = null;
2075
+ },
2076
+
2077
+ /**
2078
+ * This has been depricated, as it was a design flaw on my end. People were updating segments of the panel and not the whole part. It's counter intuitive to have to call
2079
+ * $.ui.updateAnchors(object,reset) after each change.
2080
+ * This will be removed in 1.1
2081
+ * @title $.ui.updateAnchors(element,resetHistory);
2082
+ * @api private
2083
+ */
2084
+ updateAnchors: function(domEl, reset) {
2085
+ },
2086
+ /**
2087
+ * Scrolls a panel to the top
2088
+ ```
2089
+ $.ui.scrollToTop(id);
2090
+ ```
2091
+ * @param {String} id without hash
2092
+ * @title $.ui.scrollToTop(id);
2093
+ */
2094
+ scrollToTop: function(id) {
2095
+ if (this.scrollingDivs[id]) {
2096
+ this.scrollingDivs[id].scrollTo({
2097
+ x: 0,
2098
+ y: 0
2099
+ }, 0);
2100
+ }
2101
+ },
2102
+ /**
2103
+ * Scrolls all panels to the top and fixes position when orientation changes
2104
+ ```
2105
+ $.ui.updateOrientation(event);
2106
+ ```
2107
+ * @param {Event} event
2108
+ * @title $.ui.updateOrientation(event);
2109
+ * @api private
2110
+ */
2111
+ updateOrientation: function(event) {
2112
+ for (var j in this.scrollingDivs) {
2113
+ if (typeof (this.scrollingDivs[j]) !== "function")
2114
+ this.scrollToTop(j);
2115
+ }
2116
+ },
2117
+
2118
+ /**
2119
+ * This is used when a transition fires to do helper events. We check to see if we need to change the nav menus, footer, and fire
2120
+ * the load/onload functions for panels
2121
+ ```
2122
+ $.ui.parsePanelFunctions(currentDiv,oldDiv);
2123
+ ```
2124
+ * @param {Object} current div
2125
+ * @param {Object} old div
2126
+ * @title $.ui.parsePanelFunctions(currentDiv,oldDiv);
2127
+ * @api private
2128
+ */
2129
+ parsePanelFunctions: function(what, oldDiv) {
2130
+ var that = this;
2131
+ var hasFooter = what.getAttribute("data-footer");
2132
+ var hasHeader = what.getAttribute("data-header");
2133
+ window.setTimeout(function() {
2134
+ if (hasFooter && hasFooter.toLowerCase() == "none") {
2135
+ that.toggleNavMenu(false);
2136
+ } else {
2137
+ that.toggleNavMenu(true);
2138
+ }
2139
+ if (hasFooter && that.customFooter != hasFooter) {
2140
+ that.customFooter = hasFooter;
2141
+ that.updateNavbarElements(jq("#" + hasFooter).children());
2142
+ } else if (hasFooter != that.customFooter) {
2143
+ if (that.customFooter)
2144
+ that.updateNavbarElements(that.defaultFooter);
2145
+ that.customFooter = false;
2146
+ }
2147
+
2148
+
2149
+ if (hasHeader && that.customHeader != hasHeader) {
2150
+ that.customHeader = hasHeader;
2151
+ that.updateHeaderElements(jq("#" + hasHeader).children());
2152
+ } else if (hasHeader != that.customHeader) {
2153
+ if (that.customHeader)
2154
+ {
2155
+ that.updateHeaderElements(that.defaultHeader);
2156
+ that.setTitle(that.activeDiv.title);
2157
+ }
2158
+ that.customHeader = false;
2159
+ }
2160
+
2161
+ //Load inline footers
2162
+ var inlineFooters = $(what).find("footer");
2163
+ if (inlineFooters.length > 0)
2164
+ {
2165
+ that.customFooter = what.id;
2166
+ that.updateNavbarElements(inlineFooters.children());
2167
+ }
2168
+ //load inline headers
2169
+ var inlineHeader = $(what).find("header");
2170
+
2171
+
2172
+ if (inlineHeader.length > 0)
2173
+ {
2174
+ that.customHeader = what.id;
2175
+ that.updateHeaderElements(inlineHeader.children());
2176
+ }
2177
+ //check if the panel has a footer
2178
+ if (what.getAttribute("data-tab")) { //Allow the dev to force the footer menu
2179
+
2180
+ jq("#navbar a").removeClass("selected");
2181
+ jq("#navbar #" + what.getAttribute("data-tab")).addClass("selected");
2182
+ }
2183
+ var hasMenu = what.getAttribute("data-nav");
2184
+ if (hasMenu && that.customMenu != hasMenu) {
2185
+ that.customMenu = hasMenu;
2186
+ that.updateSideMenu(jq("#" + hasMenu).children());
2187
+ } else if (hasMenu != that.customMenu) {
2188
+ if (that.customMenu)
2189
+ that.updateSideMenu(that.defaultMenu);
2190
+ that.customMenu = false;
2191
+ }
2192
+
2193
+ }, 10);
2194
+
2195
+
2196
+
2197
+ //Fire unload first
2198
+ if (oldDiv) {
2199
+ fnc = oldDiv.getAttribute("data-unload");
2200
+ if (typeof fnc == "string" && window[fnc]) {
2201
+ window[fnc](oldDiv);
2202
+ }
2203
+ }
2204
+ var fnc = what.getAttribute("data-load");
2205
+ if (typeof fnc == "string" && window[fnc]) {
2206
+ window[fnc](what);
2207
+ }
2208
+ if (this.menu.style.display == "block")
2209
+ this.toggleSideMenu(); //Close on phones to prevent orientation change bug.
2210
+
2211
+ },
2212
+ /**
2213
+ * Helper function that parses a contents html for any script tags and either adds them or executes the code
2214
+ * @api private
2215
+ */
2216
+ parseScriptTags: function(div) {
2217
+ if (!div)
2218
+ return;
2219
+ var scripts = div.getElementsByTagName("script");
2220
+ div = null;
2221
+ for (var i = 0; i < scripts.length; i++) {
2222
+ if (scripts[i].src.length > 0 && !this.remoteJSPages[scripts[i].src]) {
2223
+ var doc = document.createElement("script");
2224
+ doc.type = scripts[i].type;
2225
+ doc.src = scripts[i].src;
2226
+ document.getElementsByTagName('head')[0].appendChild(doc);
2227
+ this.remoteJSPages[scripts[i].src] = 1;
2228
+ doc = null;
2229
+ } else {
2230
+ window.eval(scripts[i].innerHTML);
2231
+ }
2232
+ }
2233
+ },
2234
+ /**
2235
+ * This is called to initiate a transition or load content via ajax.
2236
+ * We can pass in a hash+id or URL and then we parse the panel for additional functions
2237
+ ```
2238
+ $.ui.loadContent("#main",false,false,"up");
2239
+ ```
2240
+ * @param {String} target
2241
+ * @param {Boolean} newtab (resets history)
2242
+ * @param {Boolean} go back (initiate the back click)
2243
+ * @param {String} transition
2244
+ * @title $.ui.loadContent(target,newTab,goBack,transition);
2245
+ * @api public
2246
+ */
2247
+ loadContent: function(target, newTab, back, transition, anchor) {
2248
+
2249
+ if (this.doingTransition)
2250
+ return;
2251
+
2252
+
2253
+ what = null;
2254
+ var that = this;
2255
+ that.hideMask();
2256
+ var loadAjax = true;
2257
+ if (target.indexOf("#") == -1) {
2258
+ var urlHash = "url" + crc32(target); //Ajax urls
2259
+ if ($am(urlHash)) {
2260
+
2261
+ //ajax div already exists. Let's see if we should be refreshing it.
2262
+ loadAjax = false;
2263
+ if ((anchor && anchor.getAttribute("data-refresh-ajax") === 'true') || (anchor && anchor.refresh && anchor.refresh === true)||this.isAjaxApp) {
2264
+ loadAjax = true;
2265
+ } else
2266
+ target = "#" + urlHash;
2267
+ }
2268
+ }
2269
+
2270
+ if (target.indexOf("#") == -1 && anchor && loadAjax) {
2271
+
2272
+ // XML Request
2273
+ if (this.activeDiv.id == "jQui_ajax" && target == this.ajaxUrl)
2274
+ return;
2275
+ if (target.indexOf("http") == -1)
2276
+ target = AppMobi.webRoot + target;
2277
+
2278
+ var xmlhttp = new XMLHttpRequest();
2279
+ xmlhttp.onreadystatechange = function() {
2280
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
2281
+ this.doingTransition = false;
2282
+
2283
+ var doReturn = false;
2284
+
2285
+ //Here we check to see if we are retaining the div, if so update it
2286
+ if ($am(urlHash) !== undefined) {
2287
+ that.updateContentDiv(urlHash, xmlhttp.responseText);
2288
+ if(!$am(urlHash).title) $am(urlHash).title = anchor.title ? anchor.title : target;
2289
+ } else if (that.isAjaxApp || anchor.getAttribute("data-persist-ajax")) {
2290
+ var refresh = (anchor.getAttribute("data-pull-scroller") === 'true') ? true : false;
2291
+ refreshFunction = refresh ?
2292
+ function() {
2293
+ anchor.refresh = true;
2294
+ that.loadContent(target, newTab, back, transition, anchor);
2295
+ anchor.refresh = false;
2296
+ } : null
2297
+ that.addContentDiv(urlHash, xmlhttp.responseText,anchor.title ? anchor.title : target, refresh, refreshFunction);
2298
+ } else {
2299
+ that.updateContentDiv("jQui_ajax", xmlhttp.responseText);
2300
+ $am("jQui_ajax").title = anchor.title ? anchor.title : target;
2301
+ that.loadContent("#jQui_ajax", newTab, back);
2302
+ doReturn = true;
2303
+ }
2304
+ //Let's load the content now.
2305
+ //We need to check for any script tags and handle them
2306
+ var div = document.createElement("div");
2307
+ div.innerHTML = xmlhttp.responseText;
2308
+ that.parseScriptTags(div);
2309
+ if (doReturn)
2310
+ return;
2311
+ return that.loadContent("#" + urlHash, false, back, null);
2312
+
2313
+ }
2314
+ };
2315
+ ajaxUrl = target;
2316
+ var newtarget = this.useAjaxCacheBuster ? target + (target.split('?')[1] ? '&' : '?') + "cache=" + Math.random() * 10000000000000000 : target;
2317
+ xmlhttp.open("GET", newtarget, true);
2318
+ xmlhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
2319
+ xmlhttp.send();
2320
+ // show Ajax Mask
2321
+ if(this.showLoading)
2322
+ this.showMask();
2323
+ return;
2324
+ } else {
2325
+ // load a div
2326
+
2327
+ what = target.replace("#", "");
2328
+
2329
+ var slashIndex = what.indexOf('/');
2330
+ var hashLink = "";
2331
+ if (slashIndex != -1) {
2332
+ // Ignore everything after the slash for loading
2333
+ hashLink = what.substr(slashIndex);
2334
+ what = what.substr(0, slashIndex);
2335
+ }
2336
+
2337
+ what = $am(what);
2338
+
2339
+ if (!what)
2340
+ throw ("Target: " + target + " was not found");
2341
+ if (what == this.activeDiv && !back)
2342
+ return;
2343
+
2344
+ if (what.getAttribute("data-modal") == "true" || what.getAttribute("modal") == "true") {
2345
+ return this.showModal(what.id);
2346
+ }
2347
+
2348
+
2349
+
2350
+ this.transitionType = transition;
2351
+ var oldDiv = this.activeDiv;
2352
+ var currWhat = what;
2353
+
2354
+
2355
+ if (oldDiv == currWhat) //prevent it from going to itself
2356
+ return;
2357
+
2358
+ if (newTab) {
2359
+
2360
+ this.history = [];
2361
+ if(("#" + this.firstDiv.id)!=target){
2362
+ this.history.push({
2363
+ target: "#" + this.firstDiv.id,
2364
+ transition: transition
2365
+ });
2366
+ }
2367
+ } else if (!back) {
2368
+ this.history.push({
2369
+ target: previousTarget,
2370
+ transition: transition
2371
+ });
2372
+
2373
+ }
2374
+ window.history.pushState(what.id, what.id, startPath + '#' + what.id + hashLink);
2375
+ $(window).trigger("hashchange", {newUrl: startPath + '#' + what.id + hashLink,oldURL: startPath + "#" + this.activeDiv.id});
2376
+
2377
+ previousTarget = '#' + what.id + hashLink;
2378
+
2379
+ if (this.resetScrollers && this.scrollingDivs[what.id]) {
2380
+ this.scrollingDivs[what.id].scrollTo({
2381
+ x: 0,
2382
+ y: 0
2383
+ });
2384
+ }
2385
+ $(what).addClass("active");
2386
+
2387
+ what.style.display = "block";
2388
+ that.doingTransition = true;
2389
+ if (that.availableTransitions[transition])
2390
+ that.availableTransitions[transition].call(that, oldDiv, currWhat, back);
2391
+ else
2392
+ that.availableTransitions['default'].call(that, oldDiv, currWhat, back);
2393
+
2394
+
2395
+
2396
+ this.activeDiv = what;
2397
+
2398
+ if (this.scrollingDivs[this.activeDiv.id]) {
2399
+ this.scrollingDivs[this.activeDiv.id].initEvents();
2400
+ }
2401
+ if (this.scrollingDivs[oldDiv.id]) {
2402
+ this.scrollingDivs[oldDiv.id].removeEvents();
2403
+ }
2404
+ //Let's check if it has a function to run to update the data
2405
+
2406
+
2407
+
2408
+ setTimeout(function(){
2409
+ that.parsePanelFunctions(what, oldDiv);
2410
+ },300);
2411
+ setTimeout(function(){
2412
+
2413
+ if (back) {
2414
+ if (that.history.length > 0) {
2415
+ var val = that.history[that.history.length - 1];
2416
+
2417
+ var el = $am(val.target.replace("#", ""));
2418
+ that.setBackButtonText(el.title)
2419
+ }
2420
+ } else if (that.activeDiv.title)
2421
+ that.setBackButtonText(that.activeDiv.title)
2422
+ else
2423
+ that.setBackButtonText("Back");
2424
+ if (what.title) {
2425
+ that.setTitle(what.title);
2426
+ }
2427
+ if (newTab) {
2428
+ that.setBackButtonText(that.firstDiv.title)
2429
+ }
2430
+
2431
+ //Update the back buttons
2432
+ if (that.history.length == 0) {
2433
+ jq("#header #backButton").css("visibility","hidden");
2434
+ that.history = [];
2435
+ } else if (that.showBackbutton){
2436
+ jq("#header #backButton").css("visibility","visible");
2437
+ }
2438
+ },370);
2439
+ window.scrollTo(1, 1);
2440
+
2441
+ }
2442
+ },
2443
+
2444
+ /**
2445
+ * This is callled when you want to launch jqUi. If autoLaunch is set to true, it gets called on DOMContentLoaded.
2446
+ * If autoLaunch is set to false, you can manually invoke it.
2447
+ ```
2448
+ $.ui.autoLaunch=false;
2449
+ $.ui.launch();
2450
+ ```
2451
+ * @title $.ui.launch();
2452
+ */
2453
+ launch: function() {
2454
+
2455
+ if (this.hasLaunched == false || this.launchCompleted) {
2456
+ this.hasLaunched = true;
2457
+ return;
2458
+ }
2459
+ this.isAppMobi = (window.AppMobi && typeof (AppMobi) == "object" && AppMobi.app !== undefined) ? true : false;
2460
+ var that = this;
2461
+ this.viewportContainer = jq("#jQUi");
2462
+ this.navbar = $am("navbar");
2463
+ this.content = $am("content");
2464
+ this.header = $am("header");
2465
+ this.menu = $am("menu");
2466
+ if (this.viewportContainer.length == 0) {
2467
+ var container = document.createElement("div");
2468
+ container.id = "jQUi";
2469
+ var body = document.body;
2470
+ while (body.firstChild) {
2471
+ container.appendChild(body.firstChild);
2472
+ }
2473
+ jq(document.body).prepend(container);
2474
+ this.viewportContainer = jq("#jQUi");
2475
+ }
2476
+ if (!this.navbar) {
2477
+ this.navbar = document.createElement("div");
2478
+ this.navbar.id = "navbar";
2479
+ this.navbar.style.cssText = "display:none";
2480
+ this.viewportContainer.append(this.navbar);
2481
+ }
2482
+ if (!this.header) {
2483
+ this.header = document.createElement("div");
2484
+ this.header.id = "header";
2485
+ this.viewportContainer.prepend(this.header);
2486
+ }
2487
+ if (!this.menu) {
2488
+ this.menu = document.createElement("div");
2489
+ this.menu.id = "menu";
2490
+ this.menu.style.overflow = "hidden";
2491
+ this.menu.innerHTML = "<div id='menu_scroller'></div>";
2492
+ this.viewportContainer.append(this.menu);
2493
+ this.scrollingDivs["menu_scroller"] = jq("#menu_scroller").scroller({
2494
+ scrollBars: true,
2495
+ verticalScroll: true,
2496
+ vScrollCSS: "jqmScrollbar"
2497
+ });
2498
+ }
2499
+
2500
+
2501
+ if (!this.content) {
2502
+ this.content = document.createElement("div");
2503
+ this.content.id = "content";
2504
+ this.viewportContainer.append(this.content);
2505
+ }
2506
+ this.header.innerHTML = '<a id="backButton" href="javascript:;"></a> <h1 id="pageTitle"></h1>' + this.header.innerHTML;
2507
+ this.backButton = $am("backButton");
2508
+ this.backButton.className = "button";
2509
+
2510
+ jq(document).on("click", "#backButton", function() {
2511
+ that.goBack();
2512
+ });
2513
+ this.backButton.style.visibility = "hidden";
2514
+ this.addContentDiv("jQui_ajax", "");
2515
+ var maskDiv = document.createElement("div");
2516
+ maskDiv.id = "jQui_mask";
2517
+ maskDiv.className = "ui-loader";
2518
+ maskDiv.innerHTML = "<span class='ui-icon ui-icon-loading spin'></span><h1>Loading Content</h1>";
2519
+ maskDiv.style.zIndex = 20000;
2520
+ maskDiv.style.display = "none";
2521
+ document.body.appendChild(maskDiv);
2522
+ var modalDiv = document.createElement("div");
2523
+ modalDiv.id = "jQui_modal";
2524
+
2525
+ this.viewportContainer.append(modalDiv);
2526
+ modalDiv.appendChild(jq("<div id='modalContainer'></div>").get());
2527
+ this.scrollingDivs['modal_container'] = jq("#modalContainer").scroller({
2528
+ scrollBars: true,
2529
+ vertical: true,
2530
+ vScrollCSS: "jqmScrollbar"
2531
+ });
2532
+
2533
+ this.modalWindow = modalDiv;
2534
+ var defer = [];
2535
+ var contentDivs = this.viewportContainer.get().querySelectorAll(".panel");
2536
+ for (var i = 0; i < contentDivs.length; i++) {
2537
+ var el = contentDivs[i];
2538
+ var tmp = el;
2539
+ var id;
2540
+ if (el.parentNode && el.parentNode.id != "content") {
2541
+ el.parentNode.removeChild(el);
2542
+ var id = el.id;
2543
+ this.addDivAndScroll(tmp);
2544
+ if (tmp.getAttribute("selected"))
2545
+ this.firstDiv = $am(id);
2546
+ } else if (!el.parsedContent) {
2547
+ el.parsedContent = 1;
2548
+ el.parentNode.removeChild(el);
2549
+ var id = el.id;
2550
+ this.addDivAndScroll(tmp);
2551
+ if (tmp.getAttribute("selected"))
2552
+ this.firstDiv = $am(id);
2553
+ }
2554
+ if (el.getAttribute("data-defer")){
2555
+ defer[id] = el.getAttribute("data-defer");
2556
+ defer.length++;
2557
+ }
2558
+ el = null;
2559
+ }
2560
+ if(!this.firstDiv)
2561
+ this.firstDiv=$("#content").children().get(0);
2562
+ contentDivs = null;
2563
+ var loadingDefer=false;
2564
+ var toLoad=defer.length;
2565
+ if(toLoad>0){
2566
+ loadingDefer=true;
2567
+ var loaded=0;
2568
+ for (var j in defer) {
2569
+ (function(j) {
2570
+ jq.ajax({url:AppMobi.webRoot + defer[j], success:function(data) {
2571
+ if (data.length == 0)
2572
+ return;
2573
+ $.ui.updateContentDiv(j, data);
2574
+ that.parseScriptTags(jq(j).get());
2575
+ loaded++;
2576
+ if(loaded>=toLoad){
2577
+ $(document).trigger("defer:loaded");
2578
+ loadingDefer=false;
2579
+
2580
+ }
2581
+ },error:function(msg){
2582
+ //still trigger the file as being loaded to not block jq.ui.ready
2583
+ console.log("Error with deferred load "+AppMobi.webRoot+defer[j])
2584
+ loaded++;
2585
+ if(loaded>=toLoad){
2586
+ $(document).trigger("defer:loaded");
2587
+ loadingDefer=false;
2588
+ }
2589
+ }});
2590
+ })(j);
2591
+ }
2592
+ }
2593
+ if (this.firstDiv) {
2594
+
2595
+ var that = this;
2596
+ // Fix a bug in iOS where translate3d makes the content blurry
2597
+ this.activeDiv = this.firstDiv;
2598
+
2599
+ //window.setTimeout(function() {
2600
+ var loadFirstDiv=function(){
2601
+ //activeDiv = firstDiv;
2602
+ if (defaultHash.length > 0 && that.loadDefaultHash&&defaultHash!=("#"+that.firstDiv.id)&&$(defaultHash).length>0)
2603
+ {
2604
+ that.activeDiv=$(defaultHash).get();
2605
+ jq("#header #backButton").css("visibility","visible");
2606
+ that.setBackButtonText(that.activeDiv.title)
2607
+ that.history=[{target:"#"+that.firstDiv.id}]; //Reset the history to the first div
2608
+ }
2609
+ else
2610
+ previousTarget="#"+that.activeDiv.id;
2611
+ if (that.scrollingDivs[that.activeDiv.id]) {
2612
+ that.scrollingDivs[that.activeDiv.id].initEvents();
2613
+ }
2614
+ that.activeDiv.style.display = "block";
2615
+
2616
+
2617
+ if (that.activeDiv.title)
2618
+ that.setTitle(that.activeDiv.title);
2619
+ that.parsePanelFunctions(that.activeDiv);
2620
+ //Load the default hash
2621
+
2622
+ that.history=[{target:"#"+that.firstDiv.id}]; //Reset the history to the first div
2623
+ modalDiv = null;
2624
+ maskDiv = null;
2625
+ that.launchCompleted = true;
2626
+
2627
+ if(jq("#navbar a").length>0){
2628
+ jq("#navbar a").data("ignore-pressed", "true").data("resetHistory", "true");
2629
+ that.defaultFooter = jq("#navbar").children();
2630
+ that.updateNavbarElements(that.defaultFooter);
2631
+ }
2632
+ var firstMenu = jq("nav").get();
2633
+ if(firstMenu){
2634
+ that.defaultMenu = jq(firstMenu).children();
2635
+ that.updateSideMenu(that.defaultMenu);
2636
+ }
2637
+ that.defaultHeader = jq("#header").children();
2638
+ jq(document).trigger("jq.ui.ready");
2639
+ jq("#splashscreen").remove();
2640
+ };
2641
+ if(loadingDefer){
2642
+ $(document).one("defer:loaded",loadFirstDiv);
2643
+ }
2644
+ else
2645
+ loadFirstDiv();
2646
+ }
2647
+
2648
+ },
2649
+
2650
+ noTransition: function(oldDiv, currDiv, back) {
2651
+ oldDiv.style.display = "block";
2652
+ currDiv.style.display = "block";
2653
+ var that = this
2654
+ if (back) {
2655
+ that.css3animate(currDiv, {
2656
+ x: "0%",
2657
+ time: "1ms"
2658
+ });
2659
+ that.css3animate(oldDiv, {
2660
+ x: 0,
2661
+ time: "1ms"
2662
+ });
2663
+
2664
+ } else {
2665
+
2666
+ that.css3animate(oldDiv, {
2667
+ x: 0,
2668
+ y: 0,
2669
+ time: "1ms"
2670
+ });
2671
+ that.css3animate(currDiv, {
2672
+ x: "0%",
2673
+ time: "1ms"
2674
+ });
2675
+ }
2676
+ that.finishTransition(oldDiv);
2677
+ currDiv.style.zIndex = 2;
2678
+ oldDiv.style.zIndex = 1;
2679
+ $(oldDiv).removeClass('active');
2680
+ },
2681
+
2682
+ /**
2683
+ * This must be called at the end of every transition to hide the old div and reset the doingTransition variable
2684
+ *
2685
+ * @param {Object} Div that transitioned out
2686
+ * @title $.ui.finishTransition(oldDiv)
2687
+ */
2688
+ finishTransition: function(oldDiv) {
2689
+
2690
+ oldDiv.style.display = 'none';
2691
+ this.doingTransition = false;
2692
+
2693
+ }
2694
+ /**
2695
+ * END
2696
+ * @api private
2697
+ */
2698
+ };
2699
+
2700
+ function $am(el) {
2701
+ el = el.indexOf("#") == -1 ? "#" + el : el;
2702
+ return jq(el).get(0);
2703
+ }
2704
+
2705
+ var table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D"; /* Number */
2706
+ var crc32 = function( /* String */str, /* Number */crc) {
2707
+ if (crc == undefined)
2708
+ crc = 0;
2709
+ var n = 0; //a number between 0 and 255
2710
+ var x = 0; //an hex number
2711
+ crc = crc ^ (-1);
2712
+ for (var i = 0, iTop = str.length; i < iTop; i++) {
2713
+ n = (crc ^ str.charCodeAt(i)) & 0xFF;
2714
+ x = "0x" + table.substr(n * 9, 8);
2715
+ crc = (crc >>> 8) ^ x;
2716
+ }
2717
+ return crc ^ (-1);
2718
+ };
2719
+
2720
+
2721
+ $.ui = new ui;
2722
+ })(jq);
2723
+
2724
+ //The following functions are utilitiy functions for jqUi. They are not apart of the base class, but help with locking the page scroll,
2725
+ //input box issues, remove the address bar on iOS and android, etc
2726
+ (function() {
2727
+ var jQUi;
2728
+
2729
+ //Check to see if any <nav> items are found. If so, add the CSS classes
2730
+ jq(document).ready(function() {
2731
+ if (jq("nav").length > 0) {
2732
+ jq("#jQUi #header").addClass("hasMenu");
2733
+ jq("#jQUi #content").addClass("hasMenu");
2734
+ jq("#jQUi #navbar").addClass("hasMenu");
2735
+ }
2736
+ jQUi = jq("#jQUi");
2737
+ setTimeout(function(){
2738
+ hideAddressBar();
2739
+ },100);
2740
+ });
2741
+
2742
+ document.addEventListener("appMobi.device.ready", function() { //in AppMobi, we need to undo the height stuff since it causes issues.
2743
+ setTimeout(function() {
2744
+ jQUi.css("height", "100%"), document.body.style.height = "100%";
2745
+ document.documentElement.style.minHeight = window.innerHeight;
2746
+ }, 300);
2747
+ });
2748
+
2749
+
2750
+ window.addEventListener("orientationchange", function(e) {
2751
+ jq.ui.updateOrientation()
2752
+ window.setTimeout(function() {
2753
+ hideAddressBar();
2754
+ }, 200);
2755
+ }, false);
2756
+
2757
+ if (jq.os.android)
2758
+ {
2759
+ window.addEventListener("resize", function(e) {
2760
+ window.scrollTo(0,1);
2761
+ jq.ui.updateOrientation();
2762
+ if(document.body.clientWidth>=700)
2763
+ $.ui.toggleSideMenu(false);
2764
+ window.setTimeout(function() {
2765
+ hideAddressBar();
2766
+ }, 100);
2767
+ }, false);
2768
+ }
2769
+
2770
+
2771
+ function hideAddressBar() {
2772
+ if (jq.os.desktop)
2773
+ return jQUi.css("height", "100%");
2774
+ if (jq.os.android) {
2775
+ window.scrollTo(1, 1);
2776
+ if (document.documentElement.scrollHeight < window.outerHeight / window.devicePixelRatio)
2777
+ jQUi.css("height", (window.outerHeight / window.devicePixelRatio) + 'px');
2778
+ }
2779
+ else {
2780
+ document.documentElement.style.height = "5000px";
2781
+
2782
+ window.scrollTo(0, 1);
2783
+ document.documentElement.style.height = window.innerHeight + "px";
2784
+ jQUi.css("height", window.innerHeight + "px");
2785
+ }
2786
+ }
2787
+ //The following is based on Cubiq.org - iOS no click delay. We use this to capture events to input boxes to fix Android...and fix iOS ;)
2788
+ //We had to make a lot of fixes to allow access to input elements on android, etc.
2789
+ function NoClickDelay(el) {
2790
+ if (typeof (el) === "string")
2791
+ el = document.getElementById(el);
2792
+ el.addEventListener('touchstart', this, false);
2793
+ }
2794
+ var prevClickField;
2795
+ var prevPanel;
2796
+ var prevField;
2797
+ var closeField;
2798
+ NoClickDelay.prototype = {
2799
+ dX: 0,
2800
+ dY: 0,
2801
+ cX: 0,
2802
+ cY: 0,
2803
+ handleEvent: function(e) {
2804
+ switch (e.type) {
2805
+ case 'touchstart':
2806
+ this.onTouchStart(e);
2807
+ break;
2808
+ case 'touchmove':
2809
+ this.onTouchMove(e);
2810
+ break;
2811
+ case 'touchend':
2812
+ this.onTouchEnd(e);
2813
+ break;
2814
+ }
2815
+ },
2816
+
2817
+ onTouchStart: function(e) {
2818
+
2819
+ this.dX = e.touches[0].pageX;
2820
+ this.dY = e.touches[0].pageY;
2821
+
2822
+ var theTarget = e.target;
2823
+ if (theTarget.nodeType == 3)
2824
+ theTarget = theTarget.parentNode;
2825
+
2826
+ if(closeField)
2827
+ clearTimeout(closeField),closeField=null;
2828
+ if(prevField){
2829
+ prevField=null;
2830
+ var field = document.createElement('input');
2831
+ field.setAttribute('type', 'text');
2832
+ field.id="myhack";
2833
+ document.body.appendChild(field);
2834
+
2835
+ closeField=setTimeout(function() {
2836
+ field.focus();
2837
+ setTimeout(function() {
2838
+ field.blur();
2839
+ field.parentNode.removeChild(field);
2840
+ }, 50);
2841
+ }, 350);
2842
+ }
2843
+
2844
+ if(prevPanel){
2845
+ //prevField.blur();
2846
+ prevPanel.css("-webkit-transform","translate3d(0px,0px,0px)");
2847
+ prevPanel.css("left","0");
2848
+ prevField=null;
2849
+ prevPanel=null;
2850
+ }
2851
+
2852
+ var tagname = theTarget.tagName.toLowerCase();
2853
+ var type=theTarget.type||"";
2854
+ if((tagname=="a"&& theTarget.href.indexOf("tel:")===0)||((tagname=="input")||tagname=="textarea"||tagname=="select")&&type!="checkbox"&&type!="radio"){
2855
+
2856
+ if(jq.os.android&&$.ui.fixAndroidInputs){
2857
+ prevField=theTarget;
2858
+ theTarget.focus();
2859
+ //prevField=theTarget;
2860
+ prevPanel=$(theTarget).closest(".panel");
2861
+ prevPanel.css("left","-100%");
2862
+ prevPanel.css("-webkit-transition-duration","0ms");
2863
+ prevPanel.css("-webkit-transform","translate3d(100%,0px,0px)");
2864
+ prevPanel.css("position","absolute");
2865
+ return;
2866
+ }
2867
+
2868
+ }
2869
+ else
2870
+ e.preventDefault();
2871
+ this.moved = false;
2872
+ document.addEventListener('touchmove', this, true);
2873
+ document.addEventListener('touchend', this, true);
2874
+
2875
+ },
2876
+
2877
+ onTouchMove: function(e) {
2878
+
2879
+ this.moved = true;
2880
+ this.cX = e.touches[0].pageX - this.dX;
2881
+ this.cY = e.touches[0].pageY - this.dY;
2882
+
2883
+ // e.preventDefault();
2884
+ return false;
2885
+ },
2886
+ onTouchEnd: function(e) {
2887
+ document.removeEventListener('touchmove', this, true);
2888
+ document.removeEventListener('touchend', this, true);
2889
+
2890
+ if ((!jq.os.blackberry && !this.moved) || (jq.os.blackberry && (Math.abs(this.cX) < 5 || Math.abs(this.cY) < 5))) {
2891
+ var theTarget = e.target;
2892
+ if (theTarget.nodeType == 3)
2893
+ theTarget = theTarget.parentNode;
2894
+
2895
+ var theEvent = document.createEvent('MouseEvents');
2896
+ theEvent.initEvent('click', true, true);
2897
+ theTarget.dispatchEvent(theEvent);
2898
+ e.preventDefault();
2899
+ }
2900
+
2901
+ prevClickField = null;
2902
+ this.dX = this.cX = this.cY = this.dY = 0;
2903
+ return false;
2904
+
2905
+ }
2906
+ };
2907
+
2908
+
2909
+
2910
+ jq(document).ready(function() {
2911
+ document.body.addEventListener('touchmove', function(e) {
2912
+ e.preventDefault();
2913
+ if(jq.os.android)
2914
+ e.stopPropagation();
2915
+ window.scrollTo(1, 1);
2916
+ }, false);
2917
+ if (!jq.os.desktop)
2918
+ new NoClickDelay(document.getElementById("jQUi"));
2919
+
2920
+ document.getElementById("jQUi").addEventListener("click", function(e) {
2921
+
2922
+ var theTarget = e.target;
2923
+ if (theTarget.nodeType == 3)
2924
+ theTarget = theTarget.parentNode;
2925
+ if (checkAnchorClick(theTarget)) {
2926
+ e.preventDefault();
2927
+ return false;
2928
+ }
2929
+ }, true);
2930
+
2931
+ jq("#navbar").on("click", "a", function(e) {
2932
+ jq("#navbar a").removeClass("selected");
2933
+ setTimeout(function() {
2934
+ $(e.target).addClass("selected");
2935
+ }, 10);
2936
+ });
2937
+ });
2938
+
2939
+ function checkAnchorClick(theTarget) {
2940
+ var parent = false;
2941
+ while (theTarget.tagName && theTarget.tagName.toLowerCase() != "a" && theTarget.parentNode)
2942
+ parent = true, theTarget = theTarget.parentNode; //let's try the parent so <a href="#foo"><img src="whatever.jpg"></a> will work
2943
+ if (theTarget&&theTarget.tagName&&theTarget.tagName.toLowerCase() == "a") {
2944
+
2945
+
2946
+ var custom=(typeof jq.ui.customClickHandler=="function")?jq.ui.customClickHandler:false;
2947
+ if(custom!==false&&jq.ui.customClickHandler(theTarget)){
2948
+ return true;
2949
+ }
2950
+ if (theTarget.href.toLowerCase().indexOf("javascript:") !== -1 || theTarget.getAttribute("data-ignore")) {
2951
+ return false;
2952
+ }
2953
+
2954
+
2955
+
2956
+ if(theTarget.href.indexOf("tel:")===0)
2957
+ return false;
2958
+ if (theTarget.hash.indexOf("#") === -1 && theTarget.target.length > 0)
2959
+ {
2960
+
2961
+ if (theTarget.href.toLowerCase().indexOf("javascript:") != 0) {
2962
+ if (jq.ui.isAppMobi)
2963
+ AppMobi.device.launchExternal(theTarget.href);
2964
+ else if (!jq.os.desktop)
2965
+ brokerClickEventMobile(theTarget);
2966
+ else
2967
+ window.open(theTarget);
2968
+ return true;
2969
+ }
2970
+ return false;
2971
+ }
2972
+ if ((theTarget.href.indexOf("#") !== -1 && theTarget.hash.length == 0) || theTarget.href.length == 0)
2973
+ return true;
2974
+
2975
+ var mytransition = theTarget.getAttribute("data-transition");
2976
+ var resetHistory = theTarget.getAttribute("data-resetHistory");
2977
+ var back = (theTarget.getAttribute("data-reverse") && theTarget.getAttribute("data-reverse") == 'true')?true:false;
2978
+ resetHistory = resetHistory && resetHistory.toLowerCase() == "true" ? true : false;
2979
+
2980
+ var href = theTarget.hash.length > 0 ? theTarget.hash : theTarget.href;
2981
+ jq.ui.loadContent(href, resetHistory, back, mytransition, theTarget);
2982
+
2983
+ return true;
2984
+ }
2985
+ }
2986
+ function brokerClickEventMobile(theTarget) {
2987
+ if (jq.os.desktop)
2988
+ return;
2989
+ var clickevent = document.createEvent('Event');
2990
+ clickevent.initEvent('click', true, false);
2991
+ theTarget.target = "_blank";
2992
+ theTarget.dispatchEvent(clickevent);
2993
+ }
2994
+ })();
2995
+
2996
+ //Touch events are from zepto/touch.js
2997
+
2998
+ (function($) {
2999
+ var touch = {}, touchTimeout;
3000
+
3001
+ function parentIfText(node) {
3002
+ return 'tagName' in node ? node : node.parentNode;
3003
+ }
3004
+
3005
+ function swipeDirection(x1, x2, y1, y2) {
3006
+ var xDelta = Math.abs(x1 - x2), yDelta = Math.abs(y1 - y2);
3007
+ if (xDelta >= yDelta) {
3008
+ return (x1 - x2 > 0 ? 'Left' : 'Right');
3009
+ } else {
3010
+ return (y1 - y2 > 0 ? 'Up' : 'Down');
3011
+ }
3012
+ }
3013
+
3014
+ var longTapDelay = 750;
3015
+ function longTap() {
3016
+ if (touch.last && (Date.now() - touch.last >= longTapDelay)) {
3017
+ touch.el.trigger('longTap');
3018
+ touch = {};
3019
+ }
3020
+ }
3021
+ $(document).ready(function() {
3022
+ $(document.body).bind('touchstart', function(e) {
3023
+ var now = Date.now(), delta = now - (touch.last || now);
3024
+ touch.el = $(parentIfText(e.touches[0].target));
3025
+ touchTimeout && clearTimeout(touchTimeout);
3026
+ touch.x1 = e.touches[0].pageX;
3027
+ touch.y1 = e.touches[0].pageY;
3028
+ if (delta > 0 && delta <= 250)
3029
+ touch.isDoubleTap = true;
3030
+ touch.last = now;
3031
+ setTimeout(longTap, longTapDelay);
3032
+ if (!touch.el.data("ignore-pressed"))
3033
+ touch.el.addClass("selected");
3034
+ else
3035
+ touch.el.closest(".selectable").addClass("selected");
3036
+ }).bind('touchmove', function(e) {
3037
+ touch.x2 = e.touches[0].pageX;
3038
+ touch.y2 = e.touches[0].pageY;
3039
+ }).bind('touchend', function(e) {
3040
+ if (!touch.el) {
3041
+ touch = {};
3042
+ return;
3043
+ }
3044
+ if (!touch.el.data("ignore-pressed"))
3045
+ touch.el.removeClass("selected");
3046
+ else
3047
+ touch.el.closest(".selectable").removeClass("selected");
3048
+ if (touch.isDoubleTap) {
3049
+ touch.el.trigger('doubleTap');
3050
+ touch = {};
3051
+ } else if (Math.abs(touch.x1 - touch.x2) > 5 || Math.abs(touch.y1 - touch.y2) > 5) {
3052
+ (Math.abs(touch.x1 - touch.x2) > 30 || Math.abs(touch.y1 - touch.y2) > 30) &&
3053
+ touch.el.trigger('swipe') &&
3054
+ touch.el.trigger('swipe' + (swipeDirection(touch.x1, touch.x2, touch.y1, touch.y2)));
3055
+ touch.x1 = touch.x2 = touch.y1 = touch.y2 = touch.last = 0;
3056
+ touch={};
3057
+ } else if ('last' in touch) {
3058
+ touch.el.trigger('tap');
3059
+ touchTimeout = setTimeout(function() {
3060
+ touchTimeout = null;
3061
+ if (touch.el)
3062
+ touch.el.trigger('singleTap');
3063
+ touch = {};
3064
+ }, 250);
3065
+ }
3066
+ }).bind('touchcancel', function() {
3067
+ touch = {}
3068
+ });
3069
+ });
3070
+
3071
+ ['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown', 'doubleTap', 'tap', 'singleTap', 'longTap'].forEach(function(m) {
3072
+ $.fn[m] = function(callback) {
3073
+ return this.bind(m, callback)
3074
+ }
3075
+ });
3024
3076
  })(jq);
3025
3077
  (function($ui){
3026
3078