~chipaca/unity-lens-video/custom-user-agent

« back to all changes in this revision

Viewing changes to media/js/bashoneliners.js

  • Committer: Janos Gyerik
  • Date: 2011-08-08 20:19:00 UTC
  • Revision ID: janos@axiom-20110808201900-rpq8pghds6gf8vnl
top 50 link now works

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*!
2
 
 * Bash One-Liners JavaScript Library v0.1
3
 
 * http://bashoneliners.com/
4
 
 *
5
 
 * Copyright 2012, Janos Gyerik
6
 
 * http://bashoneliners.com/LICENSE
7
 
 *
8
 
 * Date: Sat Oct  8 06:38:28 CEST 2011
9
 
 */
10
 
 
11
 
function popup_error() {
12
 
    alert('Oops! Whatever you were trying to do, it\'s not working now... Please try again later!\n\nIf the problem doesn\'t go away soon, send an email to info@bashoneliners.com');
13
 
}
14
 
 
15
 
function bind_help_markdown() {
16
 
    $('.help-markdown').click(function() {
17
 
        var url = this.href;
18
 
        var dialog = $('<div class="loading"></div>').appendTo('body');
19
 
        dialog.dialog({
20
 
            close: function(event, ui) { dialog.remove(); },
21
 
            height: 400,
22
 
            width: 500,
23
 
            title: 'Markdown Syntax Quick Reference'
24
 
        });
25
 
        dialog.load(
26
 
            url,
27
 
            '',
28
 
            function(responseText, textStatus, XMLHttpRequest) {
29
 
                dialog.removeClass('loading');
30
 
            }
31
 
        );
32
 
        return false;
33
 
    });
34
 
}
35
 
 
36
 
function bind_question_answered() {
37
 
    $('.question-answered').click(function(e) {
38
 
        e.preventDefault();
39
 
        var question = $('.' + $(this).attr('data-parent'));
40
 
        var remove_buttons = function() {
41
 
            question.find('.question-answered').remove();
42
 
        };
43
 
        $.ajax({
44
 
            url: $(this).attr('href'),
45
 
            success: remove_buttons,
46
 
            error: popup_error
47
 
        });
48
 
    });
49
 
}
50
 
 
51
 
function bind_preview_markdown() {
52
 
    $('.preview-markdown').click(function(e) {
53
 
        e.preventDefault();
54
 
        var source = $('#' + $(this).attr('data-source'));
55
 
        var preview = $('#' + $(this).attr('data-source') + '-preview');
56
 
        var update_preview = function(html) {
57
 
            preview.html(html);
58
 
            preview.addClass('well');
59
 
        };
60
 
        $.ajax({
61
 
            url: $(this).attr('href'),
62
 
            type: 'post',
63
 
            data: { text: source.val() },
64
 
            success: update_preview,
65
 
            error: popup_error
66
 
        });
67
 
    });
68
 
}
69
 
 
70
 
function bind_comments_toggle() {
71
 
    $('.comments-toggle').click(function(e) {
72
 
        $(this).toggleClass('expanded').next().toggle(0);
73
 
    });
74
 
}
75
 
 
76
 
function footer_fix() {
77
 
    if ($('body').height() < $(window).height()) {
78
 
        $('.footer').addClass('fixed-bottom');
79
 
        $('body').css('padding-bottom', '50px');
80
 
    }
81
 
}
82
 
 
83
 
$(document).ready(function() {
84
 
    bind_help_markdown();
85
 
    bind_question_answered();
86
 
    bind_preview_markdown();
87
 
    bind_comments_toggle();
88
 
    footer_fix();
89
 
});
90
 
 
91
 
// eof