Skip to content

Instantly share code, notes, and snippets.

View mataspetrikas's full-sized avatar
🤔
busy busy

Matas Petrikas mataspetrikas

🤔
busy busy
View GitHub Profile
@mataspetrikas
mataspetrikas / gist:941963
Created April 26, 2011 08:01
jump link with the SC JS API
$('a.jump').live('click', function(event) {
event.preventDefault();
var targetTime = $(this).attr('data-jump-target');
player.api_play();
player.api_seekTo(targetTime);
});
// a typical link woul look like this, where the value in the data-jump-target is the time you want to jump to
<a href="#jump" class="jump" data-jump-target="455">Jump to 455</a>
@mataspetrikas
mataspetrikas / activate tracks
Created April 20, 2011 07:40
activate tracks without playing in the SoundCloud custom player
// add this after the '.sc-trackslist li' click listener
$(document).bind('activateTrack', function(event) {
var $track = $(event.target),
$player = $track.closest('.sc-player'),
trackId = $track.data('sc-track').id;
updateTrackInfo($player, trackId);
$track.addClass('active').siblings('li').removeClass('active');
$('.artworks li', $player).each(function(index) {
@mataspetrikas
mataspetrikas / gist:874096
Created March 17, 2011 10:08
smoother playing progress in the custom SoundCLoud player
.sc-scrubber .sc-buffer, .sc-scrubber .sc-played {
width: 0;
-webkit-transition: width 1s linear;
-moz-transition: width 1s linear;
transition: width 1s linear;
}
@mataspetrikas
mataspetrikas / gist:840452
Created February 23, 2011 13:55
Backbone.View event inheritance problem
var SuperView = Backbone.View.extend({
events: {
"click a.foo": "onFooClick"
},
onFooClick: function(event) {
alert('onFooClick!');
}
});
var SubView = SuperView.extend({
@mataspetrikas
mataspetrikas / gist:811849
Created February 4, 2011 21:52
adding pushState support in BackBone.js (experimental)
// browser history with HTML5 support
(function() {
var loc = window.location,
pushSupport = !!(window.history && window.history.pushState),
hashStrip = /^#*/;
// add HTML5 support to Backbone.history, drop the old IE stuff
_.extend(Backbone.History.prototype, {
getFragment : function(l) {
$.getJSON("http://api.soundcloud.com/tracks?callback=?",
{
consumer_key: YOUR_CONSUMERKEY,
format: "json"
},
function(data) {
console.log("data from SoundCloud!", data);
});
@mataspetrikas
mataspetrikas / SoundCloudBBCode.html
Created December 16, 2010 17:12
SoundCloud BB code
<object height="81" width="80%"><param name="movie" value="http://player.soundcloud.com/player.swf?url={param}"></param><param name="allowscriptaccess" value="always"></param><embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url={param}" type="application/x-shockwave-flash" width="80%"></embed></object> <a href="{param}">{param}</a>
@mataspetrikas
mataspetrikas / gist:715823
Created November 25, 2010 19:43
cacheable JSONP
(function($){
// simple js string hashing
var simpleHash = function(s, tableSize) {
var i, hash = 0;
for (i = 0, l = s.length; i < l; i += 1) {
hash += (s[i].charCodeAt() * (i+1));
}
return Math.abs(hash) % tableSize;
};
@mataspetrikas
mataspetrikas / code.html
Created November 23, 2010 10:03
generated embed code
<object height="81" width="100%"><param name="movie" value="http://player.soundcloud.com/player.swf?url=http://soundcloud.com/ronniepollock/dysfunctional-tb303-dont-leave-me-tonight&amp;g=bb"></param><param name="allowscriptaccess" value="always"></param><embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url=http://soundcloud.com/ronniepollock/dysfunctional-tb303-dont-leave-me-tonight&amp;g=bb" type="application/x-shockwave-flash" width="100%"></embed></object> <a href="http://soundcloud.com/ronniepollock/dysfunctional-tb303-dont-leave-me-tonight">[NAME]</a>
@mataspetrikas
mataspetrikas / Polling for track positon
Created November 18, 2010 10:21
Polling for track positon with SoundCloud JS api
var positionInterval;
var startPolling = function(player) {
positionInterval = setInterval(function() {
var trackPosition = player.api_getTrackPosition();
// do something with the trackPosition
}, 500);
};
var stopPolling = function() {
clearInterval(positionInterval);
positionInterval = null;