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 id="wrapper" ng-app="MyApp">
<div ng-controller="AppCtrl">
<!-- Just a jQuery Plugin -->
<h3>Check out this plain old jQuery UI slider:</h3>
<div id="slider"></div>
<p>The slider's value is: <span id="slider-value">0</span></p>
<!-- Trying to use a jQuery Plugin in an Angular Controller -->
<h3>Check out this broken Angular slider:</h3>
<div id="ng-slider"></div>
<p>The slider's value is: {{brokenSliderValue}}</p>
<!-- A functioning jQuery Plugin in an Angular Directive -->
<h3>Check out this one-way data bound Angular slider:</h3>
<div ng-slider-one model="mehSliderValue"></div>
<p>The slider's value is: <input ng-model="mehSliderValue"/> (changing me won't update the slider)</p>
<!-- A two-way data bound jQuery Plugin in an Angular Directive -->
<h3>Check out this two-way data bound Angular slider:</h3>
<div ng-slider-two model="betterSliderValue"></div>
<p>The slider's value is: <input ng-model="betterSliderValue"/> (changing me WILL update the slider)</p>
<!-- A jQuery Plugin in an Angular Directive in an ng-repeat -->
<h3>Check out this <code>ng-repeat</code>-able Angular slider:</h3>
<div ng-repeat="sliderValue in repeatSliderValues">
<div ng-slider-two model="sliderValue"></div>
<p>The slider's value is: <input ng-model="sliderValue"/></p>
</div>
</div>
</div>
#wrapper {
padding: 6px 12px;
}
// Plain-ol' jQuery Plugin
$(document).ready(function() {
$('#slider').slider({
slide: function(event, ui) {
$('#slider-value').text(ui.value);
}
});
});
var app = angular.module('MyApp', []);
app.controller('AppCtrl', ['$scope', function($scope) {
$scope.brokenSliderValue = 0;
$scope.mehSliderValue = 50;
$scope.betterSliderValue = 50;
$scope.repeatValueOne = 25;
$scope.repeatValueTwo = 50;
$scope.repeatValueThree = 75;
$scope.repeatSliderValues = [
$scope.repeatValueOne,
$scope.repeatValueTwo,
$scope.repeatValueThree
];
// Broken slider
$('#ng-slider').slider({
slide: function(event, ui) {
//$scope.$apply(function() {
$scope.brokenSliderValue = ui.value;
//});
}
});
}]);
// One-way bound slider
app.directive('ngSliderOne', [function() {
return {
restrict: 'A',
scope: {
'model': '='
},
link: function(scope, elem, attrs) {
var $slider = $(elem);
$slider.slider({
value: +scope.model,
slide: function(event, ui) {
scope.$apply(function() {
scope.model = ui.value;
});
}
});
}
};
}]);
// Two-way bound slider
app.directive('ngSliderTwo', [function() {
return {
restrict: 'A',
scope: {
'model': '='
},
link: function(scope, elem, attrs) {
var $slider = $(elem);
$slider.slider({
value: +scope.model,
slide: function (event, ui) {
scope.$apply(function() {
scope.model = ui.value;
});
}
});
scope.$watch('model', function(newVal) {
$slider.slider('value', newVal);
});
}
}
}]);
Also see: Tab Triggers