summaryrefslogtreecommitdiff
path: root/sitestatic/homepage.js
blob: 4e138e9debfeed0ef77a16746701588a0ea8732b (plain)
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
/* bootstrap-typeahead.min.js: */
/* =============================================================
 * bootstrap-typeahead.js v2.1.1
 * http://twitter.github.com/bootstrap/javascript.html#typeahead
 * =============================================================
 * Copyright 2012 Twitter, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============================================================ */
!function(n){"use strict";var h=function(t,e){this.$element=n(t),this.options=n.extend({},n.fn.typeahead.defaults,e),this.matcher=this.options.matcher||this.matcher,this.sorter=this.options.sorter||this.sorter,this.highlighter=this.options.highlighter||this.highlighter,this.updater=this.options.updater||this.updater,this.$menu=n(this.options.menu).appendTo("body"),this.source=this.options.source,this.shown=!1,this.listen()};h.prototype={constructor:h,select:function(){var t=this.$menu.find(".active").attr("data-value");return t&&this.$element.val(this.updater(t)).change(),this.hide()},updater:function(t){return t},show:function(){var t=n.extend({},this.$element.offset(),{height:this.$element[0].offsetHeight});return this.$menu.css({top:t.top+t.height,left:t.left}),this.$menu.show(),this.shown=!0,this},hide:function(){return this.$menu.hide(),this.shown=!1,this},lookup:function(t){var e;return this.query=this.$element.val(),!this.query||this.query.length<this.options.minLength?this.shown?this.hide():this:(e=n.isFunction(this.source)?this.source(this.query,n.proxy(this.process,this)):this.source)?this.process(e):this},process:function(t){var e=this;return t=n.grep(t,function(t){return e.matcher(t)}),(t=this.sorter(t)).length?this.render(t.slice(0,this.options.items)).show():this.shown?this.hide():this},matcher:function(t){return~t.toLowerCase().indexOf(this.query.toLowerCase())},sorter:function(t){for(var e,s=[],i=[],n=[];e=t.shift();)e.toLowerCase().indexOf(this.query.toLowerCase())?~e.indexOf(this.query)?i.push(e):n.push(e):s.push(e);return s.concat(i,n)},highlighter:function(t){var e=this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&");return t.replace(new RegExp("("+e+")","ig"),function(t,e){return"<strong>"+e+"</strong>"})},render:function(t){var s=this;return t=n(t).map(function(t,e){return(t=n(s.options.item).attr("data-value",e)).find("a").html(s.highlighter(e)),t[0]}),this.$menu.html(t),this},next:function(t){var e=this.$menu.find(".active").removeClass("active").next();e.length||(e=n(this.$menu.find("li")[0])),e.addClass("active")},prev:function(t){var e=this.$menu.find(".active").removeClass("active").prev();e.length||(e=this.$menu.find("li").last()),e.addClass("active")},listen:function(){this.$element.on("blur",n.proxy(this.blur,this)).on("keypress",n.proxy(this.keypress,this)).on("keyup",n.proxy(this.keyup,this)),(n.browser.chrome||n.browser.webkit||n.browser.msie)&&this.$element.on("keydown",n.proxy(this.keydown,this)),this.$menu.on("click",n.proxy(this.click,this)).on("mouseenter","li",n.proxy(this.mouseenter,this))},move:function(t){if(this.shown){switch(t.keyCode){case 9:case 13:case 27:t.preventDefault();break;case 38:t.preventDefault(),this.prev();break;case 40:t.preventDefault(),this.next()}t.stopPropagation()}},keydown:function(t){this.suppressKeyPressRepeat=!~n.inArray(t.keyCode,[40,38,9,13,27]),this.move(t)},keypress:function(t){this.suppressKeyPressRepeat||this.move(t)},keyup:function(t){switch(t.keyCode){case 40:case 38:break;case 9:case 13:if(!this.shown)return;this.select();break;case 27:if(!this.shown)return;this.hide();break;default:this.lookup()}t.stopPropagation(),t.preventDefault()},blur:function(t){var e=this;setTimeout(function(){e.hide()},150)},click:function(t){t.stopPropagation(),t.preventDefault(),this.select()},mouseenter:function(t){this.$menu.find(".active").removeClass("active"),n(t.currentTarget).addClass("active")}},n.fn.typeahead=function(i){return this.each(function(){var t=n(this),e=t.data("typeahead"),s="object"==typeof i&&i;e||t.data("typeahead",e=new h(this,s)),"string"==typeof i&&e[i]()})},n.fn.typeahead.defaults={source:[],items:8,menu:'<ul class="typeahead dropdown-menu"></ul>',item:'<li><a href="#"></a></li>',minLength:1},n.fn.typeahead.Constructor=h,n(function(){n("body").on("focus.typeahead.data-api",'[data-provide="typeahead"]',function(t){var e=n(this);e.data("typeahead")||(t.preventDefault(),e.typeahead(e.data()))})})}(window.jQuery);

/* konami.min.js: */
/*
* Konami-JS ~ 
* :: Now with support for touch events and multiple instances for 
* :: those situations that call for multiple easter eggs!
* Code: http://konami-js.googlecode.com/
* Examples: http://www.snaptortoise.com/konami-js
* Copyright (c) 2009 George Mandis (georgemandis.com, snaptortoise.com)
* Version: 1.4.0 (1/21/2013)
* Licensed under the GNU General Public License v3
* http://www.gnu.org/copyleft/gpl.html
* Tested in: Safari 4+, Google Chrome 4+, Firefox 3+, IE7+, Mobile Safari 2.2.1 and Dolphin Browser
*/
var Konami=function(t){var i={addEvent:function(t,e,n,i){t.addEventListener?t.addEventListener(e,n,!1):t.attachEvent&&(t["e"+e+n]=n,t[e+n]=function(){t["e"+e+n](window.event,i)},t.attachEvent("on"+e,t[e+n]))},input:"",pattern:"3838404037393739666513",load:function(n){this.addEvent(document,"keydown",function(t,e){if(e&&(i=e),i.input+=t?t.keyCode:event.keyCode,i.input.length>i.pattern.length&&(i.input=i.input.substr(i.input.length-i.pattern.length)),i.input==i.pattern)return i.code(n),void(i.input="")},this),this.iphone.load(n)},code:function(t){window.location=t},iphone:{start_x:0,start_y:0,stop_x:0,stop_y:0,tap:!1,capture:!1,orig_keys:"",keys:["UP","UP","DOWN","DOWN","LEFT","RIGHT","LEFT","RIGHT","TAP","TAP","TAP"],code:function(t){i.code(t)},load:function(e){this.orig_keys=this.keys,i.addEvent(document,"touchmove",function(t){if(1==t.touches.length&&!0===i.iphone.capture){var e=t.touches[0];i.iphone.stop_x=e.pageX,i.iphone.stop_y=e.pageY,i.iphone.tap=!1,i.iphone.capture=!1,i.iphone.check_direction()}}),i.addEvent(document,"touchend",function(t){!0===i.iphone.tap&&i.iphone.check_direction(e)},!1),i.addEvent(document,"touchstart",function(t){i.iphone.start_x=t.changedTouches[0].pageX,i.iphone.start_y=t.changedTouches[0].pageY,i.iphone.tap=!0,i.iphone.capture=!0})},check_direction:function(t){var e=Math.abs(this.start_x-this.stop_x),n=Math.abs(this.start_y-this.stop_y),i=this.start_x-this.stop_x<0?"RIGHT":"LEFT",o=this.start_y-this.stop_y<0?"DOWN":"UP",s=n<e?i:o;(s=!0===this.tap?"TAP":s)==this.keys[0]&&(this.keys=this.keys.slice(1,this.keys.length)),0==this.keys.length&&(this.keys=this.orig_keys,this.code(t))}}};return"string"==typeof t&&i.load(t),"function"==typeof t&&(i.code=t,i.load()),i};

/* Main homepage.js content: */
function setupTypeahead() {
    $('#pkgsearch-field').typeahead({
        source: function(query, callback) {
            $.getJSON('/opensearch/packages/suggest', {q: query}, function(data) {
                callback(data[1]);
            });
        },
        matcher: function(item) { return true; },
        sorter: function(items) { return items; },
        menu: '<ul class="pkgsearch-typeahead"></ul>',
        items: 10,
        updater: function(item) {
            $('#pkgsearch-field').val(item);
            $('#pkgsearch-form').submit();
            return item;
        }
    }).attr('autocomplete', 'off');
    $('#pkgsearch-field').keyup(function(e) {
        if (e.keyCode === 13 &&
                $('ul.pkgsearch-typeahead li.active').size() === 0) {
            $('#pkgsearch-form').submit();
        }
    });
}

function setupKonami(image_src) {
    var konami = new Konami(function() {
        $('#konami').html('<img src="' + image_src + '" alt=""/>');
        setTimeout(function() {
            $('#konami').fadeIn(500);
        }, 500);
        $('#konami').click(function() {
            $('#konami').fadeOut(500);
        });
    });
}