From 7a74dfff4311a682669d2235ace0a7ab0cde9797 Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 15 May 2012 02:22:57 +0530 Subject: [PATCH] use jquery.pandoravideo.js --- itf/frontpage/views.py | 2 + itf/settings.py | 11 +- itf/static/js/jquery.pandoravideo.js | 362 ++++++++++++++++++++ itf/templates/modules/festival/meeting.html | 22 +- itf/templates/noel/insidepage.html | 1 + 5 files changed, 393 insertions(+), 5 deletions(-) create mode 100644 itf/static/js/jquery.pandoravideo.js diff --git a/itf/frontpage/views.py b/itf/frontpage/views.py index 81ac2b7..6764c83 100755 --- a/itf/frontpage/views.py +++ b/itf/frontpage/views.py @@ -8,6 +8,7 @@ from django import forms from django.forms.widgets import Textarea from django.utils.html import urlize from django.core.mail import send_mail +from django.views.decorators.cache import cache_page class ContactForm(forms.Form): name = forms.CharField(max_length=255) @@ -32,6 +33,7 @@ class ContactForm(forms.Form): } ''' +@cache_page(60 * 30) def index(request): try: tApi = twitter.Api() diff --git a/itf/settings.py b/itf/settings.py index 69e7787..23e1fbc 100755 --- a/itf/settings.py +++ b/itf/settings.py @@ -64,10 +64,17 @@ DATABASES = { TWITTER_ID = "sachin_rt" +#CACHES = { +# 'default': { +# 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', +# 'LOCATION': '127.0.0.1:11211', +# } +#} + CACHES = { 'default': { - 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', - 'LOCATION': '127.0.0.1:11211', + 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', + 'LOCATION': join(PROJECT_ROOT, 'cache'), } } diff --git a/itf/static/js/jquery.pandoravideo.js b/itf/static/js/jquery.pandoravideo.js new file mode 100644 index 0000000..637746b --- /dev/null +++ b/itf/static/js/jquery.pandoravideo.js @@ -0,0 +1,362 @@ +'use strict'; + +(function($) { + $.fn.pandoravideo = function(options) { + + //get options, giving preference, in order, to data- attributes defined on the html element, options passed when instantiatiing $(element).pandoravideo(options), defaults. + var options = options || {}, + namespace = options.namespace || "pandora", + $this = this; + + + var optionTypes = { + 'strings': ['api', 'base', 'resolution', 'action', 'id'], + 'integers': ['in', 'out', 'width', 'interval'], + 'arrays': ['layers', 'keys'], + 'booleans': [] + //'functions': ['callback'] FIXME: lets not. + }; + + var dataOptions = $.extend(options, $this.getDataOptions(optionTypes, namespace)); + + var opts = $.extend({ + 'id': 'ABC', //FIXME: throw an error if id is undefined at this point + 'layers': ['transcripts', 'descriptions', 'keywords', 'places'], + 'keys': ['layers'], //data keys to fetch from API call. FIXME: add more apt keys + 'api': "//pad.ma/api/", //pandora instance api end-point - see http://pad.ma/api + 'in': 0, //in point (float, in seconds) of clip + 'out': 0, //out point of clip + 'pandora_base': '//pad.ma/', //pandora instance from where to fetch video and image data + 'resolution': '480p', //resolution of video (96p, 320p, or 480p) + 'width': '640', //display (css) width + 'interval': 300, //interval (in ms) to run updatePlayer polling loop + 'action': 'get', //action POST param to send to url + 'callback': function() { $.noop(); } //function to call after done instantiating pandoraVideo object, called with the object. + }, dataOptions); + + //get the pandora id and instantiate a pandoraVideo object with the current element and render it and execute optional callback + var id = opts.id, + $loading = $('
').addClass("pandoraLoading").text("Loading video...").appendTo($this), + sendData = JSON.stringify({'id': id, 'keys': opts.keys}); + + var deferred = $.post(opts.api, {'action': opts.action, 'data': sendData}, function(response) { + $loading.hide().remove(); + var pandora = new PandoraVideo(id, response.data, $this, opts); + pandora.render(); + opts.callback(pandora); + }, "json"); + + deferred.error(function(data) { + alert("failed to load video data"); + }); + }; + + /* + pandoraVideo class + Parameters: + id: pandora video id + data: data for the video object + $el: + opts: options object + + */ + var PandoraVideo = function(id, data, $el, opts) { + var that = this; + this.id = id; + this.data = data; + this.$el = $el; + this.o = opts; + this.annotPoint = -1; + this.getVideoURL = function() { + return opts.pandora_base + id + "/" + opts.resolution + ".webm"; + }; + + //empties element, appends video widget + this.render = function() { + var that = this; + this.$el.empty(); + this.$el.append(that.getWidget()); + }; + + /* + Get points + */ + var flattenedPoints = []; + $.each(that.o.layers, function(i,layerType) { + $.each(that.data.layers[layerType], function(j,layer) { + flattenedPoints.push(layer['in']); + flattenedPoints.push(layer.out); + }); + }); + this.points = makeArrayUnique(flattenedPoints); + + + this.crossesPoint = function(newPos) { + var that = this; + var positions = [that.annotPoint, newPos].sort(); + return this.points.some(function(point) { + return point >= positions[0] && point <= positions[1]; + }); + }; + + function makeArrayUnique(arr) { + var o = {}, i, l = arr.length, r = []; + for(i=0; i eg. 'width' + */ + this.getOption = function(key) { + return this.o[key] || "invalid option"; + }; + + + //returns widget for this pandoraVideo object + this.getWidget = function() { + var that = this; + var $container = this.$container = $('
').addClass("pandoraContainer"); + var $video = this.$video = $('