Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Humphreys committed Jul 27, 2016
0 parents commit 73f96d1
Show file tree
Hide file tree
Showing 18 changed files with 504 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [ "es2015-rollup" ]
}
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "standard",
"rules": {
"arrow-parens": [2, "as-needed"],
"quotes": [2, "double"]
}
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
*.log
.DS_Store
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/src
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: node_js
cache:
directories:
- node_modules
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
sudo: false
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 ZURB, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
87 changes: 87 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# angular-tribute

> An AngularJS wrapper for ZURB's [Tribute](https://github.com/zurb/tribute) library for native @mentions.
## Install

```js
$ npm install angular-tribute --save
```

**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:

```js
<script src="js/tribute.js"></script>
<script src="//npmcdn.com/angular-tribute"></script>
```

## Usage

```js
import Angular from "angular";
import AngularTribute from "angular-tribute";

angular
.module('myApp', [])
.directive('angularTribute', AngularTribute)
```

In your controller:
```js
$scope.people = [
{ name: 'Adam', email: '[email protected]' },
{ name: 'Amalie', email: '[email protected]', },
{ name: 'Estefanía', email: '[email protected]', },
{ name: 'Adrian', email: '[email protected]', },
{ name: 'Wladimir', email: '[email protected]', },
{ name: 'Samantha', email: '[email protected]', },
{ name: 'Nicole', email: '[email protected]', },
{ name: 'Natasha', email: '[email protected]', },
{ name: 'Michael', email: '[email protected]', },
{ name: 'Nicolás', email: '[email protected]', }
];

$scope.tributeConfig = {
lookup: 'name',
fillAttr: 'name'
}

$scope.tributeOnReplaced = function () {
console.log('text replaced!');
};

$scope.tributeOnNoMatch = function () {
console.log('no match found in collection!');
};
```

And in your view you can add:
```html
<textarea angular-tribute
values="$ctrl.people"
options="$ctrl.tributeConfig"
on-replaced="$ctrl.tributeOnReplaced"
on-no-match="$ctrl.tributeOnNoMatch"
></textarea>
```

> The `options`, `on-replaced` and `on-no-match` parameters are optional.
The `values` array should be an array of objects that contain a key and value like so:

```
[
{key: "Phil Heartman", value: "pheartman"},
{key: "Gordon Ramsey", value: "gramsey"}
]
```

You can modify this structure using the built-in [Tribute options](https://github.com/zurb/tribute#a-collection).

## Events

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.

## License

MIT © [ZURB](http://zurb.com)
56 changes: 56 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var Tribute = _interopDefault(require('tributejs/src'));

var _this = undefined;

if (typeof Tribute === 'undefined') {
throw new Error('[AngularTribute] cannot locate tributejs!');
}

var AngularTribute = function AngularTribute($timeout) {
return {
restrict: 'A',
scope: {
values: '=',
options: '=',
onReplaced: '&',
onNoMatch: '&'
},
controller: function controller($scope) {
_this.$onDestroy = function () {
$scope.tribute.hideMenu();
};
},
compile: function compile($element, $attrs) {
var _this2 = this;

return function ($scope, $element, $attrs) {
if (typeof $scope.options === 'array') {
$scope.tribute = new Tribute({
collection: $scope.options
});
} else {
$scope.tribute = new Tribute(angular.merge({
values: $scope.values
}, $scope.options || {}));
}

$scope.tribute.attach($element[0]);

$element[0].addEventListener("tribute-replaced", function (e) {
$timeout($scope.onReplaced.apply(_this2));
});
$element[0].addEventListener("tribute-no-match", function (e) {
$timeout($scope.onReplaced.apply(_this2));
});
};
}
};
};

AngularTribute.$inject = ['$timeout'];

module.exports = AngularTribute;
60 changes: 60 additions & 0 deletions index.umd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tributejs/src')) :
typeof define === 'function' && define.amd ? define(['tributejs/src'], factory) :
(global.AngularTribute = factory(global.Tribute));
}(this, function (Tribute) { 'use strict';

Tribute = 'default' in Tribute ? Tribute['default'] : Tribute;

var _this = undefined;

if (typeof Tribute === 'undefined') {
throw new Error('[AngularTribute] cannot locate tributejs!');
}

var AngularTribute = function AngularTribute($timeout) {
return {
restrict: 'A',
scope: {
values: '=',
options: '=',
onReplaced: '&',
onNoMatch: '&'
},
controller: function controller($scope) {
_this.$onDestroy = function () {
$scope.tribute.hideMenu();
};
},
compile: function compile($element, $attrs) {
var _this2 = this;

return function ($scope, $element, $attrs) {
if (typeof $scope.options === 'array') {
$scope.tribute = new Tribute({
collection: $scope.options
});
} else {
$scope.tribute = new Tribute(angular.merge({
values: $scope.values
}, $scope.options || {}));
}

$scope.tribute.attach($element[0]);

$element[0].addEventListener("tribute-replaced", function (e) {
$timeout($scope.onReplaced.apply(_this2));
});
$element[0].addEventListener("tribute-no-match", function (e) {
$timeout($scope.onReplaced.apply(_this2));
});
};
}
};
};

AngularTribute.$inject = ['$timeout'];

return AngularTribute;

}));
24 changes: 24 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = function(config) {
config.set({
frameworks: ["browserify", "jasmine"],
files: [
"test/support/*.js",
"test/**/*.spec.js"
],
preprocessors: {
"/**/*.js": ["browserify"],
"test/**/*.spec.js": ["browserify"]
},
browsers: ["PhantomJS"],
reporters: ["spec"],
browserify: {
transform: [
["babelify", {
presets: ["es2015"],
plugins: ["transform-runtime"]
}],
["aliasify", { aliases: { "tributejs": "./node_modules/tributejs/dist/tribute.js"} }]
]
}
});
}
61 changes: 61 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "angular-tribute",
"version": "0.0.1",
"description": "An AngularJS wrapper for ZURB's Tribute library for native @mentions",
"license": "MIT",
"repository": "zurb/angular-tribute",
"author": {
"name": "ZURB",
"email": "[email protected]",
"url": "http://zurb.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"build:all": "npm run build && npm run build:umd",
"build": "BUILD_ENV=cjs rollup -c",
"build:umd": "BUILD_ENV=umd rollup -c",
"test": "karma start karma.conf.js --single-run true --auto-watch false",
"watch-test": "karma start karma.conf.js --single-run false --auto-watch true",
"lint": "eslint src"
},
"main": "index.js",
"files": [
"index.js",
"index.umd.js"
],
"keywords": [
"tribute",
"mention",
"input",
"AngularJS"
],
"dependencies": {},
"devDependencies": {
"aliasify": "^2.0.0",
"babel-core": "^6.11.4",
"babel-plugin-transform-runtime": "^6.9.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-es2015-rollup": "^1.1.1",
"babel-runtime": "^6.9.2",
"babelify": "^7.3.0",
"browserify": "^13.0.1",
"eslint": "^3.1.1",
"eslint-config-standard": "^5.3.5",
"eslint-plugin-promise": "^2.0.0",
"eslint-plugin-standard": "^2.0.0",
"jasmine-core": "^2.4.1",
"karma": "^1.1.1",
"karma-browserify": "^5.1.0",
"karma-jasmine": "^1.0.2",
"karma-phantomjs-launcher": "^1.0.1",
"karma-spec-reporter": "0.0.26",
"phantomjs-prebuilt": "^2.1.7",
"rollup": "^0.33.0",
"rollup-plugin-babel": "^2.6.1",
"tributejs": "^2.0.4",
"angular": "^1.5.7",
"watchify": "^3.7.0"
}
}
17 changes: 17 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { rollup } from "rollup"
import babel from "rollup-plugin-babel"

const env = process.env.BUILD_ENV
const dest = env === "cjs" ? "index.js" : "index.umd.js"

export default {
entry: "./src/index.js",
external: [ "tributejs" ],
plugins: [ babel() ],
dest,
format: env,
moduleName: "AngularTribute",
globals: {
tributejs: "Tribute"
}
}
Loading

0 comments on commit 73f96d1

Please sign in to comment.