Skip to content

Commit

Permalink
enhance usage way
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehrdad-Dadkhah committed Nov 21, 2015
1 parent b9b88aa commit 01e7a8a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,18 @@ Table of Content:

```html
<h2>input</h2>
<input name="test[1]" ng-model="test[1]" value=""/>
<input name="test" ng-model="test" value=""/>

<h2>emoji panel</h2>
<emoji input-model="1" input-name="test"></emoji>
<emoji input-name="test"></emoji>
```

and in js code:

```javascript
$scope.$on('emji:addSuccess', function(event, emoji, inputName) {

$scope[inputName] += ' ' + emoji;

});
```
9 changes: 8 additions & 1 deletion demo/demoApp.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
var demoApp = angular.module('demoApp',['ngEmoji']);

var documentRoot = 'http://test.local/src/';

var testController = demoApp.controller('testController',['$scope', function($scope){

var init = function(){
//DO sth
$scope.test = '';
}

$scope.$on('emji:addSuccess', function(event, emoji, inputName) {

$scope[inputName] += ' ' + emoji;

});

init();
}]);
9 changes: 6 additions & 3 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
<h1>DEMO of editablediv directive</h1>

<h2>input</h2>
<input name="test[1]" ng-model="test[1]" value=""/>

<input name="test" ng-model="test" value="" style="width: 500px;"/>
<p>
note that if want to see emoji icon instead of it's code you should use
<a href="https://github.com/Mehrdad-Dadkhah/ng-editable-div">editable div</a>
</p>
<h2>emoji panel</h2>
<emoji input-model="1" input-name="test"></emoji>
<emoji input-name="test"></emoji>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-emoji",
"version": "1.0.0",
"version": "1.0.1",
"description": "An Angular directive for emojify complete panel",
"repository": {
"type": "git",
Expand Down
10 changes: 2 additions & 8 deletions src/ngEmoji.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
var app = angular.module('ngEmoji' , []);

var documentRoot = 'http://test.local/src/';

app.directive('emoji', function() {
return {
templateUrl: documentRoot + 'emoji.html',
restrict: 'E',
scope:{
inputModel: '@',
inputName: '@'
},
compile: function($scope, element){
Expand All @@ -27,10 +24,8 @@ app.directive('emoji', function() {
emojify.run();
element.$$element[0].innerHTML = emojify.replace(element.$$element[0].innerHTML);
},
controller: function($scope, $element){
controller: function($scope, $rootScope, $element){
var init = function(){
$scope.$parent[$scope.inputName] = [];
$scope.$parent[$scope.inputName][$scope.inputModel] = '';
$scope.showEmojiPanel = false;
}

Expand All @@ -39,8 +34,7 @@ app.directive('emoji', function() {
}

$scope.addEmoji = function(emojiCode){
var text = $scope.$parent[$scope.inputName][$scope.inputModel];
$scope.$parent[$scope.inputName][$scope.inputModel] = text+emojify.replace(emojiCode);
$rootScope.$broadcast('emji:addSuccess', emojify.replace(emojiCode), $scope.inputName);
}

init();
Expand Down

0 comments on commit 01e7a8a

Please sign in to comment.