Merge remote-tracking branch 'origin/develop'
This commit is contained in:
commit
91015da330
9 changed files with 69 additions and 13876 deletions
|
|
@ -1,5 +1,2 @@
|
|||
dev/bundle.js*
|
||||
# we do not want to lock down dependencies when used as an npm dependency,
|
||||
# only when we build
|
||||
npm-shrinkwrap.json
|
||||
demo.gif
|
||||
|
|
|
|||
|
|
@ -14,9 +14,6 @@ Hi (future) collaborator!
|
|||
- [Development workflow](#development-workflow)
|
||||
- [Local example](#local-example)
|
||||
- [Documentation website](#documentation-website)
|
||||
- [Adding/Updating a package](#addingupdating-a-package)
|
||||
- [Removing a package](#removing-a-package)
|
||||
- [In case of shrinkwrap madness](#in-case-of-shrinkwrap-madness)
|
||||
- [Commit message guidelines](#commit-message-guidelines)
|
||||
- [Revert](#revert)
|
||||
- [Type](#type)
|
||||
|
|
@ -51,7 +48,7 @@ We use a simple documentation example website as a way to develop the docsearch.
|
|||
Requirements:
|
||||
- [Node.js](https://nodejs.org/en/)
|
||||
- npm@2
|
||||
|
||||
|
||||
```sh
|
||||
npm run dev
|
||||
# open http://localhost:8080
|
||||
|
|
@ -71,41 +68,6 @@ npm run dev:docs
|
|||
open http://localhost:4000/docsearch/
|
||||
```
|
||||
|
||||
# Adding/Updating a package
|
||||
|
||||
We use a [specific shrinkwrapping tool](https://github.com/uber/npm-shrinkwrap) and npm@2.
|
||||
|
||||
```sh
|
||||
npm install
|
||||
npm install package --save[-dev]
|
||||
npm run shrinkwrap
|
||||
```
|
||||
|
||||
# Removing a package
|
||||
|
||||
```sh
|
||||
npm install
|
||||
npm remove package --save[-dev]
|
||||
npm run shrinkwrap
|
||||
```
|
||||
|
||||
Removing packages can be really tricky to handle if the package was used by
|
||||
both the host project and sub dependencies.
|
||||
|
||||
# In case of shrinkwrap madness
|
||||
|
||||
```sh
|
||||
rm -rf node_modules
|
||||
rm npm-shrinkwrap.json
|
||||
npm cache clean
|
||||
npm install
|
||||
# check everything is working
|
||||
npm run shrinkwrap
|
||||
```
|
||||
|
||||
Don't do this too often because it breaks the whole shrinkwrap idea. Since
|
||||
you are completely rebuilding the dependency tree and possibly updating things.
|
||||
|
||||
# Commit message guidelines
|
||||
|
||||
We use [conventional changelog](https://github.com/ajoslin/conventional-changelog) to generate our changelog from our git commit messages.
|
||||
|
|
|
|||
13808
npm-shrinkwrap.json
generated
13808
npm-shrinkwrap.json
generated
File diff suppressed because it is too large
Load diff
38
package.json
38
package.json
|
|
@ -7,7 +7,6 @@
|
|||
"dev": "./scripts/dev",
|
||||
"dev:docs": "./scripts/dev-docs",
|
||||
"serve": "./scripts/serve",
|
||||
"shrinkwrap": "npm-shrinkwrap --dev",
|
||||
"doctoc": "doctoc --maxlevel 3 README.md CONTRIBUTING.md",
|
||||
"build": "./scripts/build",
|
||||
"build:css": "./scripts/build-css",
|
||||
|
|
@ -25,7 +24,7 @@
|
|||
"license": "MIT",
|
||||
"repository": "algolia/docsearch",
|
||||
"devDependencies": {
|
||||
"autoprefixer": "^6.1.2",
|
||||
"autoprefixer": "^6.3.6",
|
||||
"babel": "^5.8.29",
|
||||
"babel-core": "^5.8.29",
|
||||
"babel-eslint": "^4.1.3",
|
||||
|
|
@ -33,38 +32,37 @@
|
|||
"babel-loader": "^5.3.2",
|
||||
"babel-plugin-rewire": "^0.1.22",
|
||||
"conventional-changelog": "^0.5.1",
|
||||
"coveralls": "^2.11.6",
|
||||
"cssnano": "^3.4.0",
|
||||
"coveralls": "^2.11.9",
|
||||
"cssnano": "^3.7.0",
|
||||
"doctoc": "^0.15.0",
|
||||
"eslint": "^1.6.0",
|
||||
"eslint-config-airbnb": "^0.1.0",
|
||||
"eslint-config-algolia": "^4.2.0",
|
||||
"eslint-config-algolia": "^4.7.0",
|
||||
"eslint-plugin-algolia": "^1.5.0",
|
||||
"eslint-plugin-react": "^3.5.1",
|
||||
"expect": "^1.13.0",
|
||||
"expect": "^1.20.1",
|
||||
"gh-pages": "^0.8.0",
|
||||
"jsdom": "^7.1.1",
|
||||
"json": "^9.0.3",
|
||||
"mocha": "^2.3.4",
|
||||
"mocha-jsdom": "^1.0.0",
|
||||
"mocha-lcov-reporter": "^1.0.0",
|
||||
"json": "^9.0.4",
|
||||
"mocha": "^2.5.3",
|
||||
"mocha-jsdom": "^1.1.0",
|
||||
"mocha-lcov-reporter": "^1.2.0",
|
||||
"mversion": "^1.10.1",
|
||||
"nd": "^1.2.0",
|
||||
"node-sass": "^3.4.2",
|
||||
"npm-shrinkwrap": "^200.4.0",
|
||||
"onchange": "^2.0.0",
|
||||
"postcss-cli": "^2.3.2",
|
||||
"node-sass": "^3.7.0",
|
||||
"onchange": "^2.5.0",
|
||||
"postcss-cli": "^2.5.2",
|
||||
"pretty-bytes": "^2.0.1",
|
||||
"semver": "^5.1.0",
|
||||
"sinon": "^1.17.2",
|
||||
"uglify-js": "^2.6.1",
|
||||
"webpack": "^1.12.2",
|
||||
"webpack-dev-server": "^1.12.1"
|
||||
"sinon": "^1.17.4",
|
||||
"uglify-js": "^2.6.2",
|
||||
"webpack": "^1.13.1",
|
||||
"webpack-dev-server": "^1.14.1"
|
||||
},
|
||||
"peerDependencies": {},
|
||||
"dependencies": {
|
||||
"algoliasearch": "^3.9.2",
|
||||
"autocomplete.js": "^0.17.3",
|
||||
"algoliasearch": "^3.15.0",
|
||||
"autocomplete.js": "^0.20.0",
|
||||
"hogan.js": "^3.0.2",
|
||||
"npm-zepto": "^1.1.7",
|
||||
"to-factory": "^1.0.0"
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ npm run doctoc
|
|||
|
||||
# git add and tag
|
||||
commitMessage="v$newVersion\n\n$changelog"
|
||||
git add src/lib/version.js npm-shrinkwrap.json package.json CHANGELOG.md README.md CONTRIBUTING.md
|
||||
git add src/lib/version.js package.json CHANGELOG.md README.md CONTRIBUTING.md
|
||||
printf "$commitMessage" | git commit --file -
|
||||
git tag "v$newVersion"
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ touch $tmpfile
|
|||
|
||||
# git add and tag
|
||||
commitMessage="v$newVersion\n\n$changelog"
|
||||
git add src/lib/version.js npm-shrinkwrap.json package.json CHANGELOG.md CONTRIBUTING.md README.md
|
||||
git add src/lib/version.js package.json CHANGELOG.md CONTRIBUTING.md README.md
|
||||
printf "$commitMessage" | git commit --file -
|
||||
|
||||
printf "\n\nBeta release: almost done, check everything in another terminal tab.\n"
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ set -ev # exit when error
|
|||
./scripts/validate-pr-done-on-develop
|
||||
npm run test:coverage
|
||||
npm prune
|
||||
npm run shrinkwrap --dev
|
||||
NODE_ENV=production npm run build
|
||||
./scripts/validate-commit-msgs
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ class DocSearch {
|
|||
|
||||
this.client = algoliasearch(this.appId, this.apiKey);
|
||||
this.client.addAlgoliaAgent('docsearch.js ' + version);
|
||||
|
||||
this.autocomplete = autocomplete(this.input, autocompleteOptions, [{
|
||||
source: this.getAutocompleteSource(),
|
||||
templates: {
|
||||
|
|
@ -62,7 +63,11 @@ class DocSearch {
|
|||
this.autocomplete.on(
|
||||
'autocomplete:selected',
|
||||
this.handleSelected.bind(null, this.autocomplete.autocomplete)
|
||||
);
|
||||
)
|
||||
this.autocomplete.on(
|
||||
'autocomplete:shown',
|
||||
this.handleShown.bind(null, this.input)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -184,6 +189,27 @@ class DocSearch {
|
|||
input.setVal('');
|
||||
window.location.href = suggestion.url;
|
||||
}
|
||||
|
||||
handleShown(input, event) {
|
||||
var middleOfInput = input.offset().left + input.width() / 2;
|
||||
var middleOfWindow = $(document).width() / 2;
|
||||
|
||||
if (isNaN(middleOfWindow)) {
|
||||
middleOfWindow = 900;
|
||||
}
|
||||
|
||||
var alignClass = middleOfInput - middleOfWindow >= 0 ? 'algolia-autocomplete-right' : 'algolia-autocomplete-left';
|
||||
var otherAlignClass = middleOfInput - middleOfWindow < 0 ? 'algolia-autocomplete-right' : 'algolia-autocomplete-left';
|
||||
|
||||
var autocompleteWrapper = $('.algolia-autocomplete');
|
||||
if (! autocompleteWrapper.hasClass(alignClass)) {
|
||||
autocompleteWrapper.addClass(alignClass)
|
||||
}
|
||||
|
||||
if (autocompleteWrapper.hasClass(otherAlignClass)) {
|
||||
autocompleteWrapper.removeClass(otherAlignClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default DocSearch;
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ describe('DocSearch', () => {
|
|||
expect(AutoComplete.calledOnce).toBe(true);
|
||||
expect(AutoComplete.calledWith($input, 'bar')).toBe(true);
|
||||
});
|
||||
it('should listen to the selected event of autocomplete', () => {
|
||||
it('should listen to the selected and shown event of autocomplete', () => {
|
||||
// Given
|
||||
let options = defaultOptions;
|
||||
|
||||
|
|
@ -215,7 +215,7 @@ describe('DocSearch', () => {
|
|||
new DocSearch(options);
|
||||
|
||||
// Then
|
||||
expect(autocomplete.on.calledOnce).toBe(true);
|
||||
expect(autocomplete.on.calledTwice).toBe(true);
|
||||
expect(autocomplete.on.calledWith('autocomplete:selected')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
@ -389,6 +389,25 @@ describe('DocSearch', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('handleShown', () => {
|
||||
it('should add an alignment class', () => {
|
||||
// Given
|
||||
const options = {
|
||||
apiKey: 'key',
|
||||
indexName: 'foo',
|
||||
inputSelector: '#input'
|
||||
};
|
||||
|
||||
// When
|
||||
let ds = new DocSearch(options);
|
||||
|
||||
ds.autocomplete.trigger('autocomplete:shown');
|
||||
|
||||
expect($('.algolia-autocomplete').attr('class')).toEqual('algolia-autocomplete algolia-autocomplete-left');
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatHits', () => {
|
||||
it('should not mutate the input', () => {
|
||||
// Given
|
||||
|
|
|
|||
Loading…
Reference in a new issue