From 304b708414da43aa0c22de4a4c49fcb90370d8f4 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Fri, 31 Jan 2014 16:11:44 -0500 Subject: [PATCH] cleaned up, but barely. --- .gitignore | 1 - Gruntfile.js | 39 ------- component.json => bower.json | 8 +- codecode.css | 58 +++++++++++ codecode.js | 122 ++++++++++++++++++++++ dist/codecode.js | 193 ----------------------------------- dist/codecode.js.map | 1 - dist/codecode.min.js | 7 -- package.json | 10 -- src/codecode.js | 188 ---------------------------------- 10 files changed, 185 insertions(+), 442 deletions(-) delete mode 100644 .gitignore delete mode 100644 Gruntfile.js rename component.json => bower.json (76%) create mode 100644 codecode.css create mode 100644 codecode.js delete mode 100644 dist/codecode.js delete mode 100644 dist/codecode.js.map delete mode 100644 dist/codecode.min.js delete mode 100644 package.json delete mode 100644 src/codecode.js diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 3c3629e..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index 9c030d6..0000000 --- a/Gruntfile.js +++ /dev/null @@ -1,39 +0,0 @@ -module.exports = function(grunt) { - grunt.loadNpmTasks('grunt-contrib-concat'); - grunt.loadNpmTasks('grunt-contrib-uglify'); - - grunt.initConfig({ - pkg: grunt.file.readJSON('package.json'), - - concat: { - options: { - banner: - "/*!\n" - +" * codecode.\n" - +" * v<%= pkg.version %> @stephenplusplus <%= grunt.template.today('m/d/yy') %>\n" - +" * github.com/stephenplusplus/codecode\n" - +" */\n" - }, - build: { - src: ['src/codecode.js'], - dest: 'dist/codecode.js' - } - }, - - uglify: { - options: { - mangle: true, - compress: true, - preserveComments: 'some', - sourceMap: 'dist/codecode.js.map' - }, - build: { - src: ['dist/codecode.js'], - dest: 'dist/codecode.min.js' - } - } - }); - - grunt.registerTask('build', ['concat:build', 'uglify:build']); - grunt.registerTask('default', ['build']); -}; diff --git a/component.json b/bower.json similarity index 76% rename from component.json rename to bower.json index 56f3226..12e70cf 100644 --- a/component.json +++ b/bower.json @@ -3,9 +3,11 @@ "version": "0.0.3", "author": "Stephen Sawchuk", "description": "codecode allows your readers to dock your syntax-highlighted code blocks to the bottom of the page, allowing them to refer back without losing their place in your article.", - "homepage": "http://stephenplusplus.github.com/codecode", - "main": "./dist/codecode.js", - "readme": "./readme.md", + "homepage": "http://stephenplusplus.github.io/codecode", + "main": [ + "./dist/codecode.js", + "./dist/codecode.css", + ], "repository": { "type": "git", "url": "git://github.com/stephenplusplus/codecode.git" diff --git a/codecode.css b/codecode.css new file mode 100644 index 0000000..cb4f2f3 --- /dev/null +++ b/codecode.css @@ -0,0 +1,58 @@ +.acodecode { + cursor: pointer; +} + +.acodecodeactive { + cursor: default; +} + +.codecodecode { + position: fixed; + z-index: 100; + left: 2%; + bottom: -30px; + width: 96%; + height: 0; + max-height: 270px; + text-align: left; +} + +.codecodecode > div { + box-shadow: 0 0 3px #444; +} + +.codecodecontrols { + height: 30px; + margin-top: -30px; + background-color: #fff; + background-color: rgba(255, 255, 255, .8); + border-radius: 8px 8px 0 0; +} + +.codecodecontrols a { + float: left; + line-height: 30px; + margin-left: 6px; + font-family: Arial; + font-size: 12px; +} + +.codecodecontrols .closeCodeCode { + float: right; + margin-right: 6px; +} + +.codecode, +.acodecode.codecode { + border-radius: 0 !important; + position: relative !important; + width: 100% !important; + margin: 0 !important; + overflow: auto !important; + cursor: default !important; +} + +div.codecode [id^=highlighter] div.bar.show, +div.codecode [id^=highlighter] div.toolbar { + display: none !important; +}; \ No newline at end of file diff --git a/codecode.js b/codecode.js new file mode 100644 index 0000000..cf37d58 --- /dev/null +++ b/codecode.js @@ -0,0 +1,122 @@ +(function ($, win, doc) { + 'use strict'; + + var el = {}; + var codePosition; + + el.body = $(doc.body); + + el.codecodecode = $([ + '
', + '
', + ' go back to the code.', + ' close.', + '
', + '
', + '
' + ].join('\n')); + + el.goBackToTheCode = el.codecodecode.find('.goBackToTheCode'); + el.closeCodeCode = el.codecodecode.find('.closeCodeCode'); + el.codecode = el.codecodecode.find('.codecode'); + + el.body.append(el.codecodecode); + + el.goBackToTheCode.on('click', goBackToTheCode); + el.closeCodeCode.on('click', closeCodeCode); + + function goBackToTheCode(e) { + e.preventDefault(); + + closeCodeCode(); + + el.body.animate({ scrollTop: codePosition - 20 }, 2000); + }; + + function closeCodeCode(e, callback) { + if ($.type(e) === 'object') { + e.preventDefault(); + } + + el.body.off('keyup'); + + el.codecodecode.animate({ bottom: '-300px' }, 300, callback || $.noop); + + $('.acodecodeactive').removeClass('acodecodeactive'); + }; + + function openCodeCode(codeblock) { + el.codecodecode.animate({ bottom: 0 }, 500); + + el.body.on('keyup', function (e) { + if (e.which === 27) { + closeCodeCode(); + } + }); + + codeblock.addClass('acodecodeactive'); + }; + + function bindCodeCodeClick(selector) { + el.body.on('click', selector, function () { + var codeblock = $(this); + var clone; + + if (codeblock.hasClass('acodecodeactive') || + codeblock.hasClass('codecode')) { + return; + } + + codePosition = $(this).position().top; + + clone = codeblock.clone().addClass('codecode'); + + closeCodeCode(null, function () { + el.codecode + .empty() + .append(clone.css('margin', '0 !important')) + .height('auto'); + + el.codecodecode.height( + (el.codecode.height() >= 270) ? 270 : el.codecode.height() + ); + + el.codecode.height('100%'); + }); + + openCodeCode(codeblock); + }); + }; + + $.fn.codecode = function () { + bindCodeCodeClick(this.selector); + + return this.addClass('acodecode'); + }; + + if (typeof SyntaxHighlighter !== 'undefined') { + SyntaxHighlighter.all = (function () { + var callSyntaxHighlighter = SyntaxHighlighter.all; + var syntaxActivated = false; + var checkForSyntaxEls; + var tried = 0; + + function hasSyntaxBeenHighlighted() { + if ($('.syntaxhighlighter').length > 0) { + $('.syntaxhighlighter').codecode(); + syntaxActivated = true; + } + + if (syntaxActivated || tried++ > 50) { + win.clearInterval(checkForSyntaxEls); + } + }; + + return function () { + callSyntaxHighlighter(); + + checkForSyntaxEls = win.setInterval(hasSyntaxBeenHighlighted, 50); + } + })(); + } +})(jQuery, window, document); diff --git a/dist/codecode.js b/dist/codecode.js deleted file mode 100644 index 38a0351..0000000 --- a/dist/codecode.js +++ /dev/null @@ -1,193 +0,0 @@ -/*! - * codecode. - * v0.0.3 @stephenplusplus 4/1/13 - * github.com/stephenplusplus/codecode - */ -(function($, win, doc) { - var styles - ='.acodecode {' - + 'cursor: pointer;' - +'}' - - +'.acodecodeactive {' - + 'cursor: default;' - +'}' - - +'.codecodecode {' - + 'position: fixed;' - + 'z-index: 100;' - + 'left: 2%;' - + 'bottom: -30px;' - + 'width: 96%;' - + 'height: 0;' - + 'max-height: 270px;' - + 'text-align: left;' - +'}' - - +'.codecodecode > div {' - +' box-shadow: 0 0 3px #444;' - +'}' - - +'.codecodecontrols {' - + 'height: 30px;' - + 'margin-top: -30px;' - + 'background-color: #fff;' - + 'background-color: rgba(255, 255, 255, .8);' - + 'border-radius: 8px 8px 0 0;' - +'}' - - +'.codecodecontrols a {' - + 'float: left;' - + 'line-height: 30px;' - + 'margin-left: 6px;' - + 'font-family: Arial;' - + 'font-size: 12px;' - +'}' - - +'.codecodecontrols .closecodecode {' - + 'float: right;' - + 'margin-right: 6px;' - +'}' - - +'.codecode {' - + 'border-radius: 0 !important;' - + 'position: relative !important;' - + 'width: 100% !important;' - + 'margin: 0 !important;' - + 'overflow: auto !important;' - + 'cursor: default !important;' - +'}' - - +'div.codecode [id^=highlighter] div.bar.show,' - +'div.codecode [id^=highlighter] div.toolbar {' - + 'display: none !important;' - +'}'; - - var el = {}; - el.body - = $(doc.body); - - el.codecodecode - = $('
' - + '
' - + 'go back to the code.' - + 'close.' - + '
' - + '
' - +'
'); - - el.gobacktothecode - = el.codecodecode.find('.gobacktothecode'); - - el.closecodecode - = el.codecodecode.find('.closecodecode'); - - el.codecode - = el.codecodecode.find('.codecode'); - - el.body - .append('') - .append(el.codecodecode); - - var codeposition; - - var gobacktothecode = function(e) { - e.preventDefault(); - - closecodecode(); - - el.body.animate({ scrollTop: codeposition - 20 }, 2000); - }; - - var closecodecode = function(e, callback) { - if ($.type(e) === 'object') - e.preventDefault(); - - el.body.off('keyup'); - - el.codecodecode - .animate({ bottom: '-300px' }, 300, callback || $.noop); - - $('.acodecodeactive').removeClass('acodecodeactive'); - }; - - var opencodecode = function(codeblock) { - el.codecodecode - .animate({ bottom: 0 }, 500); - - el.body.on('keyup', function(e) { - if (e.which === 27) - closecodecode(); - }); - - codeblock - .addClass('acodecodeactive'); - }; - - var bindcodecodeclick = function(selector) { - el.body.on('click', selector, function() { - var codeblock = $(this); - - if (codeblock.hasClass('acodecodeactive') || codeblock.hasClass('codecode')) - return; - - codeposition = $(this).position().top; - - var clone = - codeblock - .clone() - .addClass('codecode'); - - closecodecode(null, function() { - el.codecode - .empty() - .append(clone.css('margin', '0 !important')) - .height('auto'); - - el.codecodecode - .height(el.codecode.height() >= 270 ? 270 : el.codecode.height()); - - el.codecode - .height('100%'); - }); - - opencodecode(codeblock); - }); - }; - - el.gobacktothecode - .on('click', gobacktothecode); - - el.closecodecode - .on('click', closecodecode); - - $.fn.codecode = function() { - bindcodecodeclick(this.selector); - - return this.addClass('acodecode'); - }; - - if (typeof SyntaxHighlighter !== 'undefined') - SyntaxHighlighter.all = (function() { - var callsyntaxhighlighter = SyntaxHighlighter.all - , syntaxactivated = false - , checkforsyntaxels - , tried = 0; - - var hassyntaxbeenhighlighted = function() { - if ($('.syntaxhighlighter').length > 0) - $('.syntaxhighlighter').codecode(), - syntaxactivated = true; - - if (syntaxactivated || tried++ > 50) - win.clearInterval(checkforsyntaxels); - }; - - return function() { - callsyntaxhighlighter(); - - checkforsyntaxels = win.setInterval(hassyntaxbeenhighlighted, 50); - } - })(); - -})(jQuery, window, document); diff --git a/dist/codecode.js.map b/dist/codecode.js.map deleted file mode 100644 index 086f2e5..0000000 --- a/dist/codecode.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"dist/codecode.min.js","sources":["dist/codecode.js"],"names":["$","win","doc","styles","el","body","codecodecode","gobacktothecode","find","closecodecode","codecode","append","codeposition","e","preventDefault","animate","scrollTop","callback","type","off","bottom","noop","removeClass","opencodecode","codeblock","on","which","addClass","bindcodecodeclick","selector","this","hasClass","position","top","clone","empty","css","height","fn","SyntaxHighlighter","all","checkforsyntaxels","callsyntaxhighlighter","syntaxactivated","tried","hassyntaxbeenhighlighted","length","clearInterval","setInterval","jQuery","window","document"],"mappings":";;;;;CAKA,SAAUA,EAAGC,EAAKC,GAChB,GAAIC,GACH,k0BA0DGC,IACJA,GAAGC,KACDL,EAAEE,EAAIG,MAERD,EAAGE,aACDN,EAAE,4MAQJI,EAAGG,gBACDH,EAAGE,aAAaE,KAAK,oBAEvBJ,EAAGK,cACDL,EAAGE,aAAaE,KAAK,kBAEvBJ,EAAGM,SACDN,EAAGE,aAAaE,KAAK,aAEvBJ,EAAGC,KACAM,OAAO,UAAUR,EAAO,YACxBQ,OAAOP,EAAGE,aAEb,IAAIM,GAEAL,EAAkB,SAASM,GAC7BA,EAAEC,iBAEFL,IAEAL,EAAGC,KAAKU,SAAUC,UAAWJ,EAAe,IAAM,MAGhDH,EAAgB,SAASI,EAAGI,GACZ,WAAdjB,EAAEkB,KAAKL,IACTA,EAAEC,iBAEJV,EAAGC,KAAKc,IAAI,SAEZf,EAAGE,aACAS,SAAUK,OAAQ,UAAY,IAAKH,GAAYjB,EAAEqB,MAEpDrB,EAAE,oBAAoBsB,YAAY,oBAGhCC,EAAe,SAASC,GAC1BpB,EAAGE,aACAS,SAAUK,OAAQ,GAAK,KAE1BhB,EAAGC,KAAKoB,GAAG,QAAS,SAASZ,GACX,KAAZA,EAAEa,OACJjB,MAGJe,EACGG,SAAS,oBAGVC,EAAoB,SAASC,GAC/BzB,EAAGC,KAAKoB,GAAG,QAASI,EAAU,WAC5B,GAAIL,GAAYxB,EAAE8B,KAElB,KAAIN,EAAUO,SAAS,qBAAsBP,EAAUO,SAAS,YAAhE,CAGAnB,EAAeZ,EAAE8B,MAAME,WAAWC,GAElC,IAAIC,GACFV,EACGU,QACAP,SAAS,WAEdlB,GAAc,KAAM,WAClBL,EAAGM,SACAyB,QACAxB,OAAOuB,EAAME,IAAI,SAAU,iBAC3BC,OAAO,QAEVjC,EAAGE,aACA+B,OAAOjC,EAAGM,SAAS2B,UAAY,IAAM,IAAMjC,EAAGM,SAAS2B,UAE1DjC,EAAGM,SACA2B,OAAO,UAGZd,EAAaC,MAIjBpB,GAAGG,gBACAkB,GAAG,QAASlB,GAEfH,EAAGK,cACAgB,GAAG,QAAShB,GAEfT,EAAEsC,GAAG5B,SAAW,WAGd,MAFAkB,GAAkBE,KAAKD,UAEhBC,KAAKH,SAAS,cAGU,mBAAtBY,qBACTA,kBAAkBC,IAAM,WACtB,GAEIC,GAFAC,EAAwBH,kBAAkBC,IAC1CG,GAAkB,EAElBC,EAAQ,EAERC,EAA2B,WACzB7C,EAAE,sBAAsB8C,OAAS,IACnC9C,EAAE,sBAAsBU,WACxBiC,GAAkB,IAEhBA,GAAmBC,IAAU,KAC/B3C,EAAI8C,cAAcN,GAGtB,OAAO,YACLC,IAEAD,EAAoBxC,EAAI+C,YAAYH,EAA0B,WAInEI,OAAQC,OAAQC"} \ No newline at end of file diff --git a/dist/codecode.min.js b/dist/codecode.min.js deleted file mode 100644 index 63c8890..0000000 --- a/dist/codecode.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * codecode. - * v0.0.3 @stephenplusplus 4/1/13 - * github.com/stephenplusplus/codecode - */ -(function(o,e,c){var d=".acodecode {cursor: pointer;}.acodecodeactive {cursor: default;}.codecodecode {position: fixed;z-index: 100;left: 2%;bottom: -30px;width: 96%;height: 0;max-height: 270px;text-align: left;}.codecodecode > div { box-shadow: 0 0 3px #444;}.codecodecontrols {height: 30px;margin-top: -30px;background-color: #fff;background-color: rgba(255, 255, 255, .8);border-radius: 8px 8px 0 0;}.codecodecontrols a {float: left;line-height: 30px;margin-left: 6px;font-family: Arial;font-size: 12px;}.codecodecontrols .closecodecode {float: right;margin-right: 6px;}.codecode {border-radius: 0 !important;position: relative !important;width: 100% !important;margin: 0 !important;overflow: auto !important;cursor: default !important;}div.codecode [id^=highlighter] div.bar.show,div.codecode [id^=highlighter] div.toolbar {display: none !important;}",t={};t.body=o(c.body),t.codecodecode=o('
'),t.gobacktothecode=t.codecodecode.find(".gobacktothecode"),t.closecodecode=t.codecodecode.find(".closecodecode"),t.codecode=t.codecodecode.find(".codecode"),t.body.append("").append(t.codecodecode);var i,a=function(o){o.preventDefault(),n(),t.body.animate({scrollTop:i-20},2e3)},n=function(e,c){"object"===o.type(e)&&e.preventDefault(),t.body.off("keyup"),t.codecodecode.animate({bottom:"-300px"},300,c||o.noop),o(".acodecodeactive").removeClass("acodecodeactive")},r=function(o){t.codecodecode.animate({bottom:0},500),t.body.on("keyup",function(o){27===o.which&&n()}),o.addClass("acodecodeactive")},l=function(e){t.body.on("click",e,function(){var e=o(this);if(!e.hasClass("acodecodeactive")&&!e.hasClass("codecode")){i=o(this).position().top;var c=e.clone().addClass("codecode");n(null,function(){t.codecode.empty().append(c.css("margin","0 !important")).height("auto"),t.codecodecode.height(t.codecode.height()>=270?270:t.codecode.height()),t.codecode.height("100%")}),r(e)}})};t.gobacktothecode.on("click",a),t.closecodecode.on("click",n),o.fn.codecode=function(){return l(this.selector),this.addClass("acodecode")},"undefined"!=typeof SyntaxHighlighter&&(SyntaxHighlighter.all=function(){var c,d=SyntaxHighlighter.all,t=!1,i=0,a=function(){o(".syntaxhighlighter").length>0&&(o(".syntaxhighlighter").codecode(),t=!0),(t||i++>50)&&e.clearInterval(c)};return function(){d(),c=e.setInterval(a,50)}}())})(jQuery,window,document); -//@ sourceMappingURL=dist/codecode.js.map \ No newline at end of file diff --git a/package.json b/package.json deleted file mode 100644 index b43f1a2..0000000 --- a/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "codecode", - "version": "0.0.3", - "author": "Stephen Sawchuk", - "dependencies": { - "grunt": "~0.4.1", - "grunt-contrib-uglify": "~0.2.0", - "grunt-contrib-concat": "~0.1.3" - } -} diff --git a/src/codecode.js b/src/codecode.js deleted file mode 100644 index 1f0cf81..0000000 --- a/src/codecode.js +++ /dev/null @@ -1,188 +0,0 @@ -(function($, win, doc) { - var styles - ='.acodecode {' - + 'cursor: pointer;' - +'}' - - +'.acodecodeactive {' - + 'cursor: default;' - +'}' - - +'.codecodecode {' - + 'position: fixed;' - + 'z-index: 100;' - + 'left: 2%;' - + 'bottom: -30px;' - + 'width: 96%;' - + 'height: 0;' - + 'max-height: 270px;' - + 'text-align: left;' - +'}' - - +'.codecodecode > div {' - +' box-shadow: 0 0 3px #444;' - +'}' - - +'.codecodecontrols {' - + 'height: 30px;' - + 'margin-top: -30px;' - + 'background-color: #fff;' - + 'background-color: rgba(255, 255, 255, .8);' - + 'border-radius: 8px 8px 0 0;' - +'}' - - +'.codecodecontrols a {' - + 'float: left;' - + 'line-height: 30px;' - + 'margin-left: 6px;' - + 'font-family: Arial;' - + 'font-size: 12px;' - +'}' - - +'.codecodecontrols .closecodecode {' - + 'float: right;' - + 'margin-right: 6px;' - +'}' - - +'.codecode {' - + 'border-radius: 0 !important;' - + 'position: relative !important;' - + 'width: 100% !important;' - + 'margin: 0 !important;' - + 'overflow: auto !important;' - + 'cursor: default !important;' - +'}' - - +'div.codecode [id^=highlighter] div.bar.show,' - +'div.codecode [id^=highlighter] div.toolbar {' - + 'display: none !important;' - +'}'; - - var el = {}; - el.body - = $(doc.body); - - el.codecodecode - = $('
' - + '
' - + 'go back to the code.' - + 'close.' - + '
' - + '
' - +'
'); - - el.gobacktothecode - = el.codecodecode.find('.gobacktothecode'); - - el.closecodecode - = el.codecodecode.find('.closecodecode'); - - el.codecode - = el.codecodecode.find('.codecode'); - - el.body - .append('') - .append(el.codecodecode); - - var codeposition; - - var gobacktothecode = function(e) { - e.preventDefault(); - - closecodecode(); - - el.body.animate({ scrollTop: codeposition - 20 }, 2000); - }; - - var closecodecode = function(e, callback) { - if ($.type(e) === 'object') - e.preventDefault(); - - el.body.off('keyup'); - - el.codecodecode - .animate({ bottom: '-300px' }, 300, callback || $.noop); - - $('.acodecodeactive').removeClass('acodecodeactive'); - }; - - var opencodecode = function(codeblock) { - el.codecodecode - .animate({ bottom: 0 }, 500); - - el.body.on('keyup', function(e) { - if (e.which === 27) - closecodecode(); - }); - - codeblock - .addClass('acodecodeactive'); - }; - - var bindcodecodeclick = function(selector) { - el.body.on('click', selector, function() { - var codeblock = $(this); - - if (codeblock.hasClass('acodecodeactive') || codeblock.hasClass('codecode')) - return; - - codeposition = $(this).position().top; - - var clone = - codeblock - .clone() - .addClass('codecode'); - - closecodecode(null, function() { - el.codecode - .empty() - .append(clone.css('margin', '0 !important')) - .height('auto'); - - el.codecodecode - .height(el.codecode.height() >= 270 ? 270 : el.codecode.height()); - - el.codecode - .height('100%'); - }); - - opencodecode(codeblock); - }); - }; - - el.gobacktothecode - .on('click', gobacktothecode); - - el.closecodecode - .on('click', closecodecode); - - $.fn.codecode = function() { - bindcodecodeclick(this.selector); - - return this.addClass('acodecode'); - }; - - if (typeof SyntaxHighlighter !== 'undefined') - SyntaxHighlighter.all = (function() { - var callsyntaxhighlighter = SyntaxHighlighter.all - , syntaxactivated = false - , checkforsyntaxels - , tried = 0; - - var hassyntaxbeenhighlighted = function() { - if ($('.syntaxhighlighter').length > 0) - $('.syntaxhighlighter').codecode(), - syntaxactivated = true; - - if (syntaxactivated || tried++ > 50) - win.clearInterval(checkforsyntaxels); - }; - - return function() { - callsyntaxhighlighter(); - - checkforsyntaxels = win.setInterval(hassyntaxbeenhighlighted, 50); - } - })(); - -})(jQuery, window, document);