Skip to content

Instantly share code, notes, and snippets.

@mockee
Created October 31, 2012 09:15
Show Gist options
  • Save mockee/3986009 to your computer and use it in GitHub Desktop.
Save mockee/3986009 to your computer and use it in GitHub Desktop.
mod/profile
define('widget/profile', [
'jquery'
, 'mod/cookie'
, 'mod/template'
], function($, cookie, template) {
var body = $('body')
, base = $('#ark-console')
, header = $('.profile-hd')
, dataContainer = $('.profile-bd')
, statusBar = $('.profile-ft')
, mainSection = $('.profile-hd, .profile-bd')
, tmplItem = $('#tmpl-console-item').html()
, docElement = document.documentElement
, loc = location
, profile = {}
profile.add = function(res) {
var uriArr = res.uri.split('/')
, name = uriArr.slice(-1)
, path = uriArr.slice(0, -1).join('/')
dataContainer.find('tbody')
.append(template(tmplItem, {
name: name
, path: path || '/'
, time: res.time
, method: res.type.toUpperCase()
, stdout: res.stdout
}))
statusBar.find('.req-num')
.text($('td[data-stdout]').length)
}
function replaceClass(oldClass, newClass) {
$(this).removeClass(oldClass).addClass(newClass)
}
header.dblclick(function() {
var isMax = /height:+/gi.test(base.attr('style'))
base.height(isMax ? '' : docElement.clientHeight)
dataContainer.css('max-height', isMax ? '300px' : '100%')
})
statusBar.on('click', function(e) {
var self = $(this)
, switcher = self.find('.switcher')
, isOff = switcher.hasClass('off')
, statusArr = ['off', 'on']
replaceClass.call(switcher,
statusArr[isOff ? 0 : 1]
, statusArr[isOff ? 1 : 0])
mainSection.toggle()
self.toggleClass('mini').find('.apc')
.text(isOff ? 'Ark Profiling Console' : 'APC')
})
base.on('click', '[data-stdout]', function() {
var self = $(this)
, stdout = self.find('.stdout')
if ($.trim(stdout.text()).length) {
return stdout.empty()
}
stdout.html(self.data('stdout')).show()
.end().find('pre').width(body.width())
})
// Add shire profile
if (/profile=shire/gi.test(loc.search)) {
var sp = $('#shire-profile')
if (!sp) { return }
profile.add({
uri: loc.href
, time: sp.data('pt')
, stdout: sp.html()
, type: 'GET'
})
}
return profile
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment