Skip to content

Commit 73f96d1

Browse files
author
Jordan Humphreys
committed
Initial commit.
0 parents  commit 73f96d1

18 files changed

+504
-0
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [ "es2015-rollup" ]
3+
}

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.eslintrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "standard",
3+
"rules": {
4+
"arrow-parens": [2, "as-needed"],
5+
"quotes": [2, "double"]
6+
}
7+
}

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
*.log
3+
.DS_Store

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/src

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: node_js
2+
cache:
3+
directories:
4+
- node_modules
5+
before_script:
6+
- export DISPLAY=:99.0
7+
- sh -e /etc/init.d/xvfb start
8+
sudo: false

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 ZURB, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# angular-tribute
2+
3+
> An AngularJS wrapper for ZURB's [Tribute](https://github.com/zurb/tribute) library for native @mentions.
4+
5+
## Install
6+
7+
```js
8+
$ npm install angular-tribute --save
9+
```
10+
11+
**or** include the UMD build, hosted by [npmcdn](https://npmcdn.com) in a `<script>` tag. You will also need to include the main ZURB Tribute library:
12+
13+
```js
14+
<script src="js/tribute.js"></script>
15+
<script src="//npmcdn.com/angular-tribute"></script>
16+
```
17+
18+
## Usage
19+
20+
```js
21+
import Angular from "angular";
22+
import AngularTribute from "angular-tribute";
23+
24+
angular
25+
.module('myApp', [])
26+
.directive('angularTribute', AngularTribute)
27+
```
28+
29+
In your controller:
30+
```js
31+
$scope.people = [
32+
{ name: 'Adam', email: '[email protected]' },
33+
{ name: 'Amalie', email: '[email protected]', },
34+
{ name: 'Estefanía', email: '[email protected]', },
35+
{ name: 'Adrian', email: '[email protected]', },
36+
{ name: 'Wladimir', email: '[email protected]', },
37+
{ name: 'Samantha', email: '[email protected]', },
38+
{ name: 'Nicole', email: '[email protected]', },
39+
{ name: 'Natasha', email: '[email protected]', },
40+
{ name: 'Michael', email: '[email protected]', },
41+
{ name: 'Nicolás', email: '[email protected]', }
42+
];
43+
44+
$scope.tributeConfig = {
45+
lookup: 'name',
46+
fillAttr: 'name'
47+
}
48+
49+
$scope.tributeOnReplaced = function () {
50+
console.log('text replaced!');
51+
};
52+
53+
$scope.tributeOnNoMatch = function () {
54+
console.log('no match found in collection!');
55+
};
56+
```
57+
58+
And in your view you can add:
59+
```html
60+
<textarea angular-tribute
61+
values="$ctrl.people"
62+
options="$ctrl.tributeConfig"
63+
on-replaced="$ctrl.tributeOnReplaced"
64+
on-no-match="$ctrl.tributeOnNoMatch"
65+
></textarea>
66+
```
67+
68+
> The `options`, `on-replaced` and `on-no-match` parameters are optional.
69+
70+
The `values` array should be an array of objects that contain a key and value like so:
71+
72+
```
73+
[
74+
{key: "Phil Heartman", value: "pheartman"},
75+
{key: "Gordon Ramsey", value: "gramsey"}
76+
]
77+
```
78+
79+
You can modify this structure using the built-in [Tribute options](https://github.com/zurb/tribute#a-collection).
80+
81+
## Events
82+
83+
Tribute broadcasts two events — a `tribute-replaced` event, and a `tribute-no-match` event (see docs [here](https://github.com/zurb/tribute#replace-event)). For your convenience, you can bind to these events by passing a function to `on-replaced` or `on-no-match` attributes respectively.
84+
85+
## License
86+
87+
MIT © [ZURB](http://zurb.com)

index.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict';
2+
3+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4+
5+
var Tribute = _interopDefault(require('tributejs/src'));
6+
7+
var _this = undefined;
8+
9+
if (typeof Tribute === 'undefined') {
10+
throw new Error('[AngularTribute] cannot locate tributejs!');
11+
}
12+
13+
var AngularTribute = function AngularTribute($timeout) {
14+
return {
15+
restrict: 'A',
16+
scope: {
17+
values: '=',
18+
options: '=',
19+
onReplaced: '&',
20+
onNoMatch: '&'
21+
},
22+
controller: function controller($scope) {
23+
_this.$onDestroy = function () {
24+
$scope.tribute.hideMenu();
25+
};
26+
},
27+
compile: function compile($element, $attrs) {
28+
var _this2 = this;
29+
30+
return function ($scope, $element, $attrs) {
31+
if (typeof $scope.options === 'array') {
32+
$scope.tribute = new Tribute({
33+
collection: $scope.options
34+
});
35+
} else {
36+
$scope.tribute = new Tribute(angular.merge({
37+
values: $scope.values
38+
}, $scope.options || {}));
39+
}
40+
41+
$scope.tribute.attach($element[0]);
42+
43+
$element[0].addEventListener("tribute-replaced", function (e) {
44+
$timeout($scope.onReplaced.apply(_this2));
45+
});
46+
$element[0].addEventListener("tribute-no-match", function (e) {
47+
$timeout($scope.onReplaced.apply(_this2));
48+
});
49+
};
50+
}
51+
};
52+
};
53+
54+
AngularTribute.$inject = ['$timeout'];
55+
56+
module.exports = AngularTribute;

index.umd.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
(function (global, factory) {
2+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tributejs/src')) :
3+
typeof define === 'function' && define.amd ? define(['tributejs/src'], factory) :
4+
(global.AngularTribute = factory(global.Tribute));
5+
}(this, function (Tribute) { 'use strict';
6+
7+
Tribute = 'default' in Tribute ? Tribute['default'] : Tribute;
8+
9+
var _this = undefined;
10+
11+
if (typeof Tribute === 'undefined') {
12+
throw new Error('[AngularTribute] cannot locate tributejs!');
13+
}
14+
15+
var AngularTribute = function AngularTribute($timeout) {
16+
return {
17+
restrict: 'A',
18+
scope: {
19+
values: '=',
20+
options: '=',
21+
onReplaced: '&',
22+
onNoMatch: '&'
23+
},
24+
controller: function controller($scope) {
25+
_this.$onDestroy = function () {
26+
$scope.tribute.hideMenu();
27+
};
28+
},
29+
compile: function compile($element, $attrs) {
30+
var _this2 = this;
31+
32+
return function ($scope, $element, $attrs) {
33+
if (typeof $scope.options === 'array') {
34+
$scope.tribute = new Tribute({
35+
collection: $scope.options
36+
});
37+
} else {
38+
$scope.tribute = new Tribute(angular.merge({
39+
values: $scope.values
40+
}, $scope.options || {}));
41+
}
42+
43+
$scope.tribute.attach($element[0]);
44+
45+
$element[0].addEventListener("tribute-replaced", function (e) {
46+
$timeout($scope.onReplaced.apply(_this2));
47+
});
48+
$element[0].addEventListener("tribute-no-match", function (e) {
49+
$timeout($scope.onReplaced.apply(_this2));
50+
});
51+
};
52+
}
53+
};
54+
};
55+
56+
AngularTribute.$inject = ['$timeout'];
57+
58+
return AngularTribute;
59+
60+
}));

karma.conf.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = function(config) {
2+
config.set({
3+
frameworks: ["browserify", "jasmine"],
4+
files: [
5+
"test/support/*.js",
6+
"test/**/*.spec.js"
7+
],
8+
preprocessors: {
9+
"/**/*.js": ["browserify"],
10+
"test/**/*.spec.js": ["browserify"]
11+
},
12+
browsers: ["PhantomJS"],
13+
reporters: ["spec"],
14+
browserify: {
15+
transform: [
16+
["babelify", {
17+
presets: ["es2015"],
18+
plugins: ["transform-runtime"]
19+
}],
20+
["aliasify", { aliases: { "tributejs": "./node_modules/tributejs/dist/tribute.js"} }]
21+
]
22+
}
23+
});
24+
}

package.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"name": "angular-tribute",
3+
"version": "0.0.1",
4+
"description": "An AngularJS wrapper for ZURB's Tribute library for native @mentions",
5+
"license": "MIT",
6+
"repository": "zurb/angular-tribute",
7+
"author": {
8+
"name": "ZURB",
9+
"email": "[email protected]",
10+
"url": "http://zurb.com"
11+
},
12+
"engines": {
13+
"node": ">=4"
14+
},
15+
"scripts": {
16+
"build:all": "npm run build && npm run build:umd",
17+
"build": "BUILD_ENV=cjs rollup -c",
18+
"build:umd": "BUILD_ENV=umd rollup -c",
19+
"test": "karma start karma.conf.js --single-run true --auto-watch false",
20+
"watch-test": "karma start karma.conf.js --single-run false --auto-watch true",
21+
"lint": "eslint src"
22+
},
23+
"main": "index.js",
24+
"files": [
25+
"index.js",
26+
"index.umd.js"
27+
],
28+
"keywords": [
29+
"tribute",
30+
"mention",
31+
"input",
32+
"AngularJS"
33+
],
34+
"dependencies": {},
35+
"devDependencies": {
36+
"aliasify": "^2.0.0",
37+
"babel-core": "^6.11.4",
38+
"babel-plugin-transform-runtime": "^6.9.0",
39+
"babel-preset-es2015": "^6.9.0",
40+
"babel-preset-es2015-rollup": "^1.1.1",
41+
"babel-runtime": "^6.9.2",
42+
"babelify": "^7.3.0",
43+
"browserify": "^13.0.1",
44+
"eslint": "^3.1.1",
45+
"eslint-config-standard": "^5.3.5",
46+
"eslint-plugin-promise": "^2.0.0",
47+
"eslint-plugin-standard": "^2.0.0",
48+
"jasmine-core": "^2.4.1",
49+
"karma": "^1.1.1",
50+
"karma-browserify": "^5.1.0",
51+
"karma-jasmine": "^1.0.2",
52+
"karma-phantomjs-launcher": "^1.0.1",
53+
"karma-spec-reporter": "0.0.26",
54+
"phantomjs-prebuilt": "^2.1.7",
55+
"rollup": "^0.33.0",
56+
"rollup-plugin-babel": "^2.6.1",
57+
"tributejs": "^2.0.4",
58+
"angular": "^1.5.7",
59+
"watchify": "^3.7.0"
60+
}
61+
}

rollup.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { rollup } from "rollup"
2+
import babel from "rollup-plugin-babel"
3+
4+
const env = process.env.BUILD_ENV
5+
const dest = env === "cjs" ? "index.js" : "index.umd.js"
6+
7+
export default {
8+
entry: "./src/index.js",
9+
external: [ "tributejs" ],
10+
plugins: [ babel() ],
11+
dest,
12+
format: env,
13+
moduleName: "AngularTribute",
14+
globals: {
15+
tributejs: "Tribute"
16+
}
17+
}

0 commit comments

Comments
 (0)