Guest User

Untitled

a guest
Feb 25th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.63 KB | None | 0 0
  1. var windowW = window.innerWidth;
  2. var windowH = window.innerHeight;
  3.  
  4. var sections = [];
  5. var nav = [];
  6. nameCount = 0;
  7. $(document).ready(function() {
  8.  
  9. //$("#wrapper").css({'display': 'none'});
  10. setTimeout( function(){
  11. $('body').addClass('phaseOne');
  12. }, 500);
  13. //Form Creation to build the page//
  14. function formCreation(){
  15. $('body').prepend('<div id="formWrap"></div>')
  16. $('#formWrap').append('<input type="text" name="name" id="value_Input" size="30" maxlength="8" placeholder="Enter a Number">');
  17. $('#formWrap').append('<input type="button" id="numberButton" value="How Many Sections" onClick="changeForm()">');
  18. $("#value_Input").bind("keydown", function (event) {
  19. if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 ||
  20. // Allow: Ctrl+A
  21. (event.keyCode == 65 && event.ctrlKey === true) ||
  22.  
  23. // Allow: home, end, left, right
  24. (event.keyCode >= 35 && event.keyCode <= 39)) {
  25. // let it happen, don't do anything
  26. return;
  27. } else {
  28. // Ensure that it is a number and stop the keypress
  29. if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
  30. event.preventDefault();
  31. }
  32. }
  33. });
  34.  
  35. }
  36. formCreation();
  37.  
  38. //Touch Click VARS//
  39. var hasTouch = 'ontouchstart' in window;
  40. END_EV = hasTouch ? 'touchend' : 'click'; //public so no new "var"
  41. MOVE_EV = hasTouch ? 'touchmove' : 'mousemove'; // read mousemove isnt the same as touchmove
  42.  
  43. var START_EV = hasTouch ? 'touchstart' : 'mousedown',
  44. // but....it's the best solution I have
  45. CANCEL_EV = hasTouch ? 'touchcancel' : 'touchcancel';
  46. //Touch Click VARS END//
  47.  
  48. //Responsive Nav Button//
  49. clickCount =0;
  50. $(document).on(END_EV, '.navCase', function(e){
  51. if(clickCount <= 0){
  52. clickCount++
  53. $('body').addClass('hamburgerNavActive');
  54. }
  55. else{
  56. $('body').removeClass('hamburgerNavActive');
  57. clickCount = 0;
  58. }
  59. });
  60. //Responsive Nav Button End//
  61.  
  62. });
  63. //End Doc Ready
  64. function changeForm(){
  65. $('body').removeClass('phaseOne');
  66. setTimeout(function(){
  67. getTheValue();
  68. },500)
  69. }
  70. function getTheValue(){
  71.  
  72. var valueElement = document.getElementById("value_Input");
  73. var theCount = valueElement.value;
  74. //$('body').append(theName);
  75. $('#wrapper').append('<section></section>');
  76. var e = $('section');
  77. for (var i = 1; i < theCount; i++) {
  78. e.clone().insertAfter(e);
  79. //sectionBuild();
  80.  
  81. }
  82. $('.top-nav').append('<li><a href=""></a></li>');
  83. var e = $('.top-nav li');
  84. for (var i = 1; i < theCount; i++) {
  85. e.clone().insertAfter(e);
  86. }
  87.  
  88. $('#value_Input').remove();
  89. $('#numberButton').remove();
  90.  
  91. $('#formWrap').append('<input type="text" size="30" maxlength="70">');
  92. var e = $('#formWrap input');
  93. for (var i = 1; i < theCount; i++) {
  94. e.clone().insertAfter(e);
  95. }
  96. sectionBuild();
  97. }
  98. function sectionBuild(){
  99. var sectionLength = $('section').length;
  100. var windowW = window.innerWidth;
  101. var windowH = window.innerHeight;
  102. console.log(sectionLength);
  103. //Size Sections//
  104. $('section').css({ width : windowW});
  105. $('section').css({ height : windowH});
  106. $('#wrapper').css({ height : windowH*sectionLength});
  107.  
  108. $("section").each(function(n) {
  109. $(this).attr('id', 'section'+n);
  110. $(this).append('<h1>section'+n+'</h1>');
  111. });
  112.  
  113. writeNav();
  114. }
  115. //Write Nav//
  116. function writeNav(){
  117. var nav = []
  118. var sections = []
  119.  
  120.  
  121. $(".top-nav li").each(function(n) {
  122. $(this).attr("id", 'nav'+n);
  123. });
  124.  
  125. $(".top-nav li a").each(function(i, val){
  126. $(this).append(nav[i]);
  127. });
  128. $('.top-nav li:first-child').addClass('active');
  129. $(".top-nav").append("<div id='navLine'></div>");
  130.  
  131. $(".top-nav").find("li").each(function(){ nav.push(this.id); });
  132. $("#wrapper").find("section").each(function(){ sections.push(this.id); });
  133.  
  134.  
  135. $(".top-nav li a").each(function(i, val){
  136. $(this).attr("href", '#'+sections[i]);
  137. });
  138. $(".top-nav li a").each(function(i, val){
  139. $(this).html(sections[i]);
  140. });
  141.  
  142. $("#formWrap input").each(function(n) {
  143. $(this).attr("id", 'form'+n);
  144. $(this).attr("placeholder", 'Name Section'+n);
  145. });
  146.  
  147. console.log(nav);
  148. console.log(sections);
  149.  
  150. $('#formWrap').append('<input type="button" id="nameButton" value="Name the Sections" onClick="changeFormTwo()">');
  151.  
  152. setTimeout( function(){
  153. $('body').addClass('phaseTwo');
  154. }, 500);
  155. }
  156. function changeFormTwo(){
  157. $('body').removeClass('phaseTwo');
  158. setName();
  159.  
  160. }
  161. function setName(){
  162.  
  163. var form = []
  164. $("#formWrap").find("input").each(function(){ form.push(this); });
  165. console.log(form);
  166.  
  167. $(".top-nav li a").each(function(i, val){
  168. $(this).html(form[i].value);
  169. });
  170.  
  171. setTitle();
  172.  
  173. }
  174. function setTitle(){
  175. $('#formWrap input').remove();
  176. $('#nameButton').remove();
  177. $('#formWrap').append('<input type="text" size="30" maxlength="70" id="titleInput">');
  178. $('#formWrap').append('<input type="button" id="titleButton" value="Name the Site" onClick="changeFormThree()">');
  179. setTimeout( function(){
  180. $('body').addClass('phaseThree');
  181. }, 500);
  182.  
  183. }
  184. function changeFormThree(){
  185. $('body').removeClass('phaseThree');
  186. start();
  187.  
  188. }
  189. function start(){
  190. var titleValue = document.getElementById("titleInput");
  191. var title = titleValue.value;
  192. $('#title').html(title);
  193. $('#formWrap').remove();
  194.  
  195. $('#titleInput').remove();
  196. $('#titleButton').remove();
  197. $("#wrapper").css({'display': 'block'});
  198. preload();
  199. }
  200. //Have a Preeloadr when builiding page//
  201. function preload(){
  202. $('body').addClass('loading');
  203. $('body').prepend('<div class="progress-circle-container"><div class="progress-circle-outer"><div class="progress-circle-inner"><span class="number">100</span></div></div></div>')
  204.  
  205. setTimeout( function(){
  206. $('.progress-circle-container').addClass('on');
  207. var $num = $('.number'),
  208. times = 0;
  209. for(i=0; i<=100; i++) {
  210. setTimeout(function() {
  211. $num.html(times);
  212. times++;
  213. if (times === 100) {
  214. $('.progress-circle-container').removeClass('on');
  215. setTimeout(function(){
  216. $('.progress-circle-container').css('display', 'none');
  217. init();
  218. },1000)
  219. }
  220. },i*50)
  221. };
  222. }, 500)
  223. }
  224. //Clear Active Nav//
  225. function clearActiveNav(){
  226. $('.top-nav li').removeClass();
  227. $('body').removeClass('hamburgerNavActive');
  228. $('body').attr('id', '')
  229. clickCount = 0;
  230. };
  231. function init(){
  232. $('body').removeClass('loading').addClass('loaded');
  233. //Find Active Nav//
  234. function findActive(){
  235. var activeButton = $('.top-nav').find(' li.active');
  236. var $navLine = $("#navLine");$navLine.width(
  237. $(".top-nav li.active").width()).css("left", $(".top-nav li.active").position().left).data("origLeft", $navLine.position().left).data("origWidth", $navLine.width());
  238. $el = $(activeButton);
  239. leftPos = $el.position().left;
  240. newWidth = $el.width();
  241. $navLine.animate({
  242. left: leftPos,
  243. width: newWidth
  244. },200);
  245. //Body ID Switch//
  246. var activeID = activeButton.attr('id');
  247. $('body').attr('id', 'body'+ activeID);
  248.  
  249. };
  250. findActive();
  251. //Smooth Scrolling//
  252. $(function() {
  253. $('a[href*=#]:not([href=#])').click(function() {
  254. if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
  255. var target = $(this.hash);
  256. target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
  257. if (target.length) {
  258. $('html,body').animate({
  259. scrollTop: target.offset().top
  260. }, 1000);
  261. clearActiveNav();
  262. $(this).parent().addClass('active');
  263. findActive();
  264. return false;
  265. }
  266. }
  267. });
  268. });
  269. }
Add Comment
Please, Sign In to add comment