Skip to content

Instantly share code, notes, and snippets.

@p3drosola
Created September 19, 2012 11:59
Show Gist options
  • Save p3drosola/3749285 to your computer and use it in GitHub Desktop.
Save p3drosola/3749285 to your computer and use it in GitHub Desktop.
Task preview
$(function () {
var regex = /\/#!\/projects\/[^\/]+\/tasks\/(\d+)\/?/;
function showModal (model) {
console.log('previewing task#' + model.id, model);
var view, dialog;
view = new Teambox.Views.Thread({model: model});
dialog = (new Teambox.Views.Dialog({
extraClassName: 'share'
, header: 'Task Quickview'
, content: view.render().el
})).open();
dialog.$('.dialog_box').css({width: '600px', marginLeft: '-300px'});
}
$(document).on('click', '.textilized a, .page_content a', function (e) {
console.log('intercepted click on an anchor', e);
var match, model, view, dialog;
if (e.metaKey) {
match = $(this).attr('href').match(regex);
if (match[1]) {
e.preventDefault();
model = Teambox.collections.tasks.get(match[1]);
if (!model){
model = new Teambox.Models.Task({
id: match[1]
});
model.fetch({
success: function (model){
Teambox.collections.tasks.add(model);
showModal(model);
}
});
} else {
showModal(model);
}
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment