Skip to content

Commit 7c55ca1

Browse files
authored
Merge pull request #144 from angular-ui/adapter-assignments
2 parents 094c64d + 625d25e commit 7c55ca1

29 files changed

+550
-425
lines changed

Gruntfile.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,14 @@ module.exports = function (grunt) {
126126
});
127127

128128
grunt.registerTask('server', [
129-
'webpack:default',
130129
'connect',
131130
'watch'
132131
]);
133132

134-
grunt.registerTask('default', ['server']);
133+
grunt.registerTask('default', [
134+
'webpack:default',
135+
'server'
136+
]);
135137

136138
grunt.registerTask('test', [
137139
'clean:temp',

README.md

+58-32
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ It will start retrieving new data for new elements again if the user scrolls up/
6464
### Basic usage
6565

6666
```html
67-
<ANY ui-scroll="{scroll_expression}" buffer-size="value" ... >
67+
<ANY ui-scroll-viewport>
68+
<ANY ui-scroll="items in datasource" ... >
6869
...
70+
</ANY>
6971
</ANY>
7072
```
7173
Listing `ANY` for the tag, the directive can be applied to, stretches the truth - a little bit. The directive works well with majority
@@ -81,6 +83,10 @@ _Important!_ The viewport height must be constrained. If the height of the viewp
8183
in the datasource. Even if it does not, using the directive this way does not provide any advantages over using ng-repeat, because
8284
item template will be always instantiated for every item in the datasource.
8385

86+
_Important!_ There is a Scroll Anchoring feature enforced by Google Chrome (since Chrome 56) which makes scroller behaviour incorrect.
87+
The ui-scroll-viewport directive eliminates this effect by disabling the 'overflow-anchor' css-property on its element.
88+
But if the ui-scroll-viewport is not presented in the template, you should take care of this manually.
89+
8490

8591
### Examples
8692

@@ -142,29 +148,31 @@ It is empty since it was deprecated in v1.6.0.
142148
>{{item}}</div>
143149
```
144150

145-
### Parametrs
151+
### Parameters
146152

147153
* **uiScroll – scroll expression** – The expression indicating how to enumerate a collection. Only one format is currently supported: `variable in datasource` – where variable is the user defined loop variable and datasource is the name of the data source to enumerate.
148-
* **buffer-size - expression**, optional - number of items requested from the datasource in a single request. The default is 10 and the minimal value is 3
149-
* **padding - expression**, optional - extra height added to the visible area for the purpose of determining when the items should be created/destroyed. The value is relative to the visible height of the area, the default is 0.5 and the minimal value is 0.3
154+
* **buffer-size - expression**, optional - number of items requested from the datasource in a single request. The default is 10 and the minimal value is 3.
155+
* **padding - expression**, optional - extra height added to the visible area for the purpose of determining when the items should be created/destroyed. The value is relative to the visible height of the area, the default is 0.5 and the minimal value is 0.3.
150156
* **start-index - expression**, optional - index of the first item to be requested from the datasource. The default is 1.
151157
* **adapter - assignable expression**, optional - if provided a reference to the adapter object for the scroller instance will be injected in the appropriate scope. If you have multiple scrollers within the same viewport, make sure that every one of them has its unique adapter name.
152158

153159
Some of the properties offered by the adapter can also be accessed directly from the directive by using matching attributes. In the same way as for the adapter attribute, syntax for such attributes allows for providing a reference expression to be used to access the corresponding value. Below is a list of such attributes:
154160

155-
* **is-loading - assignable expression**, optional - a boolean value indicating whether there are any pending load requests will be injected in the appropriate scope. See also `isLoading` adapter property.
156-
* **top-visible - assignable expression**, optional - a reference to the item currently in the topmost visible position will be injected in the appropriate scope. See also `topVisible` adapter property.
157-
* **top-visible-element - assignable expression**, optional - a reference to the DOM element currently in the topmost visible position will be injected in the appropriate scope. See also `topVisibleElement` adapter property.
158-
* **top-visible-scope - assignable expression**, optional - a reference to the scope created for the item currently in the topmost visible position will be injected in the appropriate scope. See also `topVisibleScope` adapter property.
161+
* **is-loading - assignable expression**, optional - a boolean value indicating whether there are any pending load requests will be injected in the appropriate scope. See also `isLoading` adapter property, which is preferable.
162+
* **top-visible - assignable expression**, optional - a reference to the item currently in the topmost visible position will be injected in the appropriate scope. See also `topVisible` adapter property, which is preferable.
163+
* **top-visible-element - assignable expression**, optional - a reference to the DOM element currently in the topmost visible position will be injected in the appropriate scope. See also `topVisibleElement` adapter property, which is preferable.
164+
* **top-visible-scope - assignable expression**, optional - a reference to the scope created for the item currently in the topmost visible position will be injected in the appropriate scope. See also `topVisibleScope` adapter property, which is preferable.
159165

160166
The `expression` can be any angular expression (assignable expression where so specified). All expressions are evaluated once at the time when the scroller is initialized. Changes in the expression value after scroller initialization will have no impact on the scroller behavior.
161167

162-
The assignable expressions will be used by scroller to inject the requested value into the target scope. The scope associated with the viewport (the element marked with the [uiScrollViewport](#uiscrollviewport-directive) directive) will be used as the target scope. If the viewport is not defined (window viewport), the $rootScope will be used as the target scope. Note that the nearest additional scope-wrapper (like ng-if directive set right on the viewport) makes this mechanism unusable. There are two options which help in this case:
163-
164-
1. The second format `expression on controller` can be used to explicitly target the scope associated with the specified controller as the target scope for the injection. In this format `expression` is any angular assignable expression, and `controller` is the name of controller constructor function as specified in the `ng-controller` directive. The scroller will traverse its parents to locate the target scope associated with the specified controller.
165-
166-
2. Also `Controller As` syntax could be used as an alternative way to specify target controller in assignable expressions.
168+
The `assignable expressions` will be used by scroller to inject the requested value into the target scope.
169+
The target scope is being defined in accordance with standard Angular rules (nested scopes and controller As syntax should be taken into account):
170+
the scroller will traverse its parents (from the ui-scroll element's scope up to the $rootScope) to locate the target scope.
171+
If the viewport is presented (the element marked with the [uiScrollViewport](#uiscrollviewport-directive) directive),
172+
then the scope associated with the viewport will be a start point in the target scope locating.
173+
Angular $parse service is being used in `assignable expressions` implementation.
167174

175+
_Deprecated!_ The format `expression on controller` introduced in v1.5.0 (and deprecated in v1.6.1) can be used to explicitly target the scope associated with the specified controller as the target scope for the injection. In this format `expression` is any angular assignable expression, and `controller` is the name of controller constructor function as specified in the `ng-controller` directive.
168176

169177
### Datasource
170178

@@ -186,7 +194,8 @@ The data source object implements methods and properties to be used by the direc
186194
get(index, count, success)
187195

188196
This is a mandatory method used by the directive to retrieve the data.
189-
#### Parameters
197+
198+
Parameters
190199
* **descriptor** is an object defining the portion of the dataset requested. The object will have 3 properties. Two of them named `index` and `count`. They have the same meaning as in the alternative signature when the parameters passed explicitly (see below). The third one will be named either `append` if the items will be appended to the last item in the buffer, or `prepend` if they are to be prepended to the first item in the buffer. The value of the property in either case will be the item the new items will be appended/prepended to. This is useful if it is easier to identify the items to be added based on the previously requested items rather than on the index. Keep in mind that in certain use cases (i.e. on initial load) the value of the append/prepend property can be undefined.
191200
* **index** indicates the first data row requested
192201
* **count** indicates number of data rows requested
@@ -204,7 +213,7 @@ exactly `count` elements unless it hit eof/bof.
204213

205214
###Adapter
206215

207-
The adapter object is an internal object created for every instance of the scroller. Properties and methods of the adapter can be used to manipulate and assess the scroller the adapter was created for. Adapter based API replaces old (undocumented) event based API introduced earlier for this purpose. The event based API is now deprecated and no longer supported.
216+
The adapter object is an internal object created for every instance of the scroller. Properties and methods of the adapter can be used to manipulate and assess the scroller the adapter was created for.
208217

209218
Adapter object implements the following properties:
210219

@@ -250,30 +259,34 @@ Adapter object implements the following methods
250259
applyUpdates(index, newItems)
251260

252261
Replaces the item in the buffer at the given index with the new items.
253-
#### Parameters
262+
263+
Parameters
254264
* **index** provides position of the item to be affected in the dataset (not in the buffer). If the item with the given index currently is not in the buffer no updates will be applied. `$index` property of the item $scope can be used to access the index value for a given item
255265
* **newItems** is an array of items to replace the affected item. If the array is empty (`[]`) the item will be deleted, otherwise the items in the array replace the item. If the newItem array contains the old item, the old item stays in place.
256266

257267
applyUpdates(updater)
258268

259269
Updates scroller content as determined by the updater function
260-
#### Parameters
270+
271+
Parameters
261272
* **updater** is a function to be applied to every item currently in the buffer. The function will receive 3 parameters: `item`, `scope`, and `element`. Here `item` is the item to be affected, `scope` is the item $scope, and `element` is the html element for the item. The return value of the function should be an array of items. Similarly to the `newItem` parameter (see above), if the array is empty(`[]`), the item is deleted, otherwise the item is replaced by the items in the array. If the return value is not an array, the item remains unaffected, unless some updates were made to the item in the updater function. This can be thought of as in place update.
262273

263274
* Method `append`
264275

265276
append(newItems)
266277

267278
Adds new items after the last item in the buffer.
268-
#### Parameters
279+
280+
Parameters
269281
* **newItems** provides an array of items to be appended.
270282

271283
* Method `prepend`
272284

273285
prepend(newItems)
274286

275287
Adds new items before the first item in the buffer.
276-
#### Parameters
288+
289+
Parameters
277290
* **newItems** provides an array of items to be prepended.
278291

279292
#### Manipulating the scroller content with adapter methods
@@ -390,7 +403,7 @@ The ui-scroll sources are in [./src](https://github.com/angular-ui/ui-scroll/tre
390403
because of ES6 modules (since v1.6.0), they should be built. Build process includes jshint sources verification, webpack-based
391404
distributive files forming and tests running.
392405

393-
Three npm scripts are available for developing.
406+
There are some npm scripts available for developing.
394407

395408
__1__. To run dev-server use
396409

@@ -410,35 +423,48 @@ npm test
410423
```
411424

412425
This runs karma testing against temporary distributive files (./temp). We created a number of specifications which consist of more
413-
than 160 tests. They are living at [./test](https://github.com/angular-ui/ui-scroll/tree/master/test) folder. Karma watches for temp
414-
and test folders changes and automatically re-run tests.
426+
than 160 tests. They are living at the [./test](https://github.com/angular-ui/ui-scroll/tree/master/test) folder. Karma watches for temp
427+
and test folders changes and automatically re-runs tests.
428+
429+
__3__. To run both dev-server and tests in keep-alive mode use
415430

416-
__3__. To run full build use
431+
```
432+
npm run dev
433+
```
434+
435+
This is the combination of first two scripts running in concurrently mode. This allows you to work with the ui-scroll examples on 5005 port
436+
during continuous tests running.
437+
438+
__4__. To run full build process use
417439

418440
```
419441
npm run build
420442
```
421443

422-
After developing and testing complete the build process should be run to
444+
After developing and testing complete, the build process should be run to
423445
a) pass through jshint,
424446
b) generate minified versions of distributive,
425447
c) run tests with minified distributive files,
426-
d) obtain all necessary files in [./dist](https://github.com/angular-ui/ui-scroll/tree/master/dist) folder.
448+
d) obtain all necessary files in the [./dist](https://github.com/angular-ui/ui-scroll/tree/master/dist) folder.
427449

428-
PR should include source code (./scr) and tests (./test) changes and may not include public distributive (./dist) changes.
450+
PR should include source code (./scr) changes, may include tests (./test) changes and may not include public distributive (./dist) changes.
429451

430452

431453
-------------------
432454

433455

434456
## Change log
435457

458+
###v1.6.1
459+
* Refactored Adapter assignments logic
460+
* Fixed Chrome Scroll Anchoring enforced feature [bug](https://github.com/angular-ui/ui-scroll/issues/138)
461+
436462
###v1.6.0
437463
* Introduced ES6 modules in the source codes.
438464
* Improved build process with Webpack.
439465
* Added sourcemaps. Fixed dev-server.
440466
* Removed 'ui.scroll.jqlite' module. Added jqLiteExtras service to 'ui.scroll' module.
441-
* Significantly changed readme.
467+
* Significantly changed the README.
442468

443469
###v1.5.2
444470
* Refactored assignable expressions and attributes scope bindings.
@@ -481,21 +507,21 @@ PR should include source code (./scr) and tests (./test) changes and may not inc
481507
###v1.3.0
482508
* Reorganized the repository structure.
483509

484-
####v1.2.1
510+
###v1.2.1
485511
* Dismiss pending requests on applyUpdates().
486512

487-
####v1.2.0
513+
###v1.2.0
488514
* Changed the algorithm of list items building.
489515
* Integration with angular $animation.
490516
* Insert/update/delete events are no longer supported.
491517

492-
####v1.1.2
518+
###v1.1.2
493519
* Fixed inserting elements via applyUpdates error.
494520

495-
####v1.1.1
521+
###v1.1.1
496522
* Fixed jqlite on $destroy error.
497523

498-
####v1.1.0
524+
###v1.1.0
499525
* Introduced API to dynamically update scroller content.
500526
* Deep 'name' properties access via dot-notation in template.
501527
* Fixed the problem occurring if the scroller is $destroyed while there are requests pending: [#64](https://github.com/Hill30/NGScroller/issues/64).

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-ui-scroll",
33
"description": "AngularJS infinite scrolling module",
4-
"version": "1.6.0",
4+
"version": "1.6.1",
55
"main": "./dist/ui-scroll.js",
66
"homepage": "https://github.com/angular-ui/ui-scroll.git",
77
"license": "MIT",

demo/adapter/adapter.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ <h1 class="page-header page-header-exapmle">Adapter (updatable scroller)</h1>
1818

1919
<div class="description">
2020
<ul>
21-
<li>New mechanism of scroller data custom processing is introduced. </li>
22-
<li>Single datasource but two different viewports with two different processing adapters.</li>
23-
<li>The firstListAdapter is initially defined on ctrl $scope as a first level object with some property.</li>
24-
<li>The second.list.adapter chain is not defined on ctrl $scope. The scroller defines it during linking.</li>
21+
<li>This is a simple demo which demonstrates some basic Adapter usage.</li>
22+
<li>For all operations presented here the only one Adapter method is being used: applyUpdates.</li>
23+
<li>In this demo we have single datasource defined on the Main Controller .</li>
24+
<li>And two different viewports with two different processing Adapters (on the First and the Second Controllers).</li>
2525
</ul>
2626
</div>
2727

28-
<div class="viewport-group">
28+
<div class="viewport-group" ng-controller="firstController">
2929
<h2 class="viewport-group-tilte">1st list</h2>
3030

3131
<div class="info">
@@ -49,7 +49,7 @@ <h2 class="viewport-group-tilte">1st list</h2>
4949

5050
<hr>
5151

52-
<div class="viewport-group">
52+
<div class="viewport-group" ng-controller="secondController">
5353
<h2 class="viewport-group-tilte">2st list</h2>
5454

5555
<div class="info">

0 commit comments

Comments
 (0)