1
0
mirror of https://github.com/github/choosealicense.com synced 2024-12-22 21:00:10 +01:00

132 lines
3.9 KiB
JavaScript
Raw Normal View History

2013-09-14 00:39:58 -04:00
// Generated by CoffeeScript 1.6.3
2013-07-13 15:18:57 -04:00
(function() {
var Choosealicense;
2013-07-13 15:18:57 -04:00
Choosealicense = (function() {
Choosealicense.prototype.flashAvailable = function() {
if (typeof ActiveXObject !== "undefined" && ActiveXObject !== null) {
2013-10-30 20:23:28 +02:00
return !!(new ActiveXObject("ShockwaveFlash.ShockwaveFlash"));
} else {
return !!navigator.mimeTypes["application/x-shockwave-flash"];
}
};
Choosealicense.prototype.selectText = function(element) {
var range, selection;
if (document.body.createTextRange) {
range = document.body.createTextRange();
range.moveToElementText(element);
return range.select();
} else if (window.getSelection) {
selection = window.getSelection();
range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
return selection.addRange(range);
}
};
2013-07-13 15:18:57 -04:00
Choosealicense.prototype.qtip_position = {
my: "top center",
at: "bottom center"
};
Choosealicense.prototype.categories = {
required: "Required",
permitted: "Permitted",
forbidden: "Forbidden"
};
2012-12-04 17:12:12 -05:00
2013-07-13 15:18:57 -04:00
function Choosealicense() {
this.initTooltips();
this.initClipboard();
this.initLicenseVariationNav();
2012-12-04 17:12:12 -05:00
}
2013-07-13 15:18:57 -04:00
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);
}
2012-12-04 17:12:12 -05:00
}
2013-07-13 15:18:57 -04:00
_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.initZeroClipboard = function() {
2013-07-13 15:18:57 -04:00
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.initAlternativeClipboard = function() {
var _this = this;
return $(".js-clipboard-button").click(function(e) {
var target;
target = "#" + $(e.target).data("clipboard-target");
return _this.selectText($(target)[0]);
});
};
Choosealicense.prototype.initClipboard = function() {
if ((typeof ZeroClipboard !== "undefined" && ZeroClipboard !== null) && this.flashAvailable()) {
return this.initZeroClipboard();
} else {
return this.initAlternativeClipboard();
}
};
2013-07-13 15:18:57 -04:00
Choosealicense.prototype.clipboardMouseout = function(client, args) {
return this.innerText = $(this).data("clipboard-prompt");
};
Choosealicense.prototype.clipboardComplete = function(client, args) {
return this.innerText = "Copied!";
};
Choosealicense.prototype.initLicenseVariationNav = function() {
return $(".js-nav-pills a").click(function(e) {
var nav, selectedTab;
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');
return e.preventDefault();
});
};
2013-07-13 15:18:57 -04:00
return Choosealicense;
})();
$(function() {
return new Choosealicense();
2012-12-04 17:12:12 -05:00
});
2013-07-13 15:18:57 -04:00
}).call(this);