-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8ed6031
Showing
6 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Sir Trevor Blocks | ||
|
||
A place for Sir Trevor Blocks that don't come packaged as the default set. | ||
|
||
# Documentation | ||
|
||
Each BlockType should be documented with a header | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
Gist BlockType | ||
*/ | ||
|
||
var template = '<p>Drop gist link here</p><div class="input text"><label>or paste URL:</label><input type="text" class="paste-block"></div>'; | ||
var gist_template = '<div class="gist"><%= div %></div>'; | ||
|
||
var Gist = SirTrevor.BlockType.extend({ | ||
|
||
title: "Gist", | ||
className: "gist-block", | ||
dropEnabled: true, | ||
|
||
editorHTML: "<div></div>", | ||
|
||
dropzoneHTML: template, | ||
|
||
validate: function() {}, | ||
|
||
loadData: function(data){ | ||
this.loading(); | ||
this._super("loadGist", data.id); | ||
}, | ||
|
||
loadGist: function(gist_id) { | ||
// Get the gist data (too big to store in JSON) | ||
var callbackSuccess = function(data) { | ||
// Streamlined (we can't store the div item, we'll need to grab it each time) | ||
var obj = { | ||
id: gist_id | ||
}; | ||
|
||
var dataStruct = this.$el.data('block'); | ||
dataStruct.data = obj; | ||
|
||
$('head').append('<link rel="stylesheet" href="'+data.stylesheet+'" type="text/css">'); | ||
|
||
this.$el.html(data.div); | ||
this.$dropzone.fadeOut(250); | ||
this.$el.show(); | ||
this.ready(); | ||
}; | ||
|
||
var callbackFail = function(){ | ||
this.ready(); | ||
}; | ||
|
||
// Make our AJAX call | ||
$.ajax({ | ||
url: "https://gist.github.com/" + gist_id + ".json", | ||
dataType: "JSONP", | ||
success: _.bind(callbackSuccess, this), | ||
error: _.bind(callbackFail, this) | ||
}); | ||
}, | ||
|
||
onContentPasted: function(event){ | ||
// Content pasted. Delegate to the drop parse method | ||
var input = $(event.target), | ||
val = input.val(); | ||
this._super("handleDropPaste", val); | ||
}, | ||
|
||
handleDropPaste: function(url) { | ||
if(_.isURI(url)) | ||
{ | ||
if (url.indexOf("gist") != -1) { | ||
// Twitter status | ||
var ID = url.match(/[^\/]+$/); | ||
|
||
if (!_.isEmpty(ID)) { | ||
this.loading(); | ||
|
||
ID = ID[0]; | ||
this._super("loadGist", ID); | ||
} | ||
} | ||
} | ||
}, | ||
|
||
onDrop: function(transferData){ | ||
var url = transferData.getData('text/plain'); | ||
this._super("handleDropPaste", url); | ||
} | ||
}); | ||
|
||
SirTrevor.BlockTypes.Gist = new Gist(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Text Block | ||
*/ | ||
|
||
var md_template = '<div class="expanding-textarea"><pre><span></span><br></pre><textarea class="required <%= className %>"></textarea></div>'; | ||
|
||
var Markdown = SirTrevor.BlockType.extend({ | ||
|
||
title: "Markdown", | ||
className: "markdown", | ||
|
||
editorHTML: function() { | ||
return _.template(md_template, this); | ||
}, | ||
|
||
loadData: function(data){ | ||
this.$('.markdown').html(data.text); | ||
}, | ||
|
||
onBlockRender: function(){ | ||
/* Make our expanding text area */ | ||
|
||
var cont = this.$('.expanding-textarea'), | ||
area = cont.find('textarea'), | ||
span = cont.find('span'); | ||
|
||
area.bind('input', function(){ | ||
span.text(area.val()); | ||
}); | ||
|
||
cont.addClass('active'); | ||
}, | ||
|
||
toData: function() { | ||
var bl = this.$el, | ||
dataStruct = bl.data('block'), | ||
content; | ||
|
||
dataStruct.data.text = this.$('.markdown').val(); | ||
} | ||
}); | ||
|
||
SirTrevor.BlockTypes.Markdown = new Markdown(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Ordered List | ||
*/ | ||
|
||
var od_template = '<div class="text-block <%= className %>" contenteditable="true"></div>'; | ||
|
||
var OrderedList = SirTrevor.BlockType.extend({ | ||
|
||
title: "List", | ||
className: "ordered-list", | ||
|
||
editorHTML: function() { | ||
return _.template(od_template, this); | ||
}, | ||
|
||
onBlockRender: function(){ | ||
|
||
this.$('.text-block').bind('click', function(){ | ||
if($(this).html().length === 0){ | ||
document.execCommand("insertOrderedList",false,false); | ||
} | ||
}); | ||
|
||
// Put in a list | ||
if (_.isEmpty(this.data)) { | ||
this.$('.text-block').focus().click(); | ||
} | ||
}, | ||
|
||
loadData: function(data){ | ||
this.$('.text-block').html("<ol>" + this.instance._toHTML(data.text, this.type) + "</ol>"); | ||
}, | ||
|
||
toMarkdown: function(markdown){ | ||
return markdown.replace(/<\/li>/mg,"\n") | ||
.replace(/<\/?[^>]+(>|$)/g, "") | ||
.replace(/^(.+)$/mg," 1. $1"); | ||
}, | ||
|
||
toHTML: function(html) { | ||
return html.replace(/^ 1. (.+)$/mg,"<li>$1</li>"); | ||
} | ||
}); | ||
|
||
SirTrevor.BlockTypes.OrderedList = new OrderedList(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
var t_template = '<p>Drop tweet link here</p><div class="input text"><label>or paste URL:</label><input type="text" class="paste-block"></div>'; | ||
var tweet_template = '<div class="tweet media"><div class="img"><img src="<%= user.profile_image_url %>" class="tweet-avatar"></div><div class="bd tweet-body"><p><a href="http://twitter.com/#!/<%= user.screen_name %>">@<%= user.screen_name %></a>: <%= text %></p><time><%= created_at %></time></div></div>'; | ||
|
||
var Tweet = SirTrevor.BlockType.extend({ | ||
|
||
title: "Tweet", | ||
className: "tweet", | ||
dropEnabled: true, | ||
|
||
dropzoneHTML: template, | ||
|
||
validate: function() {}, | ||
|
||
loadData: function(data){ | ||
this.$block.find(".dropzone").hide(); | ||
this.$el.show(); | ||
this.$el.html(_.template(t_template, data)); | ||
}, | ||
|
||
onContentPasted: function(event){ | ||
// Content pasted. Delegate to the drop parse method | ||
var input = $(event.target), | ||
val = input.val(); | ||
|
||
// Pass this to the same handler as onDrop | ||
this._super("handleTwitterDropPaste", val); | ||
}, | ||
|
||
handleTwitterDropPaste: function(url){ | ||
|
||
if(_.isURI(url)) | ||
{ | ||
if (url.indexOf("twitter") != -1 && url.indexOf("status") != -1) { | ||
// Twitter status | ||
var tweetID = url.match(/[^\/]+$/); | ||
if (!_.isEmpty(tweetID)) { | ||
|
||
this.loading(); | ||
|
||
tweetID = tweetID[0]; | ||
|
||
var tweetCallbackSuccess = function(data) { | ||
// Parse the twitter object into something a bit slimmer.. | ||
var obj = { | ||
user: { | ||
profile_image_url: data.user.profile_image_url, | ||
profile_image_url_https: data.user.profile_image_url_https, | ||
screen_name: data.user.screen_name, | ||
name: data.user.name | ||
}, | ||
text: data.text, | ||
created_at: data.created_at, | ||
status_url: url | ||
}; | ||
|
||
// Save this data on the block | ||
var dataStruct = this.$el.data('block'); | ||
dataStruct.data = obj; | ||
|
||
this.$el.html(_.template(tweet_template, obj)); // Render | ||
this.$dropzone.hide(); | ||
this.$el.show(); | ||
|
||
this.ready(); | ||
}; | ||
|
||
var tweetCallbackFail = function(){ | ||
this.ready(); | ||
}; | ||
|
||
// Make our AJAX call | ||
$.ajax({ | ||
url: "http://api.twitter.com/1/statuses/show/" + tweetID + ".json", | ||
dataType: "JSONP", | ||
success: _.bind(tweetCallbackSuccess, this), | ||
error: _.bind(tweetCallbackFail, this) | ||
}); | ||
} | ||
} | ||
} | ||
|
||
}, | ||
|
||
onDrop: function(transferData){ | ||
var url = transferData.getData('text/plain'); | ||
this._super("handleTwitterDropPaste", url); | ||
} | ||
}); | ||
|
||
SirTrevor.BlockTypes.Tweet = new Tweet(); |