-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapplication.js
executable file
·97 lines (90 loc) · 2.92 KB
/
application.js
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
jQuery(function($){
if($('#wpadminbar').length)
$('.navbar-fixed-top').css('top',$('#wpadminbar').height());
$('#view_wrapper').on('click','input:submit',function(e){
e.preventDefault();
$form = $(this).parents('form');
button = ($(this).attr('name') ? '&' + $(this).attr('name') + '=' + $(this).val() : '');
url = $form.find('input[name="full"]').length ? '/' : ajaxurl;
$.post(url, $form.serialize()+button, function(data){
if('<html>'==data.substr(0,6)) {
$('#'+$form.data('response')+'').html(data.replace(/<\/?html>/,'')).fadeIn();
} else if (-1 !== data.indexOf('xdebug-var-dump')) {
data = data.replace('xdebug-var-dump', 'xdebug-var-dump well');
$('#'+$form.data('response')+'').html(data).fadeIn();
} else {
$('#'+$form.data('response')+'').html( $('<pre class="well" />').text( data ) ).fadeIn();
}
});
});
$('#view_wrapper').on('click','.reload',function(e){
e.preventDefault();
page = $(this).data('page');
$('#'+page).remove();
get_hash(page);
});
$("#response").ajaxError(function(e, jqxhr, settings, exception) {
$('#response').html('<pre class="well">'+exception+' ('+jqxhr.status+")\n"+jqxhr.responseText+'</pre>').fadeIn();
});
$('#change_view').click(function(e) {
e.preventDefault();
$('#view_wrapper').toggleClass('row');
$('.view-container').toggleClass('span6');
if ($('textarea.span12').length)
$('textarea.span12').removeClass('span12').addClass('span6');
else
$('textarea.span6').removeClass('span6').addClass('span12');
});
function get_hash(h) {
if (!h || typeof h != 'string') {
// hash = e.newURL.split('#').pop();
hash = window.location.hash.substr(1);
if (!hash) hash = 'home';
}
else {
hash = h;
if (window.location.hash != '#' + hash ) {
window.location.hash = '#' + hash;
return;
}
}
$('#view_wrapper > div').hide();
if ($('#'+hash).length) {
$('#'+hash).fadeIn('fast');
}
else {
$.get(ajaxurl, {action:hash}, function(data){
$('#view_wrapper').append(data);
initialize_codemirror();
});
}
$('.active').removeClass('active');
$('a[href="#'+hash+'"]').parent().addClass('active');
}
window.onhashchange = get_hash;
function initialize_codemirror() {
$('#view_wrapper')
// Include a data-ub-codemirror attribute to make it eligible for CodeMirror.
.find('[data-ub-codemirror]')
.each(function(index, element) {
var $element = $(element);
if ($element.data('ub-codemirror') === '1') {
// Already initialized.
return;
}
// Initialize CodeMirror instance.
var editor = wp.codeEditor.initialize($element);
$element.data('ub-codemirror', '1');
// Copy code back to <textarea> on change so it's submitted.
editor.codemirror.on('change', function () {
var value = editor.codemirror.getValue();
if (value !== $element.val()) {
$element.val(value).trigger('change');
}
});
});
}
get_hash();
initialize_codemirror();
});
var hash;