Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. <!doctype html>
  2. <html ng-app="Demo">
  3. <head>
  4. <meta charset="utf-8" />
  5.  
  6. <title>
  7. An Experiment In What React's JSX Might Feel Like In AngularJS
  8. </title>
  9.  
  10. <link rel="stylesheet" type="text/css" href="./demo.css"></link>
  11. </head>
  12. <body>
  13.  
  14. <h1>
  15. An Experiment In What React's JSX Might Feel Like In AngularJS
  16. </h1>
  17.  
  18. <div bn:hello-world>
  19. Woot!
  20. </div>
  21.  
  22.  
  23. <!--
  24. Load scripts.
  25. --
  26. NOTE: Our main script block isn't a JavaScript block - it's a "text/ngx" block.
  27. The ngx.js file will defer the bootstrapping of the AngularJS application until
  28. the ngx content has been parsed and re-injected into the Head as valid JavaScript.
  29. -->
  30. <script type="text/javascript" src="../../vendor/jquery/jquery-2.1.0.min.js"></script>
  31. <script type="text/javascript" src="../../vendor/angularjs/angular-1.3.16.min.js"></script>
  32. <script type="text/javascript" src="./ngx.js"></script>
  33. <script type="text/ngx">
  34.  
  35. // Create an application module for our demo.
  36. angular.module( "Demo", [] );
  37.  
  38.  
  39. // --------------------------------------------------------------------------- //
  40. // --------------------------------------------------------------------------- //
  41.  
  42.  
  43. angular.module( "Demo" ).directive(
  44. "bnHelloWorld",
  45. function( $log ) {
  46.  
  47. // Return the directive definition object.
  48. return({
  49. controller: Controller,
  50. controllerAs: "vm",
  51. link: link,
  52. restrict: "A",
  53. transclude: true,
  54. scope: true,
  55. template:
  56. ```
  57. <div class="container">
  58. <div class="header">
  59.  
  60. <h2>
  61. HTML <em>in</em> Your JavaScript?!
  62. </h2>
  63.  
  64. </div>
  65. <div class="content" ng-transclude>
  66.  
  67. <!-- Transcluded content will appear here. -->
  68.  
  69. </div>
  70. <div ng-click="vm.cycleQuote()" class="footer">
  71.  
  72. <strong>Inspiration</strong>: {{ vm.quote }}
  73.  
  74. </div>
  75. </div>
  76. ```
  77. });
  78.  
  79.  
  80. // I control the HelloWorld component.
  81. function Controller( $scope ) {
  82.  
  83. var vm = this;
  84.  
  85. var quoteIndex = 0;
  86. var quotes = [
  87. "Asphinctersayswhat?",
  88. "Ah, Nuprin. Little. Yellow. Different.",
  89. "As you can see, it sucks as it cuts.",
  90. "If you're gonna spew, spew into this.",
  91. "Party on Wayne. Party on Garth.",
  92. "Calgon - ancient Chinese secret.",
  93. "I don't even own A gun, let alone the many guns that would necessitate a rack.",
  94. "Game on!"
  95. ];
  96.  
  97. vm.quote = quotes[ quoteIndex ];
  98.  
  99. // Expose the public API.
  100. vm.cycleQuote = cycleQuote;
  101.  
  102.  
  103. // ---
  104. // PUBLIC METHODS.
  105. // ---
  106.  
  107.  
  108. // I move on to the next quote in the collection.
  109. function cycleQuote() {
  110.  
  111. if ( ++quoteIndex >= quotes.length ) {
  112.  
  113. quoteIndex = 0;
  114.  
  115. }
  116.  
  117. vm.quote = quotes[ quoteIndex ];
  118.  
  119. }
  120.  
  121. }
  122.  
  123.  
  124. // I bind the JavaScript events to the view-model of the component.
  125. function link( scope, element, attributes ) {
  126.  
  127. element.mouseenter(
  128. function handlerMouseenterEvent( event ) {
  129.  
  130. $log.info( "Moused into component." );
  131.  
  132. }
  133. );
  134.  
  135. var footer = element.find( "div.footer" )
  136. .hover(
  137. function hoverOver() {
  138.  
  139. footer.addClass( "active" );
  140.  
  141. },
  142. function hoverOut() {
  143.  
  144. footer.removeClass( "active" );
  145.  
  146. }
  147. )
  148. ;
  149.  
  150. }
  151.  
  152. }
  153. );
  154.  
  155. </script>
  156.  
  157. </body>
  158. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement