comparison src/main/webapp/resources/js/mobile/slidfast.js @ 7:764f47286679

(none)
author jurzua
date Wed, 29 Oct 2014 14:28:34 +0000
parents
children
comparison
equal deleted inserted replaced
6:ded3bccf2cf9 7:764f47286679
1 /*!
2 * JBoss, Home of Professional Open Source
3 * Copyright 2011, Red Hat, Inc. and individual contributors
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 *
22 * Author: Wesley Hales
23 *
24 * version: 1.0.0.Alpha
25 */
26
27 (function(window,document,undefined){
28
29 var slidfast = (function(){
30
31 var slidfast = function(startupOptions){
32 options = startupOptions;
33 return new slidfast.core.init();
34 },
35
36 options,
37
38 defaultPageID = "",
39
40 defaultPageHash = "",
41
42 backButtonID = "",
43
44 focusPage = null,
45
46 isReady = false;
47
48 slidfast.core = slidfast.prototype = {
49
50 constructor: slidfast,
51
52 start: function() {
53 if(options){
54 try{
55 defaultPageID = options.defaultPageID;
56 defaultPageHash = options.defaultPageHash;
57 backButtonID = options.backButtonID;
58 }catch(e){
59
60 }
61 }
62 try{
63 slidfast.core.hideURLBar();
64 slidfast.core.locationChange();
65 }catch(e){
66 alert('You must define the page ID and location hash as default parameters. \n Error:' + e)
67 }
68 },
69
70 hideURLBar: function() {
71 //hide the url bar on mobile devices
72 setTimeout(scrollTo, 0, 0, 1)
73 },
74
75 slideTo : function (id) {
76 if(!focusPage) {
77 focusPage = document.getElementById(defaultPageID);
78 }
79
80 //1.)the page we are bringing into focus dictates how
81 // the current page will exit. So let's see what classes
82 // our incoming page is using. We know it will have stage[right|left|etc...]
83 var classes = document.getElementById(id).className.split(' ');
84
85 //2.)decide if the incoming page is assigned to right or left
86 // (-1 if no match)
87 var stageType = classes.indexOf('stage-left');
88
89 //3.) decide how this focused page should exit.
90 if (stageType > 0) {
91 focusPage.className = 'page transition stage-right';
92 } else {
93 focusPage.className = 'page transition stage-left';
94 }
95
96 //4. refresh/set the variable
97 focusPage = document.getElementById(id);
98
99 //5. Bring in the new page and set the global.
100 focusPage.className = 'page transition stage-center';
101 },
102
103 init: function() {
104
105 window.addEventListener('load', function(e) {
106 isReady = true;
107 slidfast.core.start(defaultPageID, defaultPageHash);
108 }, false);
109
110 window.addEventListener('hashchange', function(e) {
111 slidfast.core.locationChange();
112 }, false);
113
114 return slidfast.core;
115
116 },
117
118 locationChange: function() {
119 if (location.hash === "#" + defaultPageHash || location.hash == '') {
120 slidfast.core.slideTo(defaultPageID);
121 if(backButtonID){
122 //we're on the default page, so no need for back button
123 document.getElementById(backButtonID).className = 'hide-button';
124 }
125 } else {
126 var hashArray = location.hash.split(':');
127 var id;
128 var sample;
129 if (hashArray.length === 2) {
130 id = hashArray[0].replace('#', '');
131 sample = hashArray[1];
132 try{
133 //method defined in a4j:jsFunction
134 handleHashChange(id, sample);
135 }catch(e){
136 alert('you must define an a4j:jsFunction component with name=\"handleHashChange\"')
137 }
138 if(backButtonID){
139 //show the back button and attach functions
140 document.getElementById(backButtonID).className = 'basic-button left-header-button';
141 document.getElementById(backButtonID).onclick = function() {
142 location.hash = defaultPageHash;
143 };
144 }
145 }
146
147 }
148 },
149
150 flip: function() {
151 //get a handle on the flippable region
152 var front = document.getElementById('front');
153 var back = document.getElementById('back');
154
155 //just a simple way to see what the state is
156 var classes = front.className.split(' ');
157 var flipped = classes.indexOf('flipped');
158
159 if (flipped >= 0) {
160 //already flipped, so return to original
161 front.className = 'normal';
162 back.className = 'flipped';
163 } else {
164 //do the flip
165 front.className = 'flipped';
166 back.className = 'normal';
167
168 }
169 }
170
171 };
172 slidfast.core.init.prototype = slidfast.core;
173 return slidfast;
174
175 })();
176
177 window.slidfast = slidfast;
178 })(window,document);
179
180
181