2014-07-31 18:36:56 +02:00
|
|
|
---
|
|
|
|
---
|
|
|
|
|
2013-07-13 21:18:57 +02:00
|
|
|
class Choosealicense
|
2013-07-15 22:19:31 +02:00
|
|
|
# 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"
|
|
|
|
|
2015-09-09 01:24:05 +02:00
|
|
|
# Annotation rule types as defined in `_config.yml`
|
|
|
|
ruletypes:
|
2013-07-13 21:18:57 +02:00
|
|
|
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
|
2015-09-09 01:24:05 +02:00
|
|
|
for ruletype, rules of window.annotations
|
2014-09-05 17:26:54 +02:00
|
|
|
for rule in rules
|
2015-09-09 01:24:05 +02:00
|
|
|
$(".license-rules ul.license-#{ruletype} li.#{rule["tag"]}").attr "title", rule["description"]
|
2013-07-13 21:18:57 +02:00
|
|
|
|
|
|
|
# Init tooltips on all rule list items
|
2015-09-09 01:24:05 +02:00
|
|
|
for ruletype, label of @ruletypes
|
|
|
|
$(".license-#{ruletype} li").qtip
|
2013-07-13 21:18:57 +02:00
|
|
|
content:
|
|
|
|
text: false
|
|
|
|
title:
|
|
|
|
text: label
|
|
|
|
position: @qtip_position
|
|
|
|
style:
|
2015-09-09 01:24:05 +02:00
|
|
|
classes: "qtip-shadow qtip-#{ruletype}"
|
2013-07-13 21:18:57 +02:00
|
|
|
|
|
|
|
false
|
|
|
|
|
2015-10-25 05:47:13 +01:00
|
|
|
# Initializes Clipboard.js
|
2015-09-20 04:46:18 +02:00
|
|
|
initClipboard: ->
|
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
|
2015-10-25 05:47:13 +01:00
|
|
|
clip = new Clipboard ".js-clipboard-button"
|
2013-11-30 00:08:27 +01:00
|
|
|
clip.on "mouseout", @clipboardMouseout
|
|
|
|
clip.on "complete", @clipboardComplete
|
2013-07-15 22:19:31 +02:00
|
|
|
|
2013-07-13 21:18:57 +02:00
|
|
|
# Callback to restore the clipboard button's original text
|
|
|
|
clipboardMouseout: (client, args) ->
|
2014-12-18 20:53:45 +01:00
|
|
|
@textContent = $(this).data("clipboard-prompt")
|
2013-07-13 21:18:57 +02:00
|
|
|
|
|
|
|
# Post-copy user feedback callback
|
|
|
|
clipboardComplete: (client, args) ->
|
2014-12-18 20:53:45 +01:00
|
|
|
@textContent = "Copied!"
|
2013-07-13 21:18:57 +02:00
|
|
|
|
2013-11-06 17:24:34 +01:00
|
|
|
# Initializes pill navigation for license variations
|
|
|
|
initLicenseVariationNav: ->
|
|
|
|
$(".js-nav-pills a").click (e) ->
|
2013-12-10 08:48:49 +01:00
|
|
|
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")
|
2013-11-06 17:24:34 +01:00
|
|
|
|
2013-12-10 08:48:49 +01:00
|
|
|
$(this).parent("li").addClass("active")
|
|
|
|
$("." + selectedTab).addClass("active")
|
2013-11-06 17:24:34 +01:00
|
|
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
2013-07-13 21:18:57 +02:00
|
|
|
$ ->
|
2013-07-15 22:19:31 +02:00
|
|
|
new Choosealicense()
|