Skip to content

Instantly share code, notes, and snippets.

View MeoMix's full-sized avatar

Sean Anderson MeoMix

  • San Francisco, CA
View GitHub Profile
@MeoMix
MeoMix / 1. nextButton-preRefactor.js
Created May 30, 2013 04:36
nextButton.js before and after refactoring to use a Backbone.View
// When clicked -- goes to the next video. Can potentially go from the end of the list to the front if repeat playlist is toggled on
define(['backgroundManager'], function (backgroundManager) {
'use strict';
var nextButton = $('#NextButton');
// Prevent spamming by only allowing a next click once every 100ms.
nextButton.click(_.debounce(function () {
if (!$(this).hasClass('disabled')) {
require(['jquery', 'underscore'], function () {
// Backbone.js 0.9.9
// (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc.
// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
// http://backbonejs.org
(function () {
define([
'utility'
], function (Utility) {
'use strict';
var PlaylistItemView = Backbone.View.extend({
tagName: 'li',
className: 'playlistItem',
// JavaScript micro-templating, similar to John Resig's implementation.
// Underscore templating handles arbitrary delimiters, preserves whitespace,
// and correctly escapes quotes within interpolated code.
_.template = function (text, data, settings) {
var render;
settings = _.defaults({}, settings, _.templateSettings);
// Combine delimiters into one regular expression via alternation.
var matcher = new RegExp([
(settings.escape || noMatch).source,
getBulkRelatedVideoInformation: function(videoIds, callback) {
// TODO: Maybe abort if takes too long or debug this really well.
var bulkRelatedVideoInformation = [];
var totalVideosToProcess = videoIds.length;
var videosProcessed = 0;
var videosToProcessConcurrently = 5;
var videosProcessing = 0;
var self = this;
var youtubeQueryInterval = setInterval(function () {
var YouTubeDataAPI = Backbone.Model.extend({
sendV2ApiRequest: function(options) {
return $.ajax({
url: options.url,
data: $.extend({}, options.data, {
// The v parameter specifies the version of the API that YouTube should use to handle the API request.
v: 2,
// The alt parameter specifies the format of the feed to be returned.
/*jslint node: true*/
// Provides methods which may be executed from the command prompt by being in this files cwd.
// Type grunt to run the default method, or "grunt paramater" to run a specific method.
//
// Options:
// * grunt: Start up a server, run Jasmine test cases, watch for changes.
// * grunt test: Start up a server, run Jasmine test cases.
// * grunt lint: Display linter errors about the project
// * grunt dist: Create a dist folder with a .zip containing the extension ready to be uploaded
//
//NOTE: BUG ISSUE 949 HAS BEEN PATCHED IN THIS VERSION: http://code.google.com/p/jstree/issues/detail?id=949 THE DEFAULT THEMES VALUE HAS BEEN SET.
/*
* jsTree 1.0-rc3
* http://jstree.com/
*
* Copyright (c) 2010 Ivan Bozhanov (vakata.com)
*
* Licensed same as jquery - under the terms of either the MIT License or the GPL Version 2 License
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
// Enables progressive rendering of children by keeping track of indices which are currently rendered.
minRenderedIndex: 0,
maxRenderedIndex: 25,
addItemView: function(item, ItemView, index) {
if (index >= this.minRenderedIndex || index < this.maxRenderedIndex) {
Backbone.Marionette.CompositeView.prototype.addItemView.apply(this, arguments);
}
},
(function () {
var g, h = this;
function l(a) {
a = a.split(".");
for (var b = h, c; c = a.shift();)
if (null != b[c]) b = b[c];
else return null;
return b
}