// (c) 2012 Kyle Graehl / Patrick Williams, BitTorrent Inc.
// Btapp may be freely distributed under the MIT license.
// For all details and documentation:
// http://pwmckenna.github.com/btapp
(function() {
"use strict";
function assert(b, err) { if(!b) { throw err; } }
//validate dependencies
assert(typeof JSON !== 'undefined', 'JSON is a hard dependency');
assert(typeof _ !== 'undefined', 'underscore/lodash is a hard dependency');
assert(typeof jQuery !== 'undefined', 'jQuery is a hard dependency');
function isMac() {
var match = navigator.userAgent.match(/Macintosh/);
return match !== undefined && match !== null;
}
var add_plugin = _.memoize(function(mime_type) {
var ret = new jQuery.Deferred();
var obj = document.createElement('object');
var onload = mime_type + '_onload';
window[onload] = function() {
ret.resolve();
};
var div = document.createElement('div');
jQuery(div).css({'position':'absolute','left':'-999em','z-index':-1});
div.innerHTML =
'';
document.body.appendChild(div);
return ret;
});
//utility function to wait for some condition
//this ends up being helpful as we toggle between a flow chart and a state diagram
function when(condition, functionality, interval) {
var when_func = function() {
if(condition.call()) {
functionality.call();
} else {
setTimeout(when_func, interval || 500);
}
};
_.defer(when_func);
}
function getCSS(url) {
jQuery(document.createElement('link') ).attr({
href: url,
type: 'text/css',
rel: 'stylesheet'
}).appendTo('head');
}
function initializeFacebox() {
jQuery.facebox.settings.overlay = true; // to disable click outside overlay to disable it
jQuery.facebox.settings.closeImage =
'https://torque.bittorrent.com/facebox/src/closelabel.png';
jQuery.facebox.settings.loadingImage =
'https://torque.bittorrent.com/facebox/src/loading.gif';
jQuery.facebox.settings.opacity = 0.6;
}
this.PluginManagerView = Backbone.View.extend({
initialize: function(options) {
this.model.on('plugin:install_plugin', this.download, this);
this.model.on('plugin:plugin_updated', this.restart, this);
},
setup: function(callback, context) {
//make sure that we've loaded what we need to display
if(typeof jQuery.facebox === 'undefined') {
getCSS('https://torque.bittorrent.com/facebox/src/facebox.css');
jQuery.getScript(
'https://torque.bittorrent.com/facebox/src/facebox.js',
_.bind(this.setup, this, callback, context)
);
return;
}
initializeFacebox();
callback.call(context);
},
restart: function(options) {
options.abort = true;
this.setup(function() {
var dialog = jQuery('
');
dialog.attr('id', 'plugin_download');
dialog.css('position', 'absolute');
dialog.css('height', '200px');
dialog.css('width', '400px');
dialog.css('left', '%50');
dialog.css('margin-left', '-200px');
var paragraph = jQuery('');
paragraph.text('The ' + this.model.get('product') + ' plugin needs to complete an update. Please restart your browser.');
dialog.append(paragraph);
dialog.hide();
jQuery('body').append(dialog);
jQuery.facebox({ div: '#plugin_download' });
}, this);
},
download: function(options) {
options.install = true;
this.setup(function() {
var dialog = jQuery('');
dialog.attr('id', 'plugin_download');
dialog.css('position', 'absolute');
dialog.css('height', '200px');
dialog.css('width', '400px');
dialog.css('left', '%50');
dialog.css('margin-left', '-200px');
var button_url = this.model.get('download_url');
var html ='
' +
'This site requires the ' + this.model.get('product') + ' plugin. ' +
'By installing this software, you are agreeing to the EULA