-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dynamo_Client_Store_web_store.war_shared_js_viewModels_guidedNavigationViewModel.js.html
executable file
·596 lines (540 loc) · 33.1 KB
/
Dynamo_Client_Store_web_store.war_shared_js_viewModels_guidedNavigationViewModel.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: Dynamo/Client/Store/web/store.war/shared/js/viewModels/guidedNavigationViewModel.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: Dynamo/Client/Store/web/store.war/shared/js/viewModels/guidedNavigationViewModel.js</h1>
<section>
<article>
<pre class="prettyprint source"><code>/**
* @fileoverview Guided Navigation View Model.
*
*
*/
define(
//-------------------------------------------------------------------
// PACKAGE NAME
//-------------------------------------------------------------------
'viewModels/guidedNavigationViewModel',
//-------------------------------------------------------------------
// DEPENDENCIES
//-------------------------------------------------------------------
['knockout', 'pubsub',
'ccConstants', 'ccLogger', 'navigation', 'jquery', 'spinner', 'CCi18n', 'pageLayout/search', 'storageApi', 'pageLayout/site'],
//-------------------------------------------------------------------
// MODULE DEFINITION
//-------------------------------------------------------------------
function(ko, pubsub, CCConstants, log, navigation, $, spinner, CCi18n, SearchViewModel, storageApi, SiteViewModel) {
"use strict";
//-------------------------------------------------------
// Class definition & member variables
//-------------------------------------------------------
/**
* Creates a Guided Navigation view model.
* @private
* @class GuidedNavigationViewModel
* @param {integer} maxDimensionCount The maximum number of dimensions.
* @param {integer} maxRefinementCount The maximum number of refinements.
* @param {string} locale The locale.
* @param {string} searchResultsHash=CCConstants.SEARCH_RESULTS_HASH An optional configurable URL root for search results page.
*
* @property {String} categoryDimension=CCConstants.SEARCH_RESULTS_HASH Category dimension.
* @property {String} priceRangeDimension=CCConstants.GUIDED_NAVIGATION_PRICERANGE Price range dimension.
* @property {observable<boolean>} displayWidget=true Display the widget?
* @property {integer} maxDimensionCount The maximum number of dimensions.
* @property {integer} maxRefinementCount The maximum number of refinements.
* @property {String} searchResultsHash=CCConstants.SEARCH_RESULTS_HASH An optional configurable URL root for search results page.
* @property {observable} dimensions A collapsible list of dimensions.
* @property {observableArray} allRefinementCrumbs Search refinement breadcrumbs.
* @property {string} searchText The current search text.
* @property {string} categoryHref Category href.
* @property {string} categoryName Category name.
* @property {string} categoryDimensionId Category dimension ID.
* @property {string} categoryRepositoryId Category repository ID.
*/
function GuidedNavigationViewModel(maxDimensionCount, maxRefinementCount, locale, searchResultsHash) {
var self = this;
self.displayWidget = ko.observable(true);
self.maxDimensionCount = maxDimensionCount;
self.maxRefinementCount = maxRefinementCount;
self.dimensions = self.collapsibleList([], self.maxDimensionCount);
self.allRefinementCrumbs = ko.observableArray();
self.searchText = ko.observable('');
self.categoryHref = ko.observable('');
self.categoryName = ko.observable('');
self.categoryDimensionId = ko.observable('');
self.categoryRepositoryId = ko.observable('');
self.priceRangeDimension = CCConstants.GUIDED_NAVIGATION_PRICERANGE;
self.categoryDimension = CCConstants.GUIDED_NAVIGATION_CATEGORY;
GuidedNavigationViewModel.prototype.locale(locale);
GuidedNavigationViewModel.prototype.searchResultsHash = searchResultsHash ? searchResultsHash : CCConstants.SEARCH_RESULTS_HASH;
self.initialize();
/**
* Remove a refinement breadcrumb.
* @function GuidedNavigationViewModel#removeRefinement
* @param {string} refinement The refinement to be removed.
*/
self.removeRefinement = function(refinement) {
GuidedNavigationViewModel.prototype.createSpinner ();
if (self.searchText() === "" && refinement.dimensionName === CCConstants.GUIDED_NAVIGATION_CATEGORY) {
var navigationState = refinement.removeAction ? refinement.removeAction.navigationState : undefined;
var navigationArray = navigationState ? navigationState.split("&") : undefined;
var found = false;
// redirects to the parent category when its category/sub-category refinement is removed by appending generated id.
for (var i=0;i < navigationArray.length;i++) {
if (navigationArray[i].indexOf("N=") !== -1) {
var id = navigationArray[i].substring(navigationArray[i].indexOf("N=") + 2);
var generatedId = self.categoryDimensionId()+"+"+id;
navigationState = navigationState.replace(id, generatedId);
found = true;
}
}
// No other refinement crumbs are present.
if (found == false) {
navigation.goTo(self.categoryHref());
}
else {
navigation.goTo(self.searchResultsHash + navigationState + "&"
+ CCConstants.SEARCH_TYPE + "=" + CCConstants.SEARCH_TYPE_GUIDED + "&"
+ CCConstants.PARAMETERS_TYPE + "=" + CCConstants.PARAMETERS_SEARCH_QUERY);
}
}
else {
navigation.goTo(self.searchResultsHash + refinement.removeAction.navigationState + "&"
+ CCConstants.SEARCH_TYPE + "=" + CCConstants.SEARCH_TYPE_GUIDED + "&"
+ CCConstants.PARAMETERS_TYPE + "=" + CCConstants.PARAMETERS_SEARCH_QUERY);
}
};
/**
* Remove all refinements.
* @function GuidedNavigationViewModel#clearAllRefinements
*/
self.clearAllRefinements = function() {
GuidedNavigationViewModel.prototype.createSpinner ();
if (self.searchText().trim()) {
navigation.goTo(self.searchResultsHash + "?"
+ CCConstants.SEARCH_TERM_KEY + "="
+ encodeURIComponent(self.searchText().trim()) + "&"
+ CCConstants.SEARCH_DYM_SPELL_CORRECTION_KEY + "="
+ encodeURIComponent(CCConstants.DYM_ENABLED) + "&"
+ CCConstants.SEARCH_NAV_ERECS_OFFSET + "=0&"
+ CCConstants.SEARCH_REC_PER_PAGE_KEY + "="
+ CCConstants.DEFAULT_SEARCH_RECORDS_PER_PAGE + "&"
+ CCConstants.SEARCH_TYPE + "=" + CCConstants.SEARCH_TYPE_SIMPLE + "&"
+ CCConstants.PARAMETERS_TYPE + "=" + CCConstants.PARAMETERS_SEARCH_QUERY);
}
else {
navigation.goTo(self.categoryHref());
}
};
/**
* Check for range refinement.
* @function GuidedNavigationViewModel#checkForRange
*/
self.checkForRange = function(value) {
var a = "dimval.match_type";
if (value && value.properties && value.properties[a] === 'range') {
return true;
}
return false;
};
/**
* Check if the range is an unbounded range.
* @function GuidedNavigationViewModel#checkIfUnboundRange
*/
self.checkIfUnboundRange = function(value) {
var dGraphSpec = "DGraph.Spec";
if (value && value.properties && value.properties[dGraphSpec].indexOf('-unbounded') != -1) {
return true;
}
return false;
};
/**
* Get the lower bound value of the range.
* @function GuidedNavigationViewModel#getLowerBound
*/
self.getLowerBound = function(value) {
var lowerBoundKey = "dimval.prop.lowerBound";
if (value && value.properties && value.properties[lowerBoundKey]) {
return value.properties[lowerBoundKey];
}
return null;
};
/**
* Get the upper bound value of the range.
* @function GuidedNavigationViewModel#getUpperBound
*/
self.getUpperBound = function(value) {
var upperBoundKey = "dimval.prop.upperBound";
if (value && value.properties && value.properties[upperBoundKey]) {
return this.correctUpperBound(value.properties[upperBoundKey]);
}
return null;
};
/**
* Correct the upper bound value of the range.
* @function GuidedNavigationViewModel#correctUpperBound
*/
self.correctUpperBound = function(value) {
var subtractionAmount = 1;
for (var i = 0; i < SiteViewModel.getInstance().selectedPriceListGroup().currency.fractionalDigits; i++) {
subtractionAmount *= 0.1;
}
subtractionAmount = subtractionAmount.toFixed(SiteViewModel.getInstance().selectedPriceListGroup().currency.fractionalDigits);
return value - subtractionAmount;
};
/**
* Get the text from the range if the range is an unbound range.
* @function GuidedNavigationViewModel#correctUpperBound
*/
self.getUpperBoundText = function(value) {
if (value.label) {
return value.label.substr(value.label.indexOf(' '));
}
return null;
};
}
/**
* Creates a Dimension.
*
* @private
* @class Dimension
* @memberof GuidedNavigationViewModel
* @param {Object} refinementMenu Provides the details of the dimension.
* @param {integer} maxRefinementCount The maximum refinement count.
* @property {string} dimensionName Name of the dimension.
* @property {observable<boolean>} isExpanded=false Is the dimension expanded?
* @property {observable<boolean>} shouldDimensionExpand=false Should the dimension expand?
* @property {string} displayName Display name associated with the current dimension.
* @property {Object[]} refinements The refinements for the dimension.
* @property {Object[]} ancestors The list of ancestors.
*/
function Dimension(refinementMenu, maxRefinementCount) {
var self = this;
self.dimensionName = refinementMenu.dimensionName;
self.isExpanded = ko.observable(false);
self.shouldDimensionExpand = ko.observable(false);
self.ariaLabelText = ko.observable('expandText');
self.displayName = refinementMenu.displayName;
if (self.displayName === "Category") {
self.displayName = CCi18n.t('ns.common:resources.categoryText');
} else if (self.displayName === "Price Range") {
self.displayName = CCi18n.t('ns.common:resources.priceRangeText');
}
self.refinements = GuidedNavigationViewModel.prototype.refinementList(refinementMenu.refinements, maxRefinementCount, self.dimensionName, refinementMenu.multiSelect);
self.ancestors = refinementMenu.ancestors;
if (refinementMenu.shouldMultiSelectDimensionExpand) {
self.shouldDimensionExpand(true);
self.isExpanded(true);
}
}
var Search = SearchViewModel.getInstance();
GuidedNavigationViewModel.prototype.isSpinnerStarted = ko.observable('false');
GuidedNavigationViewModel.prototype.locale = ko.observable('');
GuidedNavigationViewModel.prototype.searchResultsHash = '';
GuidedNavigationViewModel.prototype.refinementIndicatorOptions = {
parent : '#loadingModal',
};
/**
* Removes 'loading' spinner.
* @function GuidedNavigationViewModel#destroySpinner
*/
GuidedNavigationViewModel.prototype.destroySpinner = function() {
$('#loadingModal').hide();
spinner.destroy();
};
/**
* Creates 'loading' spinner.
* @function GuidedNavigationViewModel#createSpinner
*/
GuidedNavigationViewModel.prototype.createSpinner = function() {
$('#loadingModal').removeClass('hide');
$('#loadingModal').show();
GuidedNavigationViewModel.prototype.isSpinnerStarted('true');
if (($(window)[0].innerWidth || $(window).width()) < CCConstants.VIEWPORT_TABLET_LOWER_WIDTH) {
GuidedNavigationViewModel.prototype.refinementIndicatorOptions.posLeft = "40%";
GuidedNavigationViewModel.prototype.refinementIndicatorOptions.posTop = "80px";
} else if (($(window)[0].innerWidth || $(window).width()) < CCConstants.VIEWPORT_LARGE_DESKTOP_LOWER_WIDTH) {
GuidedNavigationViewModel.prototype.refinementIndicatorOptions.posLeft = "45%";
GuidedNavigationViewModel.prototype.refinementIndicatorOptions.posTop = "100px";
} else {
GuidedNavigationViewModel.prototype.refinementIndicatorOptions.posLeft = "50%";
GuidedNavigationViewModel.prototype.refinementIndicatorOptions.posTop = "150px";
}
spinner.create(GuidedNavigationViewModel.prototype.refinementIndicatorOptions);
};
/**
* Handle view model changes when the search result is updated
* Populates the dimensions property with nested refinements collapsible lists.
* @function GuidedNavigationViewModel#updateWithSearchResultsData
* @param {Object} obj The calling object.
* @param {SearchResultDetails} data The search result data.
* @param {GuidedNavigationViewModel} self The view model instance.
*/
GuidedNavigationViewModel.prototype.updateWithSearchResultsData = function(obj, data, self) {
var refinementCrumbs = [];
if (data && data.breadcrumbs && data.breadcrumbs.refinementCrumbs) {
refinementCrumbs = data.breadcrumbs.refinementCrumbs.slice(0);
for (var i = 0; i < refinementCrumbs.length ; i++ ) {
if (refinementCrumbs[i].multiSelect == true && refinementCrumbs[i].count > 0) {
var found = false;
for (var j = 0; j < data.navigation.length; j++ ) {
if (data.navigation[j].dimensionName == refinementCrumbs[i].dimensionName) {
data.navigation[j].shouldMultiSelectDimensionExpand = true;
refinementCrumbs[i].isSelected = true;
found = true;
if (data.navigation[j].refinements && data.navigation[j].refinements instanceof Array) {
data.navigation[j].refinements.push(refinementCrumbs[i]);
}
break;
}
}
// Creating a new dimension and adding the multi select refinement to it.
if (found == false ) {
refinementCrumbs[i].isSelected = true;
var navigation_data = {
multiSelect: true,
name: refinementCrumbs[i].name,
ancestors: [],
shouldMultiSelectDimensionExpand: true,
displayName: refinementCrumbs[i].displayName,
dimensionName: refinementCrumbs[i].dimensionName,
refinements: [ refinementCrumbs[i] ]
};
data.navigation.push(navigation_data);
}
}
if (self.searchText() === "") {
// Sends category crumb to display as titleText in product listing page.
if (refinementCrumbs[i].dimensionName == CCConstants.GUIDED_NAVIGATION_CATEGORY) {
$.Topic(pubsub.topicNames.CATEGORY_CRUMB_UPDATED).publish(self.convertLabel(refinementCrumbs[i]));
}
}
}
// Removing the default refinementCrumb (first) when category is selected from allRefinementCrumbs.
if (self.searchText() === "" && (refinementCrumbs.length > 0 && refinementCrumbs[0].dimensionName === CCConstants.GUIDED_NAVIGATION_CATEGORY &&
refinementCrumbs[0].properties && self.categoryRepositoryId() === refinementCrumbs[0].properties["dimval.prop.category.repositoryId"] )) {
self.allRefinementCrumbs(refinementCrumbs.slice(1));
} else {
self.allRefinementCrumbs(refinementCrumbs.slice(0));
}
}
if (data.searchAdjustments && data.searchAdjustments.originalTerms && data.searchAdjustments.originalTerms.length > 0) {
self.searchText(data.searchAdjustments.originalSearchTerms[0]);
}
if ((obj.message === CCConstants.SEARCH_MESSAGE_FAIL) || !((data.navigation && data.navigation.length > 0) || (refinementCrumbs.length > 0))) {
self.displayWidget(false);
} else {
var categoryListIndex = -1;
self.dimensions(ko.utils.arrayMap(data.navigation, function(refinementMenu) {
return new Dimension(refinementMenu, self.maxRefinementCount);
}), self.maxDimensionCount);
//Check if category refinement list exists in the dimensions list
$.each(self.dimensions(), function(index, value) {
if (value.dimensionName === CCConstants.GUIDED_NAVIGATION_CATEGORY) {
categoryListIndex= index;
}
});
//Place the category refinement list at the beginning of dimension list
if (categoryListIndex != -1) {
self.dimensions.unshift(self.dimensions.splice(categoryListIndex, 1)[0]);
}
self.dimensions.showAll(false);
self.displayWidget(true);
}
};
/**
* Initializes the dimensions property via topic.
* Subscribes to the needed topic and loads the view model data.
* @function GuidedNavigationViewModel#initialize
*/
GuidedNavigationViewModel.prototype.initialize = function() {
var self = this;
$.Topic(pubsub.topicNames.SEARCH_RESULTS_UPDATED).subscribe(function(obj) {
var data = this;
GuidedNavigationViewModel.prototype.updateWithSearchResultsData(obj, data, self);
GuidedNavigationViewModel.prototype.checkSpinner();
});
$.Topic(pubsub.topicNames.SEARCH_RESULTS_FOR_CATEGORY_UPDATED).subscribe(function(obj) {
var data = this;
GuidedNavigationViewModel.prototype.updateWithSearchResultsData(obj, data, self);
GuidedNavigationViewModel.prototype.checkSpinner();
});
$.Topic(pubsub.topicNames.CATEGORY_UPDATED).subscribe(function(data) {
self.categoryHref(data.categoryRoute);
self.categoryName(data.categoryName);
self.categoryDimensionId(data.dimensionId);
self.categoryRepositoryId(data.repositoryId);
self.searchText('');
});
// On Refresh load the category data from cookie
if (!self.searchText() && !self.categoryName()) {
self.loadCategoryFromLocalData();
}
};
/**
* Loads the category data from local storage ( To avoid problems with refresh.)
* @function GuidedNavigationViewModel#loadCategoryFromLocalData
*
*/
GuidedNavigationViewModel.prototype.loadCategoryFromLocalData = function() {
var self = this;
// load the data from local storage ( To avoid problems with refresh.)
var localData = null;
localData = storageApi.getInstance().getItem("category");
if (localData && typeof localData === 'string') {
localData = JSON.parse(localData);
}
if (localData != null) {
self.categoryHref(localData.categoryRoute);
self.categoryName(localData.categoryName);
self.categoryRepositoryId(localData.repositoryId);
self.categoryDimensionId(localData.dimensionId);
}
};
/**
* Converts Label to its locale specific name.
* @function GuidedNavigationViewModel#convertLabel
*/
GuidedNavigationViewModel.prototype.convertLabel = function(value) {
var label = value.label;
var a = "dimval.prop.displayName_"+GuidedNavigationViewModel.prototype.locale();
if ( value && value.properties && value.properties[a] ) {
label = value.properties[a];
}
return label;
};
/**
* Destroys spinner if it is started already.
* @function GuidedNavigationViewModel#checkSpinner
*/
GuidedNavigationViewModel.prototype.checkSpinner = function() {
if (GuidedNavigationViewModel.prototype.isSpinnerStarted()) {
GuidedNavigationViewModel.prototype.destroySpinner();
}
GuidedNavigationViewModel.prototype.isSpinnerStarted('false');
};
/**
* Creates a wrapper object over the observable with the needed parentRefinements/flags/subscriptions
* It internally uses the collapsibleList method.
* @function GuidedNavigationViewModel#refinementList
* @param {Object[]} initialList Initial list of refinements.
* @param {integer} limit The maximum number of refinements to be displayed.
* @param {string} dimensionName The name of the dimension,
* either CCConstants.GUIDED_NAVIGATION_CATEGORY or CCConstants.GUIDED_NAVIGATION_PRICERANGE
* @param {boolean} multiSelect Allow multiple selections?
* @return {observable} The refinement list wrapper object.
*/
GuidedNavigationViewModel.prototype.refinementList = function(initialList, limit, dimensionName, multiSelect) {
var self = this;
$.each(initialList, function(index, value) {
value.label = self.convertLabel(value);
value.refinementValue = CCi18n.t('ns.common:resources.refinementValueText',
{dataLabel: value.label, dataCount: value.count});
if (this.multiSelect == true) {
value.checkedValue = ko.observable(false);
// checked attribute is set when it is present in the breadcrumbs.
if (this.isSelected && this.isSelected == true) {
value.checkedValue(true);
}
value.checkedValue.subscribe(function(newValue) {
if (!newValue) {
this.navigationState = this.removeAction.navigationState;
}
GuidedNavigationViewModel.prototype.createSpinnerAndHandleRedirect(this.navigationState);
}, value);
}
else {
value.clickRefinement = function() {
GuidedNavigationViewModel.prototype.createSpinnerAndHandleRedirect(this.navigationState);
};
}
});
var observable = self.collapsibleList(initialList, limit);
if (dimensionName === CCConstants.GUIDED_NAVIGATION_CATEGORY) {
observable.sort(function(left, right) {
return left.label == right.label ? 0 : (left.label < right.label ? -1 : 1) ;
});
}
else if (dimensionName !== CCConstants.GUIDED_NAVIGATION_PRICERANGE) {
observable.sort(function(left, right) {
// If count is same, then sort by label
return left.count == right.count ? (left.label < right.label ? -1 : 1) : (left.count < right.count ? 1 : -1) ;
});
}
return observable;
};
/**
* Creates spinner and redirects to the navigationState.
* @function GuidedNavigationViewModel#createSpinnerAndHandleRedirect
* @param {string} navigationState The navigation state.
*/
GuidedNavigationViewModel.prototype.createSpinnerAndHandleRedirect = function(navigationState) {
var self = this;
GuidedNavigationViewModel.prototype.createSpinner();
navigation.goTo(self.searchResultsHash + Search.getFilteredNavState(navigationState) + "&"
+ CCConstants.SEARCH_TYPE + "=" + CCConstants.SEARCH_TYPE_GUIDED + "&"
+ CCConstants.PARAMETERS_TYPE + "=" + CCConstants.PARAMETERS_SEARCH_QUERY);
}
/**
* Create a list which collapses to a limited size.
* Creates a wrapper observable object over the observable with the needed flags/subscriptions.
* <p>
* Adds a 'display' property to the wrapper, which returns a subset of the list, up to the limit
* specified.
* @function GuidedNavigationViewModel#collapsibleList
* @param {Object[]} initialList The initial list.
* @param {integer} limit The max size of the list.
* @return {observable} The observable wrapper object.
*/
GuidedNavigationViewModel.prototype.collapsibleList = function(initialList, limit) {
var self = this;
var observable = ko.observableArray(initialList);
observable.limit = ko.observable(limit);
observable.showAll = ko.observable(false);
observable.toggleShowAll = function() {
observable.showAll(!observable.showAll());
};
observable.display = ko.computed(function() {
if (observable.showAll()) {
return observable();
}
return observable().slice(0,observable.limit());
}, observable);
return observable;
};
return GuidedNavigationViewModel;
}
);
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-ccKoErrorWrapper.html">ccKoErrorWrapper</a></li><li><a href="module-ccKoExtensions.html">ccKoExtensions</a></li></ul><h3>Classes</h3><ul><li><a href="Address.html">Address</a></li><li><a href="CartViewModel.html">CartViewModel</a></li><li><a href="DynamicProperty.html">DynamicProperty</a></li><li><a href="EventDispatcher.html">EventDispatcher</a></li><li><a href="GiftCardViewModel.html">GiftCardViewModel</a></li><li><a href="GiftProductListingViewModel.html">GiftProductListingViewModel</a></li><li><a href="ko.bindingHandlers.background.html">background</a></li><li><a href="ko.bindingHandlers.carouselSwipe.html">carouselSwipe</a></li><li><a href="ko.bindingHandlers.ccForm.html">ccForm</a></li><li><a href="ko.bindingHandlers.ccLink.html">ccLink</a></li><li><a href="ko.bindingHandlers.ccValidation.html">ccValidation</a></li><li><a href="ko.bindingHandlers.checkbox.html">checkbox</a></li><li><a href="ko.bindingHandlers.chosen.html">chosen</a></li><li><a href="ko.bindingHandlers.contextResourcesNamespace.html">contextResourcesNamespace</a></li><li><a href="ko.bindingHandlers.currency.html">currency</a></li><li><a href="ko.bindingHandlers.datepicker.html">datepicker</a></li><li><a href="ko.bindingHandlers.datepopover.html">datepopover</a></li><li><a href="ko.bindingHandlers.draggable.html">draggable</a></li><li><a href="ko.bindingHandlers.droppable.html">droppable</a></li><li><a href="ko.bindingHandlers.fade.html">fade</a></li><li><a href="ko.bindingHandlers.hover.html">hover</a></li><li><a href="ko.bindingHandlers.imageSource.html">imageSource</a></li><li><a href="ko.bindingHandlers.imageZoom.html">imageZoom</a></li><li><a href="ko.bindingHandlers.localeText.html">localeText</a></li><li><a href="ko.bindingHandlers.makeAccess.html">makeAccess</a></li><li><a href="ko.bindingHandlers.modal.html">modal</a></li><li><a href="ko.bindingHandlers.modalTabbingContraint.html">modalTabbingContraint</a></li><li><a href="ko.bindingHandlers.onRender.html">onRender</a></li><li><a href="ko.bindingHandlers.popeditor.html">popeditor</a></li><li><a href="ko.bindingHandlers.popover.html">popover</a></li><li><a href="ko.bindingHandlers.productImageSource.html">productImageSource</a></li><li><a href="ko.bindingHandlers.propertyEditor.html">propertyEditor</a></li><li><a href="ko.bindingHandlers.radio.html">radio</a></li><li><a href="ko.bindingHandlers.richTextEditor.html">richTextEditor</a></li><li><a href="ko.bindingHandlers.scrollAffix.html">scrollAffix</a></li><li><a href="ko.bindingHandlers.select2.html">select2</a></li><li><a href="ko.bindingHandlers.select2Tags.html">select2Tags</a></li><li><a href="ko.bindingHandlers.selectable.html">selectable</a></li><li><a href="ko.bindingHandlers.slickList.html">slickList</a></li><li><a href="ko.bindingHandlers.slide.html">slide</a></li><li><a href="ko.bindingHandlers.slider.html">slider</a></li><li><a href="ko.bindingHandlers.spectrum.html">spectrum</a></li><li><a href="ko.bindingHandlers.tagsInput.html">tagsInput</a></li><li><a href="ko.bindingHandlers.textCheck.html">textCheck</a></li><li><a href="ko.bindingHandlers.timepicker.html">timepicker</a></li><li><a href="ko.bindingHandlers.triggerMessage.html">triggerMessage</a></li><li><a href="ko.bindingHandlers.validatableTarget.html">validatableTarget</a></li><li><a href="ko.bindingHandlers.validatableValue.html">validatableValue</a></li><li><a href="ko.bindingHandlers.widgetLocaleText.html">widgetLocaleText</a></li><li><a href="koValidation.alphaNumeric.html">alphaNumeric</a></li><li><a href="koValidation.alphaNumericNoSpaces.html">alphaNumericNoSpaces</a></li><li><a href="koValidation.alphaNumericNoSpacesWithSeperators.html">alphaNumericNoSpacesWithSeperators</a></li><li><a href="koValidation.alphaNumericWithSeperators.html">alphaNumericWithSeperators</a></li><li><a href="koValidation.bool.html">bool</a></li><li><a href="koValidation.creditcard.html">creditcard</a></li><li><a href="koValidation.cvv.html">cvv</a></li><li><a href="koValidation.endmonth.html">endmonth</a></li><li><a href="koValidation.endyear.html">endyear</a></li><li><a href="koValidation.importFileName.html">importFileName</a></li><li><a href="koValidation.laterDate.html">laterDate</a></li><li><a href="koValidation.match.html">match</a></li><li><a href="koValidation.mediaZipFileName.html">mediaZipFileName</a></li><li><a href="koValidation.number.html">number</a></li><li><a href="koValidation.observablePattern.html">observablePattern</a></li><li><a href="koValidation.password.html">password</a></li><li><a href="koValidation.price.html">price</a></li><li><a href="koValidation.propertyIdAlreadyInUse.html">propertyIdAlreadyInUse</a></li><li><a href="koValidation.propertyNameAlreadyInUse.html">propertyNameAlreadyInUse</a></li><li><a href="koValidation.restrictSlashCharacters.html">restrictSlashCharacters</a></li><li><a href="koValidation.startmonth.html">startmonth</a></li><li><a href="koValidation.startyear.html">startyear</a></li><li><a href="koValidation.uniqueTrimmed.html">uniqueTrimmed</a></li><li><a href="koValidation.uniqueTrimmedCaseInsensitive.html">uniqueTrimmedCaseInsensitive</a></li><li><a href="koValidation.url.html">url</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.addTemplate.html">addTemplate</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.ccDate.html">ccDate</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.ccDateTime.html">ccDateTime</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.ccNumber.html">ccNumber</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.disabled.html">disabled</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.element.html">element</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.embeddedAssistance.html">embeddedAssistance</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.inTabFlow.html">inTabFlow</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.setContextVariable.html">setContextVariable</a></li><li><a href="NavStateViewModel.html">NavStateViewModel</a></li><li><a href="OrderHistoryViewModel.html">OrderHistoryViewModel</a></li><li><a href="OrderViewModel.html">OrderViewModel</a></li><li><a href="ParentOrganisation.html">ParentOrganisation</a></li><li><a href="ProductListingSearchViewModel.html">ProductListingSearchViewModel</a></li><li><a href="ProductListingViewModel.html">ProductListingViewModel</a></li><li><a href="ProductViewModel.html">ProductViewModel</a></li><li><a href="PubSub.topicNames.html">topicNames</a></li><li><a href="resetCVV.html">resetCVV</a></li><li><a href="resetPaymentDetails.html">resetPaymentDetails</a></li><li><a href="SearchRestClient.html">SearchRestClient</a></li><li><a href="UserViewModel.html">UserViewModel</a></li><li><a href="WidgetViewModel.html">WidgetViewModel</a></li><li><a href="WishlistContentViewModel.html">WishlistContentViewModel</a></li></ul><h3>Namespaces</h3><ul><li><a href="ko.bindingHandlers.html">bindingHandlers</a></li><li><a href="ko.extenders.html">extenders</a></li><li><a href="koValidation.html">koValidation</a></li></ul><h3>Global</h3><ul><li><a href="global.html#CCEETagProcessor">CCEETagProcessor</a></li><li><a href="global.html#isValidDeterminewhetherornotthepaymentdetailsobjectisvalidbasedonthevalidityofitscomponentparts.Thiswillnotcauseerrormessagestobedisplayedforanyobservablevaluesthatareunchangedandhaveneverreceivedfocusontherelatedformfield(s).">isValid
Determine whether or not the payment details object is valid
based on the validity of its component parts. This will not
cause error messages to be displayed for any observable values
that are unchanged and have never received focus on the
related form field(s).</a></li><li><a href="global.html#validatePaymentDetailsForceallrelevantmemberobservablestoperformtheirvalidationnow&displaytheerrors(ifany)">validatePaymentDetails
Force all relevant member observables to perform their
validation now & display the errors (if any)</a></li></ul>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0</a> on Mon Oct 10 2016 10:49:04 GMT+0100 (BST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>