Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
"version": "0.0.0",
"dependencies": {
"angular": "~1.3.0"
},
"resolutions": {
"angular": "~1.3.0"
}
}
55 changes: 34 additions & 21 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body ng-app="mainApp">
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body ng-app="mainApp">

<div ng-controller="HomeCtrl">
<style>
.red {
color: red;
}
.blue {
color: blue;
}
.green {
color: green;
}
.orange {
color: orange;
}

<my-title id="english" default="???" color="red"></my-title>
<my-title id="french" default="???" color="green"></my-title>
<my-title id="german" default="???" color="blue"></my-title>
<my-title id="klingon" default="nuqneH"></my-title>
</style>

<div ng-controller="HomeCtrl">

<my-little-title id="001" default="???" color="orange"></my-little-title>
<my-title id="english" title="englishModel.title" color="englishModel.color"></my-title>
<my-title id="german" title="germanModel.title" color="germanModel.color"></my-title>

<input ng-model="englishModel.color" placeholder="Type: red, green, blue or orange"><br>
<input ng-model="englishModel.title" placeholder="english title"><br>

</div>
<!--<my-little-title id="001" default="???" color="orange"></my-little-title>-->
</div>

<script src="bower_components/angular/angular.js"></script>

<script src="bower_components/angular/angular.js"></script>
<script src="js/k33g.components/components.k33g.js"></script>
<script src="js/k33g.components/my-title/my-title.js"></script>

<script src="js/k33g.components/components.k33g.js"></script>
<script src="js/k33g.components/my-title/my-title.js"></script>
<script src="js/my.components/components.my.js"></script>
<script src="js/my.components/my-little-title/my-little-title.js"></script>

<script src="js/my.components/components.my.js"></script>
<script src="js/my.components/my-little-title/my-little-title.js"></script>
<script src="js/mainApp.js"></script>
<script src="js/controllers/HomeCtrl.js"></script>

<script src="js/mainApp.js"></script>
<script src="js/controllers/HomeCtrl.js"></script>

</body>
</body>
</html>
70 changes: 28 additions & 42 deletions public/js/controllers/HomeCtrl.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,32 @@
(function () {

var HomeCtrl = function ($rootScope, myLittleSharedServices) {

//myLittleSharedServices.setColor("green");

$rootScope.$on('my-title-ready', function(event, data) {

console.log('my-title-ready', data)

if (data.id=="english") {
$rootScope.$broadcast('set-text', {
id:"english", message:"Hello world!"
});
}

if (data.id=="french") {
$rootScope.$broadcast('set-text', {
id:"french", message:"Salut tout le monde!"
});
}

if (data.id=="german") {
$rootScope.$broadcast('set-text', {
id:"german", message:"Morgen!"
});
}

if (data.id=="klingon") {
$rootScope.$broadcast('set-color', {
id:"klingon", color:"orange"
});
}

});

};

HomeCtrl.$inject = ["$rootScope"];

angular.module("mainApp").controller("HomeCtrl", HomeCtrl);

//console.log("angular.module('mainApp')", angular.module("mainApp"))
//console.log("angular.module('my.components')", angular.module("my.components"))
/**
* Home controller
* @constructor
*/
var HomeCtrl = function ($scope) {

/**
* Model object for english title
* @type {{title: string, color: string}}
*/
$scope.englishModel = {
title : 'My english title',
color : 'red'
};

/**
* Model object for german title
* @type {{title: string, color: string}}
*/
$scope.germanModel = {
title : 'My german title',
color : 'green'
}
};

HomeCtrl.$inject = ["$scope"];

angular.module("mainApp").controller("HomeCtrl", HomeCtrl);

}());
5 changes: 4 additions & 1 deletion public/js/k33g.components/my-title/my-title.html
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
<h1 style="font-size: 60px">{{title}}</h1>
<h1 style="font-size: 60px"
ng-class="[color]">
{{title}}
</h1>
73 changes: 19 additions & 54 deletions public/js/k33g.components/my-title/my-title.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,23 @@
(function (ng) {

var scripts = document.getElementsByTagName("script");
var templateUrl = scripts[scripts.length-1].src.replace(".js", ".html");

var myTitle = function($rootScope) {
return {
restrict: 'E',
templateUrl: templateUrl,
link: function(scope, element){

//scope.self = element[0];

scope.setText = function(message) {
scope.title = message;
};

scope.setColor = function(color) {
angular.element(element[0].querySelector("h1")).css("color", color);
};

scope.setText(scope.default);
scope.setColor(scope.color);

$rootScope.$broadcast('my-title-ready', {id: scope.id});
},
controller: "myTitleCtrl",
scope:{
id: "@id", default : "@default", color : "@color"
}
}

};

var myTitleCtrl = function($scope, $rootScope) {

$rootScope.$on('set-text', function(event, data) {
if(data.id == $scope.id) {
$scope.setText(data.message);
}
});

$rootScope.$on('set-color', function(event, data) {
if(data.id == $scope.id) {
$scope.setColor(data.color);
}
});

};

myTitle.$inject = ["$rootScope"];
myTitleCtrl.$inject = ["$scope", "$rootScope"];

ng.module("k33g.components")
.directive("myTitle", myTitle)
.controller("myTitleCtrl", myTitleCtrl);
// TODO : get your the template with $templateCache
// or if yu want to write an HTML file use for exemple grunt with grunt plugin html2js
var scripts = document.getElementsByTagName("script");
var templateUrl = scripts[scripts.length - 1].src.replace(".js", ".html");

var myTitle = function () {
return {
restrict: 'EA',
templateUrl: templateUrl,
replace : true,
scope: {
title: "=",
color: "="
}
}
};
myTitle.$inject = [];

ng.module("k33g.components").directive("myTitle", myTitle);

})(angular);