summaryrefslogtreecommitdiff
path: root/wikipedia/views/js/main.js
blob: 531d7fad955f523a4a7fd76a14d4d08cda21fd37 (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
window.Endless = window.Endless || {};
Endless.Wikipedia = Endless.Wikipedia || {};

(function(window, document, $) {

    "use strict";

    Endless.Wikipedia.App = function() {
        var privateObject,
            $body = $("body"),
            $image = $(".image"),
            $main = $("#main"),
            $main_content = $("#main-content"),
            $inside_content = $("#inside-content"),
            $header_content = $("#header-content"),
            $wiki_content = $("#wiki_content"),
            lang = "pt",

            _resultPageView = function(image_path) {
                $('#inside-content [src^="//"]').each(function() {
                    var parent = $(this).parent();
                    if($(this).is("img")){
                        var url = $(this).attr("src");
                        var theSplit = url.split("/");
                        var filename = theSplit[theSplit.length - 2];
                        if(filename.length == 2){
                            filename = theSplit[theSplit.length - 1];
                        }
                        var newSrc = image_path + encodeURI(filename)
                        if(newSrc.substring(newSrc.length - 4) == ".svg"){
                            newSrc += ".png";
                        }
                        $(this).attr('src', newSrc);
                    } 
                });
                // May need this back at some point
                // $('link[rel=stylesheet]').each(function(){
                //     var src = $(this).attr("href");
                //     console.log(asset_path + src);
                //     $(this).attr("href", asset_path + "/" + src);
                // });
            },

            wresize = function() {
                $main_content.height($(window).height());
                $inside_content.height($main_content.outerHeight() - ($("#header-content").outerHeight() + 15));
            }

        return {
            init: function() {
                $(document).hide();
                var image_path = $inside_content.attr('image_path');
                _resultPageView(image_path);
                wresize();
                $(document).show();
            },
            wresize: wresize
        };
    };

    $(function() {
        Endless.Wikipedia.module = new Endless.Wikipedia.App();
        Endless.Wikipedia.module.init();
    });

}(window, document, jQuery));