From 58c7a4ee1d2f2bd14cf8f5116d850c9f2b9cf6e8 Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Sat, 13 Jul 2013 15:18:57 -0400 Subject: [PATCH 1/2] javascript tweaks --- _includes/footer.html | 11 ++ _includes/header.html | 15 +- javascripts/ZeroClipboard.js | 334 +---------------------------------- javascripts/app.coffee | 62 +++++++ javascripts/app.js | 121 ++++++++----- javascripts/clipboard.js | 20 --- 6 files changed, 154 insertions(+), 409 deletions(-) create mode 100644 javascripts/app.coffee delete mode 100644 javascripts/clipboard.js diff --git a/_includes/footer.html b/_includes/footer.html index ac077cc..156d6ed 100644 --- a/_includes/footer.html +++ b/_includes/footer.html @@ -11,5 +11,16 @@ + + + + + {% if page.layout == "license" %} + + {% endif %} + + + + \ No newline at end of file diff --git a/_includes/header.html b/_includes/header.html index 31c20b5..936f804 100644 --- a/_includes/header.html +++ b/_includes/header.html @@ -1,24 +1,19 @@ + {% if page.title %}{{ page.title }} - {% endif %}{{ site.title}} + + - - - - + - -{% if page.layout == "license" %} - - -{% endif %} - + diff --git a/javascripts/ZeroClipboard.js b/javascripts/ZeroClipboard.js index 9daefbb..6cfe271 100644 --- a/javascripts/ZeroClipboard.js +++ b/javascripts/ZeroClipboard.js @@ -1,333 +1 @@ -/*! - * zeroclipboard - * The Zero Clipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie, and a JavaScript interface. - * Copyright 2012 Jon Rohan, James M. Greene, . - * Released under the MIT license - * http://jonrohan.github.com/ZeroClipboard/ - * v1.1.6 - */(function() { - "use strict"; - var _getStyle = function(el, prop) { - var y = el.style[prop]; - if (el.currentStyle) y = el.currentStyle[prop]; else if (window.getComputedStyle) y = document.defaultView.getComputedStyle(el, null).getPropertyValue(prop); - if (y == "auto" && prop == "cursor") { - var possiblePointers = [ "a" ]; - for (var i = 0; i < possiblePointers.length; i++) { - if (el.tagName.toLowerCase() == possiblePointers[i]) { - return "pointer"; - } - } - } - return y; - }; - var _elementMouseOver = function(event) { - if (!ZeroClipboard.prototype._singleton) return; - if (!event) { - event = window.event; - } - var target; - if (this !== window) { - target = this; - } else if (event.target) { - target = event.target; - } else if (event.srcElement) { - target = event.srcElement; - } - ZeroClipboard.prototype._singleton.setCurrent(target); - }; - var _addEventHandler = function(element, method, func) { - if (element.addEventListener) { - element.addEventListener(method, func, false); - } else if (element.attachEvent) { - element.attachEvent("on" + method, func); - } - }; - var _removeEventHandler = function(element, method, func) { - if (element.removeEventListener) { - element.removeEventListener(method, func, false); - } else if (element.detachEvent) { - element.detachEvent("on" + method, func); - } - }; - var _addClass = function(element, value) { - if (element.addClass) { - element.addClass(value); - return element; - } - if (value && typeof value === "string") { - var classNames = (value || "").split(/\s+/); - if (element.nodeType === 1) { - if (!element.className) { - element.className = value; - } else { - var className = " " + element.className + " ", setClass = element.className; - for (var c = 0, cl = classNames.length; c < cl; c++) { - if (className.indexOf(" " + classNames[c] + " ") < 0) { - setClass += " " + classNames[c]; - } - } - element.className = setClass.replace(/^\s+|\s+$/g, ""); - } - } - } - return element; - }; - var _removeClass = function(element, value) { - if (element.removeClass) { - element.removeClass(value); - return element; - } - if (value && typeof value === "string" || value === undefined) { - var classNames = (value || "").split(/\s+/); - if (element.nodeType === 1 && element.className) { - if (value) { - var className = (" " + element.className + " ").replace(/[\n\t]/g, " "); - for (var c = 0, cl = classNames.length; c < cl; c++) { - className = className.replace(" " + classNames[c] + " ", " "); - } - element.className = className.replace(/^\s+|\s+$/g, ""); - } else { - element.className = ""; - } - } - } - return element; - }; - var _getDOMObjectPosition = function(obj) { - var info = { - left: 0, - top: 0, - width: obj.width || obj.offsetWidth || 0, - height: obj.height || obj.offsetHeight || 0, - zIndex: 9999 - }; - var zi = _getStyle(obj, "zIndex"); - if (zi && zi != "auto") { - info.zIndex = parseInt(zi, 10); - } - while (obj) { - var borderLeftWidth = parseInt(_getStyle(obj, "borderLeftWidth"), 10); - var borderTopWidth = parseInt(_getStyle(obj, "borderTopWidth"), 10); - info.left += isNaN(obj.offsetLeft) ? 0 : obj.offsetLeft; - info.left += isNaN(borderLeftWidth) ? 0 : borderLeftWidth; - info.top += isNaN(obj.offsetTop) ? 0 : obj.offsetTop; - info.top += isNaN(borderTopWidth) ? 0 : borderTopWidth; - obj = obj.offsetParent; - } - return info; - }; - var _noCache = function(path) { - return (path.indexOf("?") >= 0 ? "&" : "?") + "nocache=" + (new Date).getTime(); - }; - var _vars = function(options) { - var str = []; - if (options.trustedDomains) { - if (options.trustedDomains.length) { - str.push("trustedDomain=" + options.trustedDomains.join(",")); - } else { - str.push("trustedDomain=" + options.trustedDomains); - } - } - return str.join("&"); - }; - var _inArray = function(elem, array) { - if (array.indexOf) { - return array.indexOf(elem); - } - for (var i = 0, length = array.length; i < length; i++) { - if (array[i] === elem) { - return i; - } - } - return -1; - }; - var _prepGlue = function(elements) { - if (typeof elements === "string") throw new TypeError("ZeroClipboard doesn't accept query strings."); - if (!elements.length) return [ elements ]; - return elements; - }; - var ZeroClipboard = function(elements, options) { - if (elements) (ZeroClipboard.prototype._singleton || this).glue(elements); - if (ZeroClipboard.prototype._singleton) return ZeroClipboard.prototype._singleton; - ZeroClipboard.prototype._singleton = this; - this.options = {}; - for (var kd in _defaults) this.options[kd] = _defaults[kd]; - for (var ko in options) this.options[ko] = options[ko]; - this.handlers = {}; - if (ZeroClipboard.detectFlashSupport()) _bridge(); - }; - var currentElement, gluedElements = []; - ZeroClipboard.prototype.setCurrent = function(element) { - currentElement = element; - this.reposition(); - this.setText(this.options.text || element.getAttribute("data-clipboard-text") || document.getElementById(element.getAttribute("data-clipboard-target")).innerHTML); - if (element.getAttribute("title")) { - this.setTitle(element.getAttribute("title")); - } - this.setHandCursor(_getStyle(element, "cursor") == "pointer"); - }; - ZeroClipboard.prototype.setText = function(newText) { - if (newText && newText !== "") { - this.options.text = newText; - if (this.ready()) this.flashBridge.setText(newText); - } - }; - ZeroClipboard.prototype.setTitle = function(newTitle) { - if (newTitle && newTitle !== "") this.htmlBridge.setAttribute("title", newTitle); - }; - ZeroClipboard.prototype.setSize = function(width, height) { - if (this.ready()) this.flashBridge.setSize(width, height); - }; - ZeroClipboard.prototype.setHandCursor = function(enabled) { - if (this.ready()) this.flashBridge.setHandCursor(enabled); - }; - ZeroClipboard.version = "1.1.6"; - var _defaults = { - moviePath: "ZeroClipboard.swf", - trustedDomains: null, - text: null, - hoverClass: "zeroclipboard-is-hover", - activeClass: "zeroclipboard-is-active" - }; - ZeroClipboard.setDefaults = function(options) { - for (var ko in options) _defaults[ko] = options[ko]; - }; - ZeroClipboard.destroy = function() { - ZeroClipboard.prototype._singleton.unglue(gluedElements); - var bridge = ZeroClipboard.prototype._singleton.htmlBridge; - bridge.parentNode.removeChild(bridge); - delete ZeroClipboard.prototype._singleton; - }; - ZeroClipboard.detectFlashSupport = function() { - var hasFlash = false; - try { - if (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) { - hasFlash = true; - } - } catch (error) { - if (navigator.mimeTypes["application/x-shockwave-flash"]) { - hasFlash = true; - } - } - return hasFlash; - }; - var _bridge = function() { - var client = ZeroClipboard.prototype._singleton; - client.htmlBridge = document.getElementById("global-zeroclipboard-html-bridge"); - if (client.htmlBridge) { - client.flashBridge = document["global-zeroclipboard-flash-bridge"]; - return; - } - var html = ' '; - client.htmlBridge = document.createElement("div"); - client.htmlBridge.id = "global-zeroclipboard-html-bridge"; - client.htmlBridge.setAttribute("class", "global-zeroclipboard-container"); - client.htmlBridge.setAttribute("data-clipboard-ready", false); - client.htmlBridge.style.position = "absolute"; - client.htmlBridge.style.left = "-9999px"; - client.htmlBridge.style.top = "-9999px"; - client.htmlBridge.style.width = "15px"; - client.htmlBridge.style.height = "15px"; - client.htmlBridge.style.zIndex = "9999"; - client.htmlBridge.innerHTML = html; - document.body.appendChild(client.htmlBridge); - client.flashBridge = document["global-zeroclipboard-flash-bridge"]; - }; - ZeroClipboard.prototype.resetBridge = function() { - this.htmlBridge.style.left = "-9999px"; - this.htmlBridge.style.top = "-9999px"; - this.htmlBridge.removeAttribute("title"); - this.htmlBridge.removeAttribute("data-clipboard-text"); - _removeClass(currentElement, this.options.activeClass); - currentElement = null; - }; - ZeroClipboard.prototype.ready = function() { - var ready = this.htmlBridge.getAttribute("data-clipboard-ready"); - return ready === "true" || ready === true; - }; - ZeroClipboard.prototype.reposition = function() { - if (!currentElement) return false; - var pos = _getDOMObjectPosition(currentElement); - this.htmlBridge.style.top = pos.top + "px"; - this.htmlBridge.style.left = pos.left + "px"; - this.htmlBridge.style.width = pos.width + "px"; - this.htmlBridge.style.height = pos.height + "px"; - this.htmlBridge.style.zIndex = pos.zIndex + 1; - this.setSize(pos.width, pos.height); - }; - ZeroClipboard.dispatch = function(eventName, args) { - ZeroClipboard.prototype._singleton.receiveEvent(eventName, args); - }; - ZeroClipboard.prototype.on = function(eventName, func) { - var events = eventName.toString().split(/\s/g); - for (var i = 0; i < events.length; i++) { - eventName = events[i].toLowerCase().replace(/^on/, ""); - if (!this.handlers[eventName]) this.handlers[eventName] = func; - } - if (this.handlers.noflash && !ZeroClipboard.detectFlashSupport()) { - this.receiveEvent("onNoFlash", null); - } - }; - ZeroClipboard.prototype.addEventListener = ZeroClipboard.prototype.on; - ZeroClipboard.prototype.receiveEvent = function(eventName, args) { - eventName = eventName.toString().toLowerCase().replace(/^on/, ""); - var element = currentElement; - switch (eventName) { - case "load": - if (args && parseFloat(args.flashVersion.replace(",", ".").replace(/[^0-9\.]/gi, "")) < 10) { - this.receiveEvent("onWrongFlash", { - flashVersion: args.flashVersion - }); - return; - } - this.htmlBridge.setAttribute("data-clipboard-ready", true); - break; - case "mouseover": - _addClass(element, this.options.hoverClass); - break; - case "mouseout": - _removeClass(element, this.options.hoverClass); - this.resetBridge(); - break; - case "mousedown": - _addClass(element, this.options.activeClass); - break; - case "mouseup": - _removeClass(element, this.options.activeClass); - break; - case "complete": - this.options.text = null; - break; - } - if (this.handlers[eventName]) { - var func = this.handlers[eventName]; - if (typeof func == "function") { - func.call(element, this, args); - } else if (typeof func == "string") { - window[func].call(element, this, args); - } - } - }; - ZeroClipboard.prototype.glue = function(elements) { - elements = _prepGlue(elements); - for (var i = 0; i < elements.length; i++) { - if (_inArray(elements[i], gluedElements) == -1) { - gluedElements.push(elements[i]); - _addEventHandler(elements[i], "mouseover", _elementMouseOver); - } - } - }; - ZeroClipboard.prototype.unglue = function(elements) { - elements = _prepGlue(elements); - for (var i = 0; i < elements.length; i++) { - _removeEventHandler(elements[i], "mouseover", _elementMouseOver); - var arrayIndex = _inArray(elements[i], gluedElements); - if (arrayIndex != -1) gluedElements.splice(arrayIndex, 1); - } - }; - if (typeof module !== "undefined") { - module.exports = ZeroClipboard; - } else { - window.ZeroClipboard = ZeroClipboard; - } -})(); \ No newline at end of file +!function(){"use strict";var _getStyle=function(el,prop){var y=el.style[prop];if(el.currentStyle)y=el.currentStyle[prop];else if(window.getComputedStyle)y=document.defaultView.getComputedStyle(el,null).getPropertyValue(prop);if(y=="auto"&&prop=="cursor"){var possiblePointers=["a"];for(var i=0;i=0?"&":"?")+"nocache="+(new Date).getTime()};var _vars=function(options){var str=[];if(options.trustedDomains){if(options.trustedDomains.length){str.push("trustedDomain="+options.trustedDomains.join(","))}else{str.push("trustedDomain="+options.trustedDomains)}}return str.join("&")};var _inArray=function(elem,array){if(array.indexOf){return array.indexOf(elem)}for(var i=0,length=array.length;i ';client.htmlBridge=document.createElement("div");client.htmlBridge.id="global-zeroclipboard-html-bridge";client.htmlBridge.setAttribute("class","global-zeroclipboard-container");client.htmlBridge.setAttribute("data-clipboard-ready",false);client.htmlBridge.style.position="absolute";client.htmlBridge.style.left="-9999px";client.htmlBridge.style.top="-9999px";client.htmlBridge.style.width="15px";client.htmlBridge.style.height="15px";client.htmlBridge.style.zIndex="9999";client.htmlBridge.innerHTML=html;document.body.appendChild(client.htmlBridge);client.flashBridge=document["global-zeroclipboard-flash-bridge"]};ZeroClipboard.prototype.resetBridge=function(){this.htmlBridge.style.left="-9999px";this.htmlBridge.style.top="-9999px";this.htmlBridge.removeAttribute("title");this.htmlBridge.removeAttribute("data-clipboard-text");_removeClass(currentElement,this.options.activeClass);currentElement=null};ZeroClipboard.prototype.ready=function(){var ready=this.htmlBridge.getAttribute("data-clipboard-ready");return ready==="true"||ready===true};ZeroClipboard.prototype.reposition=function(){if(!currentElement)return false;var pos=_getDOMObjectPosition(currentElement);this.htmlBridge.style.top=pos.top+"px";this.htmlBridge.style.left=pos.left+"px";this.htmlBridge.style.width=pos.width+"px";this.htmlBridge.style.height=pos.height+"px";this.htmlBridge.style.zIndex=pos.zIndex+1;this.setSize(pos.width,pos.height)};ZeroClipboard.dispatch=function(eventName,args){ZeroClipboard.prototype._singleton.receiveEvent(eventName,args)};ZeroClipboard.prototype.on=function(eventName,func){var events=eventName.toString().split(/\s/g);for(var i=0;i + @initTooltips() + @initClipboard() if ZeroClipboard? + + # Init tooltip action + initTooltips: -> + + # Dynamically add annotations as title attribute to rule list items + for category, rules of annotations + for label, text of rules + $(".license-rules ul.license-#{category} li.#{label}").attr "title", text + + # Init tooltips on all rule list items + for category, label of @categories + $(".license-#{category} li").qtip + content: + text: false + title: + text: label + position: @qtip_position + style: + classes: "qtip-shadow qtip-#{category}" + + false + + # if Zero Clipboard is present, bind to button and init + initClipboard: -> + + # Backup the clipboard button's original text. + $(".js-clipboard-button").data "clipboard-prompt", $(".js-clipboard-button").text() + + # Hook up copy to clipboard buttons + clip = new ZeroClipboard $(".js-clipboard-button"), + moviePath: "/javascripts/ZeroClipboard.swf" + clip.on "mouseout", @clipboardMouseout + clip.on "complete", @clipboardComplete + clip + + # Callback to restore the clipboard button's original text + clipboardMouseout: (client, args) -> + @innerText = $(this).data("clipboard-prompt") + + # Post-copy user feedback callback + clipboardComplete: (client, args) -> + @innerText = "Copied!" + +$ -> + new Choosealicense() \ No newline at end of file diff --git a/javascripts/app.js b/javascripts/app.js index 35f8c36..0e440f1 100644 --- a/javascripts/app.js +++ b/javascripts/app.js @@ -1,52 +1,81 @@ -var qtip_position = { - my: 'top center', - at: 'bottom center' -}; +// Generated by CoffeeScript 1.6.2 +(function() { + var Choosealicense; -$(document).ready(function() { - for (var category in annotations) { - var categoryAnnotations = annotations[category]; - for (var annotation in categoryAnnotations) { - $('.license-rules ul.license-' + category + ' li.' + annotation).attr('title', categoryAnnotations[annotation]); - } - } + Choosealicense = (function() { + Choosealicense.prototype.qtip_position = { + my: "top center", + at: "bottom center" + }; - $('.license-required li').qtip({ - content: { - text: false, - title: { - text: 'Required' + Choosealicense.prototype.categories = { + required: "Required", + permitted: "Permitted", + forbidden: "Forbidden" + }; + + function Choosealicense() { + this.initTooltips(); + if (typeof ZeroClipboard !== "undefined" && ZeroClipboard !== null) { + this.initClipboard(); } - }, - position: qtip_position, - style: { - classes: 'qtip-shadow qtip-required' } + + Choosealicense.prototype.initTooltips = function() { + var category, label, rules, text, _ref; + + for (category in annotations) { + rules = annotations[category]; + for (label in rules) { + text = rules[label]; + $(".license-rules ul.license-" + category + " li." + label).attr("title", text); + } + } + _ref = this.categories; + for (category in _ref) { + label = _ref[category]; + $(".license-" + category + " li").qtip({ + content: { + text: false, + title: { + text: label + } + }, + position: this.qtip_position, + style: { + classes: "qtip-shadow qtip-" + category + } + }); + } + return false; + }; + + Choosealicense.prototype.initClipboard = function() { + var clip; + + $(".js-clipboard-button").data("clipboard-prompt", $(".js-clipboard-button").text()); + clip = new ZeroClipboard($(".js-clipboard-button"), { + moviePath: "/javascripts/ZeroClipboard.swf" + }); + clip.on("mouseout", this.clipboardMouseout); + clip.on("complete", this.clipboardComplete); + return clip; + }; + + Choosealicense.prototype.clipboardMouseout = function(client, args) { + return this.innerText = $(this).data("clipboard-prompt"); + }; + + Choosealicense.prototype.clipboardComplete = function(client, args) { + return this.innerText = "Copied!"; + }; + + return Choosealicense; + + })(); + + $(function() { + return new Choosealicense(); }); - $('.license-permitted li').qtip({ - content: { - text: false, - title: { - text: 'Permitted' - } - }, - position: qtip_position, - style: { - classes: 'qtip-shadow qtip-permitted' - } - }); - - $('.license-forbidden li').qtip({ - content: { - text: false, - title: { - text: 'Forbidden' - } - }, - position: qtip_position, - style: { - classes: 'qtip-shadow qtip-forbidden' - } - }); -}); \ No newline at end of file +}).call(this); diff --git a/javascripts/clipboard.js b/javascripts/clipboard.js deleted file mode 100644 index dba4865..0000000 --- a/javascripts/clipboard.js +++ /dev/null @@ -1,20 +0,0 @@ -$(document).ready(function() { - - // Backup the clipboard button's original text. - $(".js-clipboard-button").data('clipboard-prompt', $('.js-clipboard-button').text()); - - // Hook up copy to clipboard buttons - var clip = new ZeroClipboard($(".js-clipboard-button"), { - moviePath: "../../javascripts/ZeroClipboard.swf" - }); - - clip.on('mouseover', function(client, args) { - // Restore the clipboard button's original text. - this.innerText = $(this).data('clipboard-prompt'); - }); - - clip.on('complete', function(client, args) { - this.innerText = 'Copied!'; - }); - -}); \ No newline at end of file From 090d1467d4568ff6e0b645b66e247a145508943d Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Sat, 13 Jul 2013 15:25:55 -0400 Subject: [PATCH 2/2] add coffeescrpt to scripts --- .gitignore | 3 ++- script/bootstrap | 3 +++ script/server | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b5474b4..2487073 100644 --- a/.gitignore +++ b/.gitignore @@ -166,4 +166,5 @@ pip-log.txt .config #jekyll -_site \ No newline at end of file +_site +node_modules \ No newline at end of file diff --git a/script/bootstrap b/script/bootstrap index d825802..a74f422 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -5,5 +5,8 @@ set -e echo "bundling installin'" bundle install +echo "npm installin'" +npm install coffee-script + echo echo "You're all set. Just run script/server and you can play license roulette!" \ No newline at end of file diff --git a/script/server b/script/server index f7acb22..777c8b3 100755 --- a/script/server +++ b/script/server @@ -2,6 +2,9 @@ set -e +echo "compiling javascript..." +coffee -c javascripts/app.coffee + echo "spinning up the server..." bundle exec jekyll serve -w