PageSourceSearch

https://theatre-news.com/Scripts/app/vm.competitions.js

js theatre-news.com collected 2026-10-02 18:41:28 UTC 4,453 bytes, 136 lines download raw bytes

1define('vm.competitions', ['config', 'jquery', 'ko', 'ds', 'history-manager', 'vm-factory', 'animation-helper'],
2     function (config, $, ko, ds, historyManager, vmFactory, animation) {
3
4         var pageNo = ko.observable(1),
5             totalResults = ko.observable(),
6
7             viewReady = ko.observable(),
8
9             lastOptions = null,
10
11             activeSearch = ko.observable(false),
12             freeText = ko.observable(),
13
14             competitions = ko.observableArray(),
15
16             //#region Paging Links
17             pageLinks = ko.observableArray(),
18             createPaging = function() {
19                 pageLinks(vmFactory.createPageVms(config.paging.pageSize, totalResults(), pageNo()));
20             },
21             changePage = function(pageVm) {
22
23                 var newPage = parseInt(pageVm.pageNo);
24                 var currentNo = pageNo();
25
26                 if (!isNaN(newPage) && currentNo == newPage)
27                     return;
28
29                 if (pageVm.isPrevious)
30                     newPage = parseFloat(currentNo) - 1;
31
32                 if (pageVm.isNext)
33                     newPage = parseFloat(currentNo) + 1;
34
35                 historyManager.pushKey('page', newPage);
36
37                 animation.scrollTo('#competitions', config.scrolling.offset, config.scrolling.duration);
38             },
39             //#endregion  
40
41             load = function() {
42                 var options = {
43                     page: pageNo()
44                 };
45
46                 if (freeText() && freeText() != '')
47                     options.freeText = freeText();
48
49                 // already showing this data
50                 if (JSON.stringify(lastOptions) == JSON.stringify(options)) {
51                     return false;
52                 }
53
54                 lastOptions = _.clone(options);
55
56                 return ds.competition.list(options)
57                     .done(function(response) {
58                         competitions(response.results);
59                         totalResults(response.totalCount);
60                         createPaging();
61                         viewReady(true);
62                     });
63             },
64
65
66             checkHashValue = function(e, hashKey, koObservable, defaultValue) {
67                 var hashValue = e.getState(hashKey);
68                 if (hashValue != koObservable) {
69                     if (hashValue)
70                         return hashValue;
71                     else
72                         return defaultValue;
73                 }
74
75                 return koObservable;
76             },
77
78             getPageFromHash = function(e) {
79                 var page = checkHashValue(e, 'page', pageNo(), 1);
80
81                 if (Math.ceil(parseFloat(totalResults() / config.paging.pageSize)) < page)
82                     historyManager.pushKey('page', 1);
83                 else
84                     pageNo(checkHashValue(e, 'page', pageNo(), 1));
85             },
86
87             getFreeTextFromHash = function (e) {
88                 freeText(checkHashValue(e, 'search', freeText(), ""));
89
90                 if (freeText() && freeText() != '')
91                     activeSearch(true);
92             },
93
94             hashChanged = function(e) {
95                 getPageFromHash(e);
96                 getFreeTextFromHash(e);
97
98                 load();
99             },
100
101             runSearch = function () {
102                 var state = historyManager.getState();
103
104                 delete state['page'];
105                 state['search'] = freeText();
106
107                 historyManager.pushState(state);
108             },
109
110            clearSearch = function () {
111                var state = historyManager.getState();
112                delete state['search'];
113                historyManager.pushState(state);
114
115                activeSearch(false);
116            };
117
118         var vm = {
119             viewReady: viewReady,
120
121             hashChanged: hashChanged,
122             competitions: competitions,
123             totalResults: totalResults,
124             pageNo: pageNo,
125
126             pageLinks: pageLinks,
127             changePage: changePage,
128
129             freeText: freeText,
130             activeSearch: activeSearch,
131             runSearch: runSearch,
132             clearSearch: clearSearch
133         };
134
135         return vm;
136     });

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.