JavaScript

Javascript code posted
created at 16 Nov 10:52

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Avoid `console` errors in browsers that lack a console.
;(function(){for(var a,e=function(){},b="assert clear count debug dir dirxml error exception group groupCollapsed groupEnd info log markTimeline profile profileEnd table time timeEnd timeStamp trace warn".split(" "),c=b.length,d=window.console=window.console||{};c--;)a=b[c],d[a]||(d[a]=e)})();

(function(n, w, d, $, undefined) {
    var Initializer, init, base, SmoothScroll, App;
    Initializer = (function() {
        function Initializer() {
            this.init();
        }
        Initializer.prototype = {
            isDev: function() {
                var host = location.hostname,
                    regex = /panasonic\.jp$/i;
                return !regex.test(host);
            },
            isSp: function() {
                var mq = 'only screen and (max-width:640px) and (max-device-width:1280px)';
                return (w.matchMedia && w.matchMedia(mq).matches);
            },
            isLegacy: function() {
                return ((w.Modernizr !== undefined) && !w.Modernizr.opacity);
            },
            readWebFont: function() {
                var src = '//typesquare.com/accessor/script/typesquare.js?F3oktzPCZQs%3D',
                    script = '<script' + ' src="$1" charset="UTF-8"></' + 'script>';
                if (!this.isLegacy()) {
                    script = script.replace('$1', src);
                    d.write(script);
                }
                return this;
            },
            init: function() {
                if (this.isDev()) {
                    this.readWebFont();
                }
                /*if (w.WOW !== undefined) {
                    new WOW().init();
                }*/
                return this;
            }
        };
        return Initializer;
    })();

    init = new Initializer();

    SmoothScroll = (function() {
        function SmoothScroll() {
            this.obj = {
                anchor: base.find('a[href^=#]:not(".no-scroll")')
            };
            this.browsebarHeight = this._browsebarHeight();
            this.init();
        }
        SmoothScroll.prototype = {
            _browsebarHeight: function() {
                return init.isSp() ? 0 : $('#browsebar').height();
            },
            enterPage: function() {
                var target,
                    position = $(w).scrollTop();
                if (location.hash) {
                    target = $(location.hash);
                    if (target.length === 0) {
                        return this;
                    }
                    position = target.offset().top - this.browsebarHeight;
                }
                if (position > 0) {
                    this._scrollTo(position, 1);
                }
                return this;
            },
            anchor: function() {
                var self =this,
                    duration = 450,
                    browsebarHeight = self.browsebarHeight;
                self.obj.anchor.on('click.SmoothScroll', function(e) {
                    var obj = $(this),
                        target = $(obj.attr('href')),
                        position = 0;
                    if (target.length && target.is(':visible')) {
                        e.preventDefault();
                        position = target.offset().top - browsebarHeight;
                        self._scrollTo(position, duration);
                    }
                });
                return this;
            },
            _scrollTo: function(position, duration) {
                $('html, body').animate({scrollTop: position}, duration);
                return this;
            },
            init: function() {
                if (!init.isSp()) {
                    this.enterPage();
                }
                this.anchor();
                return this;
            }
        };
        return SmoothScroll;
    })();

    App = (function() {
        function App() {
            this.init();
        }
        App.prototype = {
            bgVideo: function() {
                var obj;
                if (base.hasClass('index')) {
                    obj = d.getElementById('hero-video');
                    if (obj) {
                        obj.playbackRate = 0.6;
                    }
                }
                return this;
            },
            navEvent: function() {
                var win = $(w),
                    gnavBar = base.find('#gnav-bar'),
                    button = gnavBar.find('.nav-button'),
                    nav = gnavBar.find('#gnav'),
                    openClass = 'open';
                button.on('click', function(e) {
                    var obj = $(this);
                    e.preventDefault();
                    if (obj.hasClass(openClass)) {
                        nav
                            .stop()
                            .slideUp(250, function() {
                                obj.removeClass(openClass);
                            });
                    } else {
                        nav
                            .stop()
                            .slideDown(300, function() {
                                obj.addClass(openClass);
                            });
                    }
                });
                win.on('resize orientationchange', function() {
                    if (!init.isSp()) {
                        nav.show();
                    } else {
                        if (button.hasClass(openClass)) {
                            nav.show();
                        } else {
                            nav.hide();
                        }
                    }
                });
                return this;
            },
            twitterIntent: function() {
                var obj = base.find('a.twitter-win');
                obj.on('click', function(e) {
                    if (!init.isLegacy()) {
                        e.preventDefault();
                    }
                });
                return this;
            },
            init: function() {
                this.bgVideo()
                    .navEvent()
                    .twitterIntent();
                return this;
            }
        };
        return App;
    })();

    $(function() {
        var html = $('html');
        base = $('#evolta2015');
        new SmoothScroll();
        new App();
        html.addClass('loaded');
    });
})(navigator, window, document, jQuery);
6.53 KB in 8 ms with coderay