Created
May 26, 2021 10:24
-
-
Save laminbarrow/cb25572e716f2d5bbffb457fddfd523b to your computer and use it in GitHub Desktop.
My shaping up with anjular 1 code sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var app = angular.module('gemStore', ['store-directives']); | |
app.controller('GalleryController', function() { | |
this.imageIndex = 0; | |
this.currentImageChange = function(imageNumber) { | |
console.log(imageNumber); | |
this.imageIndex = imageNumber || 0; | |
}; | |
}); | |
app.controller('StoreController', function() { | |
this.products = gems; | |
}); | |
app.controller("ReviewController", function(){ | |
this.review = {}; | |
this.addReview = function(product){ | |
this.review.createdOn = Date.now(); | |
product.reviews.push(this.review); | |
this.review = {}; | |
}; | |
}); | |
var gems = [{ | |
name: 'Azurite', | |
description: "Some gems have hidden qualities beyond their luster, beyond their shine... Azurite is one of those gems.", | |
shine: 8, | |
price: 110.50, | |
rarity: 7, | |
color: '#CCC', | |
faces: 14, | |
images: [ | |
"img/gem-02.gif", | |
"img/gem-05.gif", | |
"img/gem-09.gif" | |
], | |
reviews: [{ | |
stars: 5, | |
body: "I love this gem!", | |
author: "joe@thomas.com", | |
createdOn: 1397490980837 | |
}, { | |
stars: 1, | |
body: "This gem sucks.", | |
author: "tim@hater.com", | |
createdOn: 1397490980837 | |
}] | |
}, { | |
name: 'Bloodstone', | |
description: "Origin of the Bloodstone is unknown, hence its low value. It has a very high shine and 12 sides, however.", | |
shine: 9, | |
price: 22.90, | |
rarity: 6, | |
color: '#EEE', | |
faces: 12, | |
images: [ | |
"img/gem-01.gif", | |
"img/gem-03.gif", | |
"img/gem-04.gif", | |
], | |
reviews: [{ | |
stars: 3, | |
body: "I think this gem was just OK, could honestly use more shine, IMO.", | |
author: "JimmyDean@sausage.com", | |
createdOn: 1397490980837 | |
}, { | |
stars: 4, | |
body: "Any gem with 12 faces is for me!", | |
author: "gemsRock@alyssaNicoll.com", | |
createdOn: 1397490980837 | |
}] | |
}, { | |
name: 'Zircon', | |
description: "Zircon is our most coveted and sought after gem. You will pay much to be the proud owner of this gorgeous and high shine gem.", | |
shine: 70, | |
price: 1100, | |
rarity: 2, | |
color: '#000', | |
faces: 6, | |
images: [ | |
"img/gem-06.gif", | |
"img/gem-07.gif", | |
"img/gem-10.gif" | |
], | |
reviews: [{ | |
stars: 1, | |
body: "This gem is WAY too expensive for its rarity value.", | |
author: "turtleguyy@zdn.me", | |
createdOn: 1397490980837 | |
}, { | |
stars: 1, | |
body: "BBW: High Shine != High Quality.", | |
author: "LouisW407@gmail.com", | |
createdOn: 1397490980837 | |
}, { | |
stars: 1, | |
body: "Don't waste your rubles!", | |
author: "nat@flatland.com", | |
createdOn: 1397490980837 | |
}] | |
}]; | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app="gemStore"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>AngularJS</title> | |
<link data-require="bootstrap-css" data-semver="3.1.1" rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" /> | |
<link data-require="semantic-ui@*" data-semver="0.9.6" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.9.6/css/semantic.min.css" /> | |
<script data-require="jquery@*" data-semver="2.0.3" src="http://code.jquery.com/jquery-2.0.3.min.js"></script> | |
<script data-require="semantic-ui@*" data-semver="0.9.6" src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.9.6/javascript/semantic.min.js"></script> | |
<link rel="stylesheet" href="style.css" /> | |
<script data-require="angular.js@1.2.x" src="http://code.angularjs.org/1.2.15/angular.js" data-semver="1.2.15"></script> | |
<script src="app.js"></script> | |
<script src="products.js"></script> | |
</head> | |
<body ng-controller="StoreController as store"> | |
<!-- Store Header --> | |
<header> | |
<h1 class="text-center">Flatlander Crafted Gems</h1> | |
<h2 class="text-center">– an Angular store –</h2> | |
</header> | |
<!-- Products Container --> | |
<div class="list-group"> | |
<!-- Product Container --> | |
<div class="list-group-item" ng-repeat="product in store.products | orderBy:'-price'"> | |
<!-- $index Practice: --> | |
<h3>Gem #{{$index + 1}}: {{product.name | uppercase}}<em class="pull-right">{{product.price | currency}}</em> | |
</h3> | |
<!-- Image Gallery --> | |
<div ng-show="product.images.length" ng-controller="GalleryController as gallery"> | |
<div class="img-wrap"> | |
<img ng-src="{{product.images[gallery.imageIndex]}}" class="img-thumbnail center-block" /> | |
</div> | |
<ul class="img-thumbnails clearfix"> | |
<li class="small-image pull-left thumbnail" ng-repeat="image in product.images" ng-click="gallery.currentImageChange($index)"> | |
<img ng-src="{{image}}" /> | |
</li> | |
</ul> | |
</div> | |
<!-- Product Tabs --> | |
<product-tabs></product-tabs> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = angular.module('store-directives', []); | |
app.directive("descriptions", function() { | |
return { | |
restrict: "E", | |
templateUrl: "descriptions.html" | |
}; | |
}); | |
app.directive("reviews", function() { | |
return { | |
restrict: "E", | |
templateUrl: "reviews.html" | |
}; | |
}); | |
app.directive("specs", function() { | |
return { | |
restrict: "E", | |
templateUrl: "specs.html" | |
}; | |
}); | |
app.directive("productTabs", function() { | |
return { | |
restrict: "E", | |
templateUrl: "product-tabs.html", | |
controller: function() { | |
this.tab = 1; | |
this.isSet = function(checkTab) { | |
return this.tab === checkTab; | |
}; | |
this.setTab = function(activeTab) { | |
this.tab = activeTab; | |
}; | |
}, | |
controllerAs: "tab" | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment