| 1 |
(function($) { |
| 2 |
$.cookie = function(name, value, options) { if (typeof value != 'undefined') { options = options || {}; if (value === null) { value = ''; options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; } expires = '; expires=' + date.toUTCString(); } var path = options.path ? '; path=' + (options.path) : ''; var domain = options.domain ? '; domain=' + (options.domain) : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = $.trim(cookies[i]); if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } }; |
| 3 |
$('head').append('<link rel="stylesheet" href="'+DEBUG_TOOLBAR_STATIC_PATH+'css/toolbar.css?'+ Math.random() +'" type="text/css" />'); |
| 4 |
var COOKIE_NAME = 'fldt'; |
| 5 |
var COOKIE_NAME_ACTIVE = COOKIE_NAME +'_active'; |
| 6 |
var fldt = { |
| 7 |
init: function() { |
| 8 |
$('#flDebug').show(); |
| 9 |
var current = null; |
| 10 |
$('#flDebugPanelList li a').on('click', function() { |
| 11 |
if (!this.className) { |
| 12 |
return false; |
| 13 |
} |
| 14 |
current = $('#flDebug #' + this.className + '-content'); |
| 15 |
if (current.is(':visible')) { |
| 16 |
$(document).trigger('close.flDebug'); |
| 17 |
$(this).parent().removeClass('flDebugActive'); |
| 18 |
} else { |
| 19 |
$('.flDebugPanelContentParent').hide(); // Hide any that are already open |
| 20 |
current.show(); |
| 21 |
$('#flDebugToolbar li').removeClass('flDebugActive'); |
| 22 |
$(this).parent().addClass('flDebugActive'); |
| 23 |
} |
| 24 |
return false; |
| 25 |
}); |
| 26 |
$('#flDebugPanelList li .flDebugSwitch').on('click', function() { |
| 27 |
var $panel = $(this).parent(); |
| 28 |
var $this = $(this); |
| 29 |
var dom_id = $panel.attr('id'); |
| 30 |
|
| 31 |
// Turn cookie content into an array of active panels |
| 32 |
var active_str = $.cookie(COOKIE_NAME_ACTIVE); |
| 33 |
var active = (active_str) ? active_str.split(';') : []; |
| 34 |
active = $.grep(active, function(n,i) { return n != dom_id; }); |
| 35 |
|
| 36 |
if ($this.hasClass('flDebugActive')) { |
| 37 |
$this.removeClass('flDebugActive'); |
| 38 |
$this.addClass('flDebugInactive'); |
| 39 |
} else { |
| 40 |
active.push(dom_id); |
| 41 |
$this.removeClass('flDebugInactive'); |
| 42 |
$this.addClass('flDebugActive'); |
| 43 |
} |
| 44 |
|
| 45 |
if (active.length > 0) { |
| 46 |
$.cookie(COOKIE_NAME_ACTIVE, active.join(';'), { |
| 47 |
path: '/', expires: 10 |
| 48 |
}); |
| 49 |
} else { |
| 50 |
$.cookie(COOKIE_NAME_ACTIVE, null, { |
| 51 |
path: '/', expires: -1 |
| 52 |
}); |
| 53 |
} |
| 54 |
}); |
| 55 |
$('#flDebug a.flDebugClose').on('click', function() { |
| 56 |
$(document).trigger('close.flDebug'); |
| 57 |
$('#flDebugToolbar li').removeClass('flDebugActive'); |
| 58 |
return false; |
| 59 |
}); |
| 60 |
$('#flDebug a.flDebugRemoteCall').on('click', function() { |
| 61 |
$('#flDebugWindow').load(this.href, {}, function() { |
| 62 |
$('#flDebugWindow a.flDebugBack').click(function() { |
| 63 |
$(this).parent().parent().hide(); |
| 64 |
return false; |
| 65 |
}); |
| 66 |
}); |
| 67 |
$('#flDebugWindow').show(); |
| 68 |
return false; |
| 69 |
}); |
| 70 |
$('#flDebugTemplatePanel a.flDebugTemplateShowContext').on('click', function() { |
| 71 |
fldt.toggle_arrow($(this).children('.flDebugToggleArrow')) |
| 72 |
fldt.toggle_content($(this).parent().next()); |
| 73 |
return false; |
| 74 |
}); |
| 75 |
$('#flDebugSQLPanel a.flDebugShowStacktrace').on('click', function() { |
| 76 |
fldt.toggle_content($('.flDebugHideStacktraceDiv', $(this).parents('tr'))); |
| 77 |
return false; |
| 78 |
}); |
| 79 |
$('#flDebugHideToolBarButton').on('click', function() { |
| 80 |
fldt.hide_toolbar(true); |
| 81 |
return false; |
| 82 |
}); |
| 83 |
$('#flDebugShowToolBarButton').on('click', function() { |
| 84 |
fldt.show_toolbar(); |
| 85 |
return false; |
| 86 |
}); |
| 87 |
$(document).on('close.flDebug', function() { |
| 88 |
// If a sub-panel is open, close that |
| 89 |
if ($('#flDebugWindow').is(':visible')) { |
| 90 |
$('#flDebugWindow').hide(); |
| 91 |
return; |
| 92 |
} |
| 93 |
// If a panel is open, close that |
| 94 |
if ($('.flDebugPanelContentParent').is(':visible')) { |
| 95 |
$('.flDebugPanelContentParent').hide(); |
| 96 |
return; |
| 97 |
} |
| 98 |
// Otherwise, just minimize the toolbar |
| 99 |
if ($('#flDebugToolbar').is(':visible')) { |
| 100 |
fldt.hide_toolbar(true); |
| 101 |
return; |
| 102 |
} |
| 103 |
}); |
| 104 |
if ($.cookie(COOKIE_NAME)) { |
| 105 |
fldt.hide_toolbar(false); |
| 106 |
} else { |
| 107 |
fldt.show_toolbar(false); |
| 108 |
} |
| 109 |
$('#flDebug table.flDebugTablesorter').each(function() { |
| 110 |
var headers = {}; |
| 111 |
$(this).find('thead th').each(function(idx, elem) { |
| 112 |
headers[idx] = $(elem).data(); |
| 113 |
}); |
| 114 |
$(this).tablesorter({headers: headers}); |
| 115 |
}) |
| 116 |
.bind('sortEnd', function() { |
| 117 |
$(this).find('tbody tr').each(function(idx, elem) { |
| 118 |
var even = idx % 2 === 0; |
| 119 |
$(elem) |
| 120 |
.toggleClass('flDebugEven', even) |
| 121 |
.toggleClass('flDebugOdd', !even); |
| 122 |
}); |
| 123 |
}); |
| 124 |
}, |
| 125 |
toggle_content: function(elem) { |
| 126 |
if (elem.is(':visible')) { |
| 127 |
elem.hide(); |
| 128 |
} else { |
| 129 |
elem.show(); |
| 130 |
} |
| 131 |
}, |
| 132 |
close: function() { |
| 133 |
$(document).trigger('close.flDebug'); |
| 134 |
return false; |
| 135 |
}, |
| 136 |
hide_toolbar: function(setCookie) { |
| 137 |
// close any sub panels |
| 138 |
$('#flDebugWindow').hide(); |
| 139 |
// close all panels |
| 140 |
$('.flDebugPanelContentParent').hide(); |
| 141 |
$('#flDebugToolbar li').removeClass('flDebugActive'); |
| 142 |
// finally close toolbar |
| 143 |
$('#flDebugToolbar').hide('fast'); |
| 144 |
$('#flDebugToolbarHandle').show(); |
| 145 |
// Unbind keydown |
| 146 |
$(document).unbind('keydown.flDebug'); |
| 147 |
if (setCookie) { |
| 148 |
$.cookie(COOKIE_NAME, 'hide', { |
| 149 |
path: '/', |
| 150 |
expires: 10 |
| 151 |
}); |
| 152 |
} |
| 153 |
}, |
| 154 |
show_toolbar: function(animate) { |
| 155 |
// Set up keybindings |
| 156 |
$(document).on('keydown.flDebug', function(e) { |
| 157 |
if (e.keyCode == 27) { |
| 158 |
fldt.close(); |
| 159 |
} |
| 160 |
}); |
| 161 |
$('#flDebugToolbarHandle').hide(); |
| 162 |
if (animate) { |
| 163 |
$('#flDebugToolbar').show('fast'); |
| 164 |
} else { |
| 165 |
$('#flDebugToolbar').show(); |
| 166 |
} |
| 167 |
$.cookie(COOKIE_NAME, null, { |
| 168 |
path: '/', |
| 169 |
expires: -1 |
| 170 |
}); |
| 171 |
}, |
| 172 |
toggle_arrow: function(elem) { |
| 173 |
var uarr = String.fromCharCode(0x25b6); |
| 174 |
var darr = String.fromCharCode(0x25bc); |
| 175 |
elem.html(elem.html() == uarr ? darr : uarr); |
| 176 |
}, |
| 177 |
load_href: function(href) { |
| 178 |
$.get(href, function(data, status, xhr) { |
| 179 |
document.open(); |
| 180 |
document.write(xhr.responseText); |
| 181 |
document.close(); |
| 182 |
}); |
| 183 |
return false; |
| 184 |
}, |
| 185 |
$: $ |
| 186 |
}; |
| 187 |
$(document).ready(function() { |
| 188 |
fldt.init(); |
| 189 |
}); |
| 190 |
window.fldt = fldt; |
| 191 |
|
| 192 |
})(jQuery.noConflict(true)); |