From 752f07a6fcc334aacc7d5a39aa725dc3e3baf389 Mon Sep 17 00:00:00 2001 From: Chris Bell Date: Mon, 20 Aug 2012 15:46:01 +0100 Subject: [PATCH] Make blocks use the new block syntax --- src/gist.js | 19 +++++----- src/markdown.js | 15 ++++---- src/ordered-list.js | 12 +++---- src/tweet.js | 87 --------------------------------------------- 4 files changed, 19 insertions(+), 114 deletions(-) delete mode 100644 src/tweet.js diff --git a/src/gist.js b/src/gist.js index 9257dca..5580f2f 100644 --- a/src/gist.js +++ b/src/gist.js @@ -5,7 +5,7 @@ var template = '

Drop gist link here

'; var gist_template = '
<%= div %>
'; -var Gist = SirTrevor.BlockType.extend({ +SirTrevor.Blocks.Gist = SirTrevor.Block.extend({ title: "Gist", className: "gist-block", @@ -16,8 +16,7 @@ var Gist = SirTrevor.BlockType.extend({ dropzoneHTML: template, loadData: function(data){ - this.loading(); - this._super("loadGist", data.id); + this.loadGist(data.id); }, loadGist: function(gist_id) { @@ -33,9 +32,9 @@ var Gist = SirTrevor.BlockType.extend({ $('head').append(''); - this.$el.html(data.div); + this.$editor.html(data.div); this.$dropzone.fadeOut(250); - this.$el.show(); + this.$editor.show(); this.ready(); }; @@ -56,7 +55,7 @@ var Gist = SirTrevor.BlockType.extend({ // Content pasted. Delegate to the drop parse method var input = $(event.target), val = input.val(); - this._super("handleDropPaste", val); + this.handleDropPaste(val); }, handleDropPaste: function(url) { @@ -70,7 +69,7 @@ var Gist = SirTrevor.BlockType.extend({ this.loading(); ID = ID[0]; - this._super("loadGist", ID); + this.loadGist(ID); } } } @@ -78,8 +77,6 @@ var Gist = SirTrevor.BlockType.extend({ onDrop: function(transferData){ var url = transferData.getData('text/plain'); - this._super("handleDropPaste", url); + this.handleDropPaste(url); } -}); - -SirTrevor.BlockTypes.Gist = new Gist(); \ No newline at end of file +}); \ No newline at end of file diff --git a/src/markdown.js b/src/markdown.js index 01e0715..e2eecd4 100644 --- a/src/markdown.js +++ b/src/markdown.js @@ -4,7 +4,7 @@ var md_template = '

'; -var Markdown = SirTrevor.BlockType.extend({ +SirTrevor.Blocks.Markdown = SirTrevor.Block.extend({ title: "Markdown", className: "markdown", @@ -14,13 +14,13 @@ var Markdown = SirTrevor.BlockType.extend({ }, loadData: function(data){ - this.$('.markdown').html(data.text); + this.$$('.markdown').html(data.text); }, onBlockRender: function(){ /* Make our expanding text area */ - var cont = this.$('.expanding-textarea'), + var cont = this.$$('.expanding-textarea'), area = cont.find('textarea'), span = cont.find('span'); @@ -33,11 +33,8 @@ var Markdown = SirTrevor.BlockType.extend({ toData: function() { var bl = this.$el, - dataStruct = bl.data('block'), - content; + dataStruct = bl.data('block'); - dataStruct.data.text = this.$('.markdown').val(); + dataStruct.data.text = this.$$('.markdown').val(); } -}); - -SirTrevor.BlockTypes.Markdown = new Markdown(); \ No newline at end of file +}); \ No newline at end of file diff --git a/src/ordered-list.js b/src/ordered-list.js index 0925a41..92bb0c0 100644 --- a/src/ordered-list.js +++ b/src/ordered-list.js @@ -4,7 +4,7 @@ var od_template = '
'; -var OrderedList = SirTrevor.BlockType.extend({ +SirTrevor.Blocks.Ol = SirTrevor.Block.extend({ title: "List", className: "ordered-list", @@ -15,7 +15,7 @@ var OrderedList = SirTrevor.BlockType.extend({ onBlockRender: function(){ - this.$('.text-block').bind('click', function(){ + this.$$('.text-block').bind('click', function(){ if($(this).html().length === 0){ document.execCommand("insertOrderedList",false,false); } @@ -23,12 +23,12 @@ var OrderedList = SirTrevor.BlockType.extend({ // Put in a list if (_.isEmpty(this.data)) { - this.$('.text-block').focus().click(); + this.$$('.text-block').focus().click(); } }, loadData: function(data){ - this.$('.text-block').html("
    " + this.instance._toHTML(data.text, this.type) + "
"); + this.$$('.text-block').html("
    " + this.instance._toHTML(data.text, this.type) + "
"); }, toMarkdown: function(markdown){ @@ -40,6 +40,4 @@ var OrderedList = SirTrevor.BlockType.extend({ toHTML: function(html) { return html.replace(/^ 1. (.+)$/mg,"
  • $1
  • "); } -}); - -SirTrevor.BlockTypes.OrderedList = new OrderedList(); \ No newline at end of file +}); \ No newline at end of file diff --git a/src/tweet.js b/src/tweet.js deleted file mode 100644 index 5ab38df..0000000 --- a/src/tweet.js +++ /dev/null @@ -1,87 +0,0 @@ -var t_template = '

    Drop tweet link here

    '; -var tweet_template = '

    @<%= user.screen_name %>: <%= text %>

    '; - -var Tweet = SirTrevor.BlockType.extend({ - - title: "Tweet", - className: "tweet", - dropEnabled: true, - - dropzoneHTML: t_template, - - loadData: function(data){ - this.$block.find(".dropzone").hide(); - this.$el.show(); - this.$el.html(_.template(tweet_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(); \ No newline at end of file