Skip to content

Instantly share code, notes, and snippets.

View addyosmani's full-sized avatar
🎯
Focusing

Addy Osmani addyosmani

🎯
Focusing
View GitHub Profile
@addyosmani
addyosmani / polymer-perf-bookmarklet.js
Last active September 8, 2015 16:04 — forked from ebidel/polymer-perf-bookmarklet.js
Polymer performance numbers bookmarklet
javascript:(function(){(function printStats(){var loadTimes=window.chrome.loadTimes();firstPaint=loadTimes.firstPaintTime*1000;firstPaintTime=firstPaint-(loadTimes.startLoadTime*1000);console.info('First paint took',firstPaintTime,'ms');console.info('Load took',performance.timing.loadEventStart-performance.timing.navigationStart,'ms');var instances=0;if(parseFloat(Polymer.version)<1){instances=[].slice.call(document.querySelectorAll('html /deep/ *')).filter(function(el){return el.localName.indexOf('-')!=-1||el.getAttribute('is');}).length;}else{instances=Polymer.telemetry.instanceCount;}console.info('Custom element instances:',instances);var reflectCount=0;if(Polymer.telemetry){console.info('=== Properties set to reflectToAttribute ===');Polymer.telemetry.registrations.forEach(function(el){for(var prop in el.properties){if(el.properties[prop].reflectToAttribute){console.log(el.is+'.'+prop);reflectCount++;}}});}else{console.info('=== Properties set to reflect ===');Polymer.elements.forEach(function(el){for(var
/* View documents with Google Docs ...
* because my laptop can't handle Word and Chrome at the same time. */
$(document).ready(function(){
// I'm sure there's a more efficient selector for this.
$('a[href$=doc], a[href$=docx], a[href$=pdf], a[href$=rtf]').attr(
'href',
function(){
return 'http://docs.google.com/viewer?url=' + this.href;
}
/*!
* jQuery Tiny Pub/Sub - v0.3pre - 11/4/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($){
/*!
* jQuery Tiny Pub/Sub - v0.3pre - 11/4/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($){
//For use on the jquery functions that except selectors
jQuery.fn.atLeastOne = function(prop, selectorsArr) {
var ret = 0, self = this,
testSelector = function(value){
return self[prop].apply(self, [value]).size() > 0;
};
$.each(selectorsArr, function(i, value){
ret = testSelector(value);
// break loop if found
if(ret) { return false }
(function($){
$.Class = function(code){
var klass = function() {
var instance = (arguments[0] !== null && this.__init__ && typeof this.__init__ == 'function') ? this.__init__.apply(this, arguments) : this;
return instance;
};
$.extend(klass, this);
$.extend(klass.prototype, {
'bind': function(type, fn) {
this.__events__ = this.__events__ || {};
(function($){
$.pubsub = (function(){
var mule = $({});
return {
subscribe:function(key, fn){
//Normalise
mule.bind(key, function(e, data){
fn.apply(null, [data]);
});
(function($) {
$.fn.enable = function() {
// Enable each selected element by removing its 'disabled' attribute.
return this.each(function() {
$(this).removeAttr('disabled');
});
};
$.fn.disable = function() {
(function( $ ){
$.fn.pushTop = function() {
return this.each(function() {
var $this = $(this);
top_z_index = 0;
$('*').each(function() {
var this_z_index = $(this).css('z-index');
if (this_z_index != "auto" && this_z_index > top_z_index) {
top_z_index = this_z_index;
}
(function($) {
$.fn.recurse = function(closure, options) {
var self = this, settings = $.extend({}, $.fn.recurse.defaults, options);
self.queue(settings.queue, function(next){
if (!closure.apply(self, [self])) {
self.delay(settings.delay, settings.queue).queue(settings.queue, arguments.callee).trigger('queue').dequeue(settings.queue);
} else {
self.trigger('complete');
}
});