requirejs.html 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8"/>
  5. <title>Angular</title>
  6. <meta name="viewport" content="width=device-width"/>
  7. <link rel="stylesheet" href="style.css"/>
  8. </head>
  9. <body>
  10. <ul>
  11. <li><a href="index.html">Vanilla JS</a></li>
  12. <li><a href="jquery.html">jQuery plugin</a></li>
  13. <li><a href="angular.html">Angular module</a></li>
  14. <li><a href="requirejs.html" class="active">RequireJS module</a></li>
  15. </ul>
  16. <div class="span6">
  17. <h2>Angular module</h2>
  18. <div class="angular" ng-controller="chartCtrl">
  19. <span class="chart" easypiechart ng-init="options = { animate:false, barColor:'#E67E22', scaleColor:false, lineWidth:3, lineCap:'butt' }" percent="percent" options="options">
  20. <span class="percent" ng-bind="percent"></span>
  21. </span>
  22. <input type="range" min="-100" max="100" step="1" ng-model="percent" />
  23. </div>
  24. </div>
  25. <div class="span6">
  26. <h2>jQuery module</h2>
  27. <span id="chart" class="chart" data-percent="12">
  28. <span class="percent"></span>
  29. </span>
  30. <input type="range" min="-100" max="100" step="1" id="updater" />
  31. </div>
  32. <script src="../bower_components/requirejs/require.js"></script>
  33. <script>
  34. require.config({
  35. paths: {
  36. 'jquery': 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery',
  37. 'angular': 'https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular',
  38. 'angular-easypiechart': '../dist/angular.easypiechart',
  39. 'jquery-easypiechart': '../dist/jquery.easypiechart'
  40. },
  41. shim: {
  42. 'angular': { 'exports': 'angular' }
  43. }
  44. });
  45. require([
  46. 'angular-easypiechart'
  47. ], function () {
  48. angular.module('app', ['easypiechart'])
  49. .controller('chartCtrl', ['$scope', function ($scope) {
  50. $scope.percent = 65;
  51. }]);
  52. angular.bootstrap(document.getElementsByTagName('html')[0], ['app']);
  53. });
  54. require([
  55. 'jquery-easypiechart'
  56. ], function () {
  57. var chart = $('#chart').easyPieChart({
  58. onStep: function(from, to, percent) {
  59. $(this.el).find('.percent').text(Math.round(percent));
  60. }
  61. }).data('easyPieChart');
  62. $('#updater').on('change', function() {
  63. chart.update($(this).val());
  64. });
  65. });
  66. </script>
  67. </body>
  68. </html>