UNPKG

ngprogress

Version:
441 lines (387 loc) 16.8 kB
<!doctype html> <html ng-app="progressApp"> <head> <meta name="HandheldFriendly" content="True"> <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1"> <title>ngProgress - A slim, site-wide progressbar for AngularJS</title> <style> body { margin: 0px; padding: 0px; font-family: sans-serif; font-weight: lighter; letter-spacing: 1px; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; } html { overflow-y: scroll; } #title { text-align: center; font-size: 1.5em; font-family: sans-serif; font-weight: lighter; letter-spacing: 1px; } @media screen and (min-width:800px){ #title { font-size:2em; } } p { margin: 1em 0 1em 1em; line-height: 1.5em; } pre { margin: 0 0 0 1em; } div { margin: 1em 0; } #header a, #demo a, #demo_contained a, pre { display: inline-block; padding: 6px 12px; margin-bottom: 0; font-size: 14px; font-weight: normal; line-height: 1.428571429; border: 1px solid #CCC; border-radius: 4px; color: #333333; background-color: #ffffff; white-space: pre-wrap; } #demo_contained { position: relative; background-color: rgba(0,0,0,0.1); padding: 5px; } #header a, #demo a, #demo_contained a { text-align: center; vertical-align: middle; cursor: pointer; text-decoration: none; } #header a, #demo a:hover, #demo_contained a:hover { background: #1abc9c; color: #fff; border: 1px solid #1abc9c; -webkit-transition: all 0.3s ease-in; -moz-transition: all 0.3s ease-in; -o-transition: all 0.3s ease-in; transition: all 0.3s ease-in; } a:hover { color: #333333; text-decoration: none; } .container { max-width: 600px; margin: 1em auto; padding: 0 0.5em; } .container hr { border: 1px solid #999; } .value { float: right; } #api p { border-bottom: 1px solid lightgrey; padding-bottom: 1em; } a:-webkit-any-link { color: #E2835D; text-decoration: none; } h1,h2,h3,h4,h5 { color: #545454; font-weight: lighter; letter-spacing: 2px; } #license p { font-size: .7em; } </style> <link rel="stylesheet" href="ngProgress.css"> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.js"></script> </head> <body ng-controller="MainCtrl"> <style>#forkongithub a{background:#000;color:#fff;text-decoration:none;font-family:arial, sans-serif;text-align:center;font-weight:bold;padding:5px 0;font-size:1rem;line-height:2rem;position:relative;transition:0.5s;display:block;width:100%;}#forkongithub a:hover{background:#060;color:#fff;}#forkongithub a::before,#forkongithub a::after{content:"";width:100%;display:block;position:absolute;top:1px;left:0;height:1px;background:#fff;}#forkongithub a::after{bottom:1px;top:auto;}@media screen and (min-width:800px){#forkongithub{position:absolute;display:block;top:0;right:0;width:200px;overflow:hidden;height:200px;}#forkongithub a{width:200px;padding:5px 40px;position:absolute;top:60px;right:-60px;transform:rotate(45deg);-webkit-transform:rotate(45deg);box-shadow:4px 4px 10px rgba(0,0,0,0.8);}}</style><span id="forkongithub"><a href="https://github.com/victorbjelkholm/ngprogress" target="_blank">Fork me on GitHub</a></span> <div id="title"> <strong>ngProgress</strong> <br> A slim, site-wide progressbar for AngularJS </div> <div class="container" ng-show="show"> <div id="header"> <center> <a href="#installation">Installation</a> <a href="#demo">Demo</a> <a href="#api">API</a> </center> </div> <p> I recently saw Youtube's and Medium's new loading bars (and Medium don't get it) and was interested in implementing it on my own. In comes <a href="https://github.com/rstacruz/nprogress" target="_blank">NProgress</a>, a jQuery dependent plugin that creates this effect. </p> <p> I didn't think the plugin needed a jQuery dependency, so I created my own AngularJS Provider that I can use for my heavy-applications. Try it out, fork it and submit a pull request if you want! </p> <p> Right now, the plugin weighs 8kb, contains 12 different methods and has a dependency on Angular (duh). </p> <p> Reach out to me on Twitter ( <a href="https://twitter.com/VictorBjelkholm" target="_blank">@VictorBjelkholm</a> ) if you have feedback, criticisms or just want someone to blame for your problems. Or, visit the <a href="https://github.com/VictorBjelkholm/ngProgress/" target="_blank">Github repository</a> </p> <div id="installation"> <h2> Installation </h2> <p> <strong>Manual:</strong> Download <a href="https://raw.github.com/VictorBjelkholm/ngProgress/master/build/ngProgress.js" target="_blank">ngProgress.js</a> or <a href="https://raw.github.com/VictorBjelkholm/ngProgress/master/build/ngProgress.min.js" target="_blank">ngProgress.min.js</a> </p> <p><strong>Automatic:</strong> Install using bower: <pre>bower install ngprogress</pre> </p> <h3>Usage</h3> <p> Include ngProgress.js ( or ngProgress.min.js) and ngProgress.css in your website. <pre> &lt;script src="app/components/ngProgress/ngProgress.js"&gt;&lt;/script&gt; &lt;link rel="stylesheet" href="ngProgress.css"&gt; </pre> </p> <p> Set ngProgress as a dependency in your module <pre> var app = angular.module('progressApp', ['ngProgress']); </pre> </p> <p> Inject ngProgressFactory in the controller where you plan to use it <pre> var MainCtrl = function($scope, ngProgressFactory) { } </pre> </p> <p> Create a new instance of ngProgress and start showing the progress of things! <pre> $scope.progressbar = ngProgressFactory.createInstance(); $scope.progressbar.start(); </pre> </p> <p> Use this command to start the progress bar. The <a href="#api">ngProgress API</a> will show you how to manipulate ngProgress. <pre> ngProgress.start(); </pre> </p> </div> <div id="demo"> <h2> Demo </h2> <div> <div class="value">Progress: <input type="number" ng-model="counter"></div> <a href="#demo" ng-click="setWidth(counter, $event)">Set progress</a> </div> <hr> <div> <a href="#demo" ng-click="startProgress($event)">Start progressbar</a> </div> <hr> <div> <a href="#demo" ng-click="completeProgress($event)">Complete progressbar</a> </div> <hr> <div> <a href="#demo" ng-click="stopProgress($event)">Stop progressbar</a> </div> <hr> <div> <a href="#demo" ng-click="resetProgress($event)">Reset progressbar</a> </div> <hr> <div> <a href="#demo" ng-click="increment($event)">Increment</a> </div> <hr> <div> <div class="value"> Height: <input type="text" ng-model="height"> </div> <a href="#demo" ng-click="new_height($event, height)">Change height</a> </div> <hr> <div> <div class="value"> Color: <input type="text" ng-model="color"> </div> <a href="#demo" ng-click="new_color($event, color)">Change color</a> </div> </div> <div id="demo_contained"> <h3>Contained</h3> <div> <a href="#demo_contained" ng-click="start_contained($event)">Start progressbar</a> <a href="#demo_contained" ng-click="complete_contained($event)">Complete progressbar</a> <a href="#demo_contained" ng-click="reset_contained($event)">Reset progressbar</a> </div> </div> <div id="share"> <h2>Share</h2> <p>Since the providers quality depends on peer-review, please review it yourself or share it to people that like to review stuff. I would be forever grateful and buy you a coffee if you are in Barcelona.</p> <div> <iframe src="http://ghbtns.com/github-btn.html?user=victorbjelkholm&amp;repo=ngprogress&amp;type=watch&amp;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="100" height="20"></iframe> <iframe src="http://ghbtns.com/github-btn.html?user=victorbjelkholm&amp;type=follow&amp;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="175" height="20"></iframe><br/> <a href="http://news.ycombinator.com/submit" class="hn-share-button">Vote on HN</a> <a href="https://twitter.com/share" class="twitter-share-button" data-via="VictorBjelkholm" data-hashtags="angularjs">Tweet</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script> <div style="margin:0;padding:0;display:inline;" class="g-plusone" data-action="share" data-annotation="inline" data-width="200"></div> </div> </div> <div id="api"> <h2> API </h2> <pre>ngProgressFactory.createInstance()</pre> <p>REQUIRED TO USE! Creates a new instance of ngProgress that you can use the methods below with.</p> <pre>ngProgress.start();</pre> <p>Starts the animation and adds between 0 - 5 percent to the loading percentage every 400 milliseconds. Should always be finished with progressbar.complete() to hide it.</p> <pre>ngProgress.height();</pre> <p>Sets the height of the progressbar. Use any valid CSS value Eg '10px', '1em' or '1%'.</p> <pre>ngProgress.color();</pre> <p>Sets the color of the progressbar and it's shadow. Use any valid HTML color</p> <pre>ngProgress.status();</pre> <p>Returns the current percent value the progressbar is at. Should'nt be needed.</p> <pre>ngProgress.stop();</pre> <p>Stops the progressbar at its current location.</p> <pre>ngProgress.set();</pre> <p>Sets the progressbar percentage value. Use a number between 0 - 100. If 100 is provided, complete will be called.</p> <pre>ngProgress.reset();</pre> <p>Resets the progressbar to percentage 0 and will be hiden after it's rolled back.</p> <pre>ngProgress.complete();</pre> <p>Jumps to 100% progress and fades away progressbar.</p> </div> <div id="license"> <h2>License</h2> <p>The MIT License (MIT)</p> <p>Copyright (c) 2013 Victor Bjelkholm</p> <p> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: </p> <p> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. </p> <p> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. </p> </div> </div> <!-- <script src="src/module.js"></script> <script src="src/directive.js"></script> <script src="src/provider.js"></script> --> <script src="build/ngprogress.js"></script> <script> var app = angular.module('progressApp', ['ngProgress']); var MainCtrl = function($scope, $timeout, ngProgressFactory) { $scope.name = 'Lars'; $scope.show = false; $scope.progressbar = ngProgressFactory.createInstance(); $scope.color = 'firebrick'; $scope.height = '3px'; $scope.contained_progressbar = ngProgressFactory.createInstance(); $scope.contained_progressbar.setParent(document.getElementById('demo_contained')); $scope.contained_progressbar.setAbsolute(); $scope.progressbar.start(); $timeout(function(){ $scope.progressbar.complete(); $scope.show = true; }, 2000); $scope.setWidth = function(new_width, $event) { $scope.progressbar.set(new_width); $event.preventDefault(); } $scope.startProgress = function($event) { $event.preventDefault(); $scope.progressbar.start(); } $scope.increment = function($event) { $event.preventDefault(); $scope.progressbar.set($scope.progressbar.status() + 9); } $scope.new_color = function($event, color) { $event.preventDefault(); $scope.progressbar.setColor(color); } $scope.new_height = function($event, new_height) { $event.preventDefault(); $scope.progressbar.setHeight(new_height); } $scope.completeProgress = function($event) { $event.preventDefault(); $scope.progressbar.complete(); } $scope.stopProgress = function($event) { $event.preventDefault(); $scope.progressbar.stop(); } $scope.resetProgress = function($event) { $scope.progressbar.reset(); $event.preventDefault(); } $scope.start_contained = function($event) { $scope.contained_progressbar.start(); $event.preventDefault(); } $scope.complete_contained = function($event) { $scope.contained_progressbar.complete(); $event.preventDefault(); } $scope.reset_contained = function($event) { $scope.contained_progressbar.reset(); $event.preventDefault(); } } </script> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-20806824-13', 'victorbjelkholm.github.io'); ga('send', 'pageview'); </script> <script> (function(d, t) { var g = d.createElement(t), s = d.getElementsByTagName(t)[0]; g.src = '//hnbutton.appspot.com/static/hn.min.js'; s.parentNode.insertBefore(g, s); }(document, 'script')); </script> <script type="text/javascript"> (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); </script> </body> </html>