JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<div class="with-ctxmenu">
Right click me !
</div>
<div class="hidden">
<div id="ctxmenu-tpl">
<ul class="ctxmenu-menu">
<li>
<a href="">Link with menu</a>
<ul class="ctxmenu-menu">
<li><a href="#">Link</a></li>
<li><a href="#">Link again</a></li>
<li><a href="#">And again</a></li>
<li><a href="#">The last one</a></li>
</ul>
</li>
<li>
<a href="#">Link with menu</a>
<ul class="ctxmenu-menu">
<li><a href="#">First link</a></li>
<li><a href="#">Second link</a></li>
</ul>
</li>
<li>
<a href="#">Link without menu</a>
</li>
<li>
<a href="">Link without menu</a>
</li>
</ul>
</div>
</div>
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Condensed);
body {
background: #456;
font-size: 0.9em;
font-family: 'Ubuntu Condensed', sans-serif;
color: #333;
}
.with-ctxmenu {
width: 200px;
margin: 80px auto;
padding: 10px;
text-align: center;
border: 2px solid #333;
border-radius: 10px;
background: #789;
font-size: 1.2em;
font-weight: bold;
}
.hidden {
display: none;
}
.ctxmenu {
position: absolute;
top: 0;
left: 0;
color: #333;
}
.ctxmenu-menu {
list-style: none;
padding: 1px;
margin: 0;
border: 1px solid #888;
background: #fefefe;
border-radius: 2px;
box-shadow: 2px 2px 3px #333;
}
.ctxmenu-menu li {
position: relative;
}
.ctxmenu-menu a,
.ctxmenu-menu a:visited {
display: block;
white-space: nowrap;
padding: 3px 20px 3px 5px;
border: 1px solid transparent;
background: transparent;
border-radius: 3px;
color: #333;
text-decoration: none;
}
.ctxmenu-menu a:hover {
border-color: #0065a5;
background: #7daac7;
}
.ctxmenu-menu .ctxmenu-menu {
position: absolute;
top: 0;
left: 100%;
display: none;
}
.ctxmenu-menu li:hover > .ctxmenu-menu {
display: block;
}
var ctxmenu = {
container: null
// Initialize and add the div#ctxmenu container in the body
,init: function() {
// hide the old ctxmenu
this.hide();
this.container = document.createElement('div');
this.container.setAttribute('id', 'ctxmenu');
// autohide
this.container.className = 'ctxmenu hidden';
document.body.appendChild(this.container);
}
// Setting the configuration of the ctxmenu
,set: function() {
this.init();
// override the default settings
var settings = _.extend({
content: null
,posX: 0
,posY: 0
}, arguments[0] || {});
// adding the content
this.container.innerHTML = settings.content;
// positionning
this.container.style.left = settings.posX + 'px';
this.container.style.top = settings.posY + 'px';
}
// Showing the ctxmenu
,show: function() {
if(undefined !== arguments[0]) {
this.set(arguments[0]);
}
this.container.className = 'ctxmenu';
}
// Hide the ctxmenu
,hide: function() {
if(this.container) {
this.container.remove();
this.container = null;
}
}
};
[].forEach.call(document.querySelectorAll('.with-ctxmenu'), function(el) {
el.addEventListener('contextmenu', function(e) {
// prevent the right click default action
e.preventDefault();
// prevent the auto kill
e.stopPropagation();
ctxmenu.show({
content: document.getElementById('ctxmenu-tpl').innerHTML
,posX: e.clientX
,posY: e.clientY
});
});
});
// hide the contextmenu on left/right click
document.addEventListener('click', function() { ctxmenu.hide(); }, false);
document.addEventListener('contextmenu', function() { ctxmenu.hide(); }, false);
Also see: Tab Triggers