diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2018-01-20 20:18:47 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-20 20:18:47 +0530 |
commit | 0d8bd65472d2167fe4e346ee2e0f0ca34aeef761 (patch) | |
tree | 7cf6f3d61d77a6d6886f09eb2d3f52fcd67f340b /js | |
parent | f1614a1e597a1ac53987a0466a41a14bf557e3d3 (diff) |
Add files via upload
Diffstat (limited to 'js')
-rw-r--r-- | js/index.js | 93 | ||||
-rw-r--r-- | js/menu.js | 154 |
2 files changed, 247 insertions, 0 deletions
diff --git a/js/index.js b/js/index.js new file mode 100644 index 0000000..c5340b8 --- /dev/null +++ b/js/index.js @@ -0,0 +1,93 @@ +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var ChangingTitle = function () { + function ChangingTitle() { + var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + + _classCallCheck(this, ChangingTitle); + + this.node = x; + this.letterfy(this.node.querySelector('h1')); + } + + _createClass(ChangingTitle, [{ + key: 'letterfy', + value: function letterfy(node) { + var text = node.innerText; + node.innerText = ''; + node.classList.add('current'); + for (var c in text) { + var span = document.createElement('span'); + span.innerText = text[c]; + span.classList.add('letter', 'in'); + span.style.animationDelay = c * 0.1 + 's'; + node.appendChild(span); + } + } + }, { + key: 'changeText', + value: function changeText(newText) { + var oldTitle = this.node.querySelector('.current'); + var i = 0; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = oldTitle.children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var letter = _step.value; + + letter.style.animationDelay = i++ * 0.1 + 's'; + letter.classList.remove('in'); + letter.classList.add('out'); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + oldTitle.classList.remove('current'); + var newTitle = document.createElement('h1'); + newTitle.classList.add('current'); + for (var c in newText) { + var span = document.createElement('span'); + span.innerText = newText[c]; + span.classList.add('letter', 'in'); + span.style.animationDelay = c * 0.1 + 0.5 + 's'; + newTitle.appendChild(span); + } + this.node.appendChild(newTitle); + setTimeout(this.removeNode(oldTitle), 2000); + } + }, { + key: 'removeNode', + value: function removeNode(x) { + return function () { + x.remove(); + }; + } + }]); + + return ChangingTitle; +}(); + +; + +var ct = new ChangingTitle(document.querySelector('.changing-title')); +var texts = ['Hi! I am नवन']; +var count = 0; +setInterval(function () { + ct.changeText(texts[++count % texts.length]); +}, 2000); diff --git a/js/menu.js b/js/menu.js new file mode 100644 index 0000000..6c0ab53 --- /dev/null +++ b/js/menu.js @@ -0,0 +1,154 @@ +(function($) { + + /* + Responsive Flat Menu + http://cssmenumaker.com/menu/responsive-flat-menu + */ + + $.fn.menumaker = function(options) { + + var cssmenu = $(this), + settings = $.extend({ + title: "Menu", + format: "dropdown", + sticky: false + }, options); + + return this.each(function() { + cssmenu.prepend('<div id="menu-button">' + settings.title + '</div>'); + $(this).find("#menu-button").on('click', function() { + $(this).toggleClass('menu-opened'); + var mainmenu = $(this).next('ul'); + if (mainmenu.hasClass('open')) { + mainmenu.hide().removeClass('open'); + } else { + mainmenu.show().addClass('open'); + if (settings.format === "dropdown") { + mainmenu.find('ul').show(); + } + } + }); + + cssmenu.find('li ul').parent().addClass('has-sub'); + + multiTg = function() { + cssmenu.find(".has-sub").prepend('<span class="submenu-button"></span>'); + cssmenu.find('.submenu-button').on('click', function() { + $(this).toggleClass('submenu-opened'); + if ($(this).siblings('ul').hasClass('open')) { + $(this).siblings('ul').removeClass('open').hide(); + } else { + $(this).siblings('ul').addClass('open').show(); + } + }); + }; + + if (settings.format === 'multitoggle') multiTg(); + else cssmenu.addClass('dropdown'); + + if (settings.sticky === true) cssmenu.css('position', 'fixed'); + + resizeFix = function() { + if ($(window).width() > 768) { + cssmenu.find('ul').show(); + } + + if ($(window).width() <= 768) { + cssmenu.find('ul').hide().removeClass('open'); + } + }; + resizeFix(); + return $(window).on('resize', resizeFix); + + }); + }; +})(jQuery); + +/* + By Osvaldas Valutis, www.osvaldas.info + Available for use under the MIT License +*/ + +; +(function($, window, document, undefined) { + $.fn.doubleTapToGo = function(params) { + if (!('ontouchstart' in window) && + !navigator.msMaxTouchPoints && + !navigator.userAgent.toLowerCase().match(/windows phone os 7/i)) return false; + + this.each(function() { + var curItem = false; + + $(this).on('click', function(e) { + var item = $(this); + if (item[0] != curItem[0]) { + e.preventDefault(); + curItem = item; + } + }); + + $(document).on('click touchstart MSPointerDown', function(e) { + var resetItem = true, + parents = $(e.target).parents(); + + for (var i = 0; i < parents.length; i++) + if (parents[i] == curItem[0]) + resetItem = false; + + if (resetItem) + curItem = false; + }); + }); + return this; + }; +})(jQuery, window, document); + +/** + * doubleTapToGoDecorator + * Adds the ability to remove the need for a second tap + * when in the mobile view + * + * @param {function} f - doubleTapToGo + */ +function doubleTapToGoDecorator(f) { + return function() { + + this.each(function() { + $(this).on('click', function(e) { + + // If mobile menu view + if ($('#menu-button').css('display') == 'block') { + + // If this is not a submenu button + if (!$(e.target).hasClass('submenu-button')) { + + // Remove the need for a second tap + window.location.href = $(e.target).attr('href'); + } + } + + }); + }); + + return f.apply(this); + } +} + +// Add decorator to the doubleTapToGo plugin +jQuery.fn.doubleTapToGo = doubleTapToGoDecorator(jQuery.fn.doubleTapToGo); + +/** + * jQuery + */ +(function($) { + $(document).ready(function() { + + $("#cssmenu").menumaker({ + title: "Menu", + format: "multitoggle" + }); + + $('#cssmenu li:has(ul)').doubleTapToGo(); + + }); +})(jQuery);
\ No newline at end of file |