HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URL's added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div class="container" ng-app="ModalDialogSample">
<div class="centered">
<h1>simple modal dialogs</h1>
<modal-dialog-trigger trigger-on="testone" class="btn btn-danger">modal-dialog-trigger</modal-dialog-trigger>
<span ng-controller="ModalDialogSampleController as mdsc">
<a class="btn btn-info" ng-click="mdsc.open('testwo')">ng-click="expression"</a>
</span>
<modal-dialog-trigger trigger-on="login-form" class="btn btn-success">login form</modal-dialog-trigger>
</div>
<modal-dialog id="testone">
<h1>testone</h1>
<code>
<modal-dialog-trigger trigger-on="testone" class="btn btn-danger">modal-dialog-trigger</modal-dialog-trigger>
</code>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias, quas minima nam. Architecto nobis at deleniti unde ea totam, provident magni enim velit. Quo accusantium laborum magnam, veniam veritatis sit.</p>
</modal-dialog>
<modal-dialog id="testwo">
<h1>testtwo</h1>
<code>
<span ng-controller="ModalDialogSampleController as mdsc">
<a class="btn btn-info" ng-click="mdsc.open('testwo')">ng-click="expression"</a>
</span>
</code>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Recusandae voluptas eos a. Repellendus sunt, velit vitae quibusdam possimus dignissimos. Harum possimus dolores nobis quisquam accusantium ducimus, odio asperiores nemo expedita!</p>
<p>Blanditiis quaerat unde, minus tempore doloribus aut excepturi tempora labore dicta alias iusto error. Nesciunt et, error, blanditiis, inventore tenetur dolore mollitia sit vero ab laudantium, veritatis odio fugiat repellat!</p>
</modal-dialog>
<modal-dialog id="login-form">
<!-- from bootstrap doc -->
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Sign in</button>
</div>
</div>
</form>
</modal-dialog>
</div>
<!-- template --
<div class="dr-modal">
<div class="modal-overlay"></div>
<div class="modal-dialog">
<div class="modal-dialog-close"><i class="fa fa-times"></i></div>
<div class="modal-dialog-content" ng-transclude></div>
</div>
</div>
<!-- -->
/***************
* modal bones
**************/
.dr-modal {
.modal-overlay {
position: absolute;
z-index: 9999;
top: 0; left: 0;
width: 100%;
height: 100%;
}
.modal-dialog {
box-sizing: border-box;
z-index: 10000;
.modal-dialog-close {
display: inline-block;
position: absolute;
top: 0; right: 0;
cursor: pointer;
}
}
}
modal-dialog {
display: none;
}
/***************
* modal themes
* <modal-dialog theme='theme-class'></modal-dialog>
**************/
.dr-modal-default-theme {
.modal-overlay {
background: #000;
opacity: 0.7;
}
.modal-dialog {
margin: 25px auto;
background: white;
padding: 25px;
.modal-dialog-close {
padding: 10px 15px;
&:hover {
color: #E9573F;
}
}
}
}
/**
* from http://www.smashingmagazine.com/2013/08/09/absolute-horizontal-vertical-centering-css/
*/
%abs-centered {
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
margin: auto;
}
/**
* sample styles
*/
html, body {
width: 100%;
height: 100%;
}
.container {
position: relative;
width: 100%;
height: 100%;
}
.centered {
@extend %abs-centered;
display: block;
width: 800px;
height: 155px;
text-align: center;
}
// animations will be added soon
var modal = angular.module('dx.ModalDialog', []);
// I think that each dialog should have its own controller
function ModalDialogController($scope, ModalDialog) {
this.id = $scope.id;
this.close = function() {
$scope.shown = false;
$scope.$apply();
}
this.open = function() {
$scope.shown = true;
$scope.$apply();
}
this.toggle = function() {
$scope.shown = !$scope.shown;
$scope.$apply();
}
this.init = function(controller) {
ModalDialog.add(controller);
}
}
modal.controller('ModalDialogController', ModalDialogController);
// so here's a singleton service to store those dialog controllers
// and it exposes APIs to the application to control the modal dialogs
function ModalDialogService() {
var dialogControllers = [],
service = {};
service.add = function(dialogController) {
// TODO duplicated ids
dialogControllers.push({
id: dialogController.id,
controller: dialogController
});
}
service.open = function(dialogId) {
handleTargetDialog(dialogId, 'open');
}
service.close = function(dialogId) {
handleTargetDialog(dialogId, 'close');
}
service.toggle = function(dialogId) {
handleTargetDialog(dialogId, 'toggle');
}
function handleTargetDialog(targetId, action) {
/* var found = false;
// TODO any good solutions for this iteration ?
for (var i = 0; i < dialogControllers.length; i++) {
if (dialogControllers[i].id !== targetId) continue;
found = true;
dialogControllers[i].controller[action]();
break;
}*/
var targetDialogController = dialogControllers.filter(function(dialogCtrl) {
return dialogCtrl.id === targetId;
}).pop();
if (!targetDialogController) console.error('dialog error : ' + dialogId + ' not found !');
targetDialogController.controller[action]();
}
return service;
}
modal.service('ModalDialog', ModalDialogService);
// here is the directive
// create a controller and inject ModalDialog into it
// then use the ModalDialog APIs to control the modal dialogs.
function modalDialog() {
return {
restrict: 'E',
replace: true,
transclude: true,
scope: {
id: '@'
},
link: function(scope, elem, attrs, ctrl) {
elem.addClass(attrs.theme || 'dr-modal-default-theme');
ctrl.init(ctrl);
},
controller: 'ModalDialogController',
controllerAs: 'mdctrl',
template: '<div class="dr-modal" ng-show="shown"> \
<div class="modal-overlay" ng-click="mdctrl.close()"></div> \
<div class="modal-dialog">\
<div class="modal-dialog-close" ng-click="mdctrl.close()"><i class="fa fa-times"></i></div>\
<div class="modal-dialog-content" ng-transclude></div>\
</div>\
</div>'
};
}
modal.directive('modalDialog', modalDialog);
// another way to use this directive
// simply write :
// <modal-dialog-trigger trigger-on='target-id'>...</modal-dialog-trigger>
// or
// <a modal-dialog-trigger trigger-on='target-id'>...</a>
function modalDialogTrigger(ModalDialog) {
return {
restrict: 'EA',
link: function(scope, elem, attrs) {
elem.bind('click', function() {
ModalDialog.toggle(attrs.triggerOn);
});
}
}
}
modal.directive('modalDialogTrigger', modalDialogTrigger);
/*****************************
* a sample controller
*****************************/
var sample = angular.module('ModalDialogSample', ['dx.ModalDialog']);
function ModalDialogSampleController($scope, ModalDialog) {
this.open = function(id) {
ModalDialog.open(id);
}
}
sample.controller('ModalDialogSampleController', ModalDialogSampleController);
Also see: Tab Triggers