Skip to content

Instantly share code, notes, and snippets.

View MeoMix's full-sized avatar

Sean Anderson MeoMix

  • San Francisco, CA
View GitHub Profile
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.
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 () {
// 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,
define([
'utility'
], function (Utility) {
'use strict';
var PlaylistItemView = Backbone.View.extend({
tagName: 'li',
className: 'playlistItem',
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 () {
@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')) {
item.destroy({
data: $.param({
playlistId: playlistId,
userId: loginManager.get('user').get('id')
}),
processData: true,
success: callback,
error: function (error) {
console.error(error);
}
//Create a storage location for the tree view dialog.
var treeViewDialog = $('<div />', {
id: 'TreeViewDialog'
}).appendTo(workflowDialog);
//Create a storage location for the lookup tree which is about to be created inside of our dialog.
var dialogContent = $('<div />', {
id: 'TreeViewDialogContent'
});
dialogContent.appendTo(treeViewDialog);
//Takes a song's UID and returns the index of that song in the playlist if found.
var getSongIndexById = function(songs, id) {
var songIndex = -1;
for (var i = 0; i < songs.length; i++) {
if (songs[i] && songs[i].id === id) {
songIndex = i;
break;
}
}
//Takes a song's UID and returns the index of that song in the playlist if found.
var getSongIndexById = function(songs, id) {
var songIndex = -1;
for (var i = 0; i < songs.length; i++) {
if (songs[i] && songs[i].id === id) {
songIndex = i;
break;
}
}