2013-07-13 21:18:57 +02:00
|
|
|
class Choosealicense
|
|
|
|
|
2013-07-15 22:19:31 +02:00
|
|
|
# Checks if Flash is available in the client.
|
|
|
|
flashAvailable: ->
|
|
|
|
if ActiveXObject?
|
2013-10-30 19:23:28 +01:00
|
|
|
!!(new ActiveXObject("ShockwaveFlash.ShockwaveFlash"))
|
2013-07-15 22:19:31 +02:00
|
|
|
else
|
|
|
|
!!navigator.mimeTypes["application/x-shockwave-flash"]
|
|
|
|
|
|
|
|
# Selects the content of a given element
|
|
|
|
selectText: (element) ->
|
|
|
|
if document.body.createTextRange
|
2013-11-30 00:08:27 +01:00
|
|
|
range = document.body.createTextRange()
|
|
|
|
range.moveToElementText(element)
|
|
|
|
range.select()
|
2013-07-15 22:19:31 +02:00
|
|
|
else if window.getSelection
|
|
|
|
selection = window.getSelection()
|
|
|
|
range = document.createRange()
|
|
|
|
|
|
|
|
range.selectNodeContents(element)
|
2013-11-30 00:08:27 +01:00
|
|
|
selection.removeAllRanges()
|
|
|
|
selection.addRange(range)
|
2013-07-15 22:19:31 +02:00
|
|
|
|
2013-07-13 21:18:57 +02:00
|
|
|
# Qtip position attributes for tooltips
|
|
|
|
qtip_position:
|
|
|
|
my: "top center"
|
|
|
|
at: "bottom center"
|
|
|
|
|
|
|
|
# Annotation categories as defined in `_config.yml`
|
|
|
|
categories:
|
|
|
|
required: "Required"
|
|
|
|
permitted: "Permitted"
|
|
|
|
forbidden: "Forbidden"
|
|
|
|
|
|
|
|
# fire on document.ready
|
|
|
|
constructor: ->
|
|
|
|
@initTooltips()
|
2013-07-15 22:19:31 +02:00
|
|
|
@initClipboard()
|
2013-11-06 17:24:34 +01:00
|
|
|
@initLicenseVariationNav()
|
2013-07-13 21:18:57 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2013-07-15 22:19:31 +02:00
|
|
|
# Initializes ZeroClipboard
|
|
|
|
initZeroClipboard: ->
|
2013-11-30 00:08:27 +01:00
|
|
|
# Backup the clipboard button's original text.
|
|
|
|
$(".js-clipboard-button").data "clipboard-prompt", $(".js-clipboard-button").text()
|
2013-07-15 22:19:31 +02:00
|
|
|
|
2013-11-30 00:08:27 +01:00
|
|
|
# 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
|
2013-07-15 22:19:31 +02:00
|
|
|
|
|
|
|
# Initializes an alternative way to copy the license for non-flash compatible
|
|
|
|
# browsers
|
|
|
|
initAlternativeClipboard: ->
|
|
|
|
$(".js-clipboard-button").click (e) =>
|
|
|
|
target = "#" + $(e.target).data("clipboard-target")
|
|
|
|
@selectText $(target)[0]
|
|
|
|
|
2013-07-13 21:18:57 +02:00
|
|
|
# if Zero Clipboard is present, bind to button and init
|
|
|
|
initClipboard: ->
|
2013-07-15 22:19:31 +02:00
|
|
|
if ZeroClipboard? && @flashAvailable()
|
|
|
|
@initZeroClipboard()
|
|
|
|
else
|
|
|
|
@initAlternativeClipboard()
|
2013-07-13 21:18:57 +02:00
|
|
|
|
|
|
|
# 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!"
|
|
|
|
|
2013-11-06 17:24:34 +01:00
|
|
|
# Initializes pill navigation for license variations
|
|
|
|
initLicenseVariationNav: ->
|
|
|
|
$(".js-nav-pills a").click (e) ->
|
|
|
|
selectedTab = $(this).data('selected-tab')
|
|
|
|
nav = $(this).closest('.js-nav-pills')
|
|
|
|
nav.find('li').removeClass('active')
|
|
|
|
nav.closest('.js-license-variations').siblings('.js-variation-tab').removeClass('active')
|
|
|
|
|
|
|
|
$(this).parent('li').addClass('active')
|
|
|
|
$('.' + selectedTab).addClass('active')
|
|
|
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
2013-07-13 21:18:57 +02:00
|
|
|
$ ->
|
2013-07-15 22:19:31 +02:00
|
|
|
new Choosealicense()
|