PageSourceSearch

https://www.drinking-water-engineering-and-science.net/template_DWES_CoPublisher.js

js drinking-water-engineering-and-science.net collected 2026-10-04 20:46:38 UTC 15,862 bytes, 417 lines download raw bytes

1/*
2 *
3 */
4var CoPublisher = CoPublisher || {};
5CoPublisher.Helper = CoPublisher.Helper || {};
6CoPublisher.Helper.Color = CoPublisher.Helper.Color || (function($) {
7        'use strict';
8//privates
9
10        var _color;
11
12        var parseColorCode =function parseColor(color) {
13            var cleanedColor = $.trim(color);
14            var firstChar = cleanedColor.charAt(0);
15            var rgb = {red: 0, green: 0, blue: 0};
16
17            if(firstChar == '#')
18            {
19                var colorOfNumber = cleanedColor.substr(1,cleanedColor.length - 1);
20                var red, green, blue = 0;
21
22                if(colorOfNumber.length < 6)
23                {
24                    red = colorOfNumber.slice(0,1);
25                    red.concat(red);
26
27                    green = colorOfNumber.slice(1,2);
28                    green.concat(green);
29
30                    blue = colorOfNumber.slice(2,3);
31                    blue.concat(blue);
32
33                }
34                else
35                {
36                    red = colorOfNumber.slice(0,2);
37                    green = colorOfNumber.slice(2,4);
38                    blue = colorOfNumber.slice(4,6);
39                }
40                rgb.red = parseInt(red,16);
41                rgb.green = parseInt(green,16);
42                rgb.blue = parseInt(blue,16);
43            }
44            if(firstChar.toLowerCase() == 'r')
45            {
46                cleanedColor = cleanedColor.toLowerCase();
47                cleanedColor = cleanedColor.replace(/rgb/gi, "");
48                cleanedColor = cleanedColor.replace(/\(/gi, "");
49                cleanedColor = cleanedColor.replace(/\)/gi, "");
50
51                var colorArray = cleanedColor.split(",");
52
53                if(colorArray[0] != undefined)
54                    rgb.red = parseInt($.trim(colorArray[0]),10);
55                if(colorArray[1] != undefined)
56                    rgb.green = parseInt($.trim(colorArray[1]),10);
57                if(colorArray[2] != undefined)
58                    rgb.blue = parseInt($.trim(colorArray[2]),10);
59                console.log("it's a rgb color ");
60                console.log(rgb);
61            }
62
63            if(firstChar.toLowerCase() == 'h')
64                throw "Only hex and rgb color support";
65
66            return rgb;
67        }
68        var lightColorCode = function lightenColor(percentage) {
69
70            percentage = (percentage/100);
71
72            var rgb = parseColorCode(_color);
73            rgb.red = Math.round(rgb.red * (1 - percentage));
74            rgb.green = Math.round(rgb.green * (1 - percentage));
75            rgb.blue = Math.round(rgb.blue * (1 - percentage));
76
77            return rgb;
78        };
79
80//public interface
81        return {
82            init: function(htmlColorCode) {
83                _color = htmlColorCode;
84            },
85            lighten: function(percentage){
86                var rgb = lightColorCode(percentage);
87                return "rgb("+rgb.red+","+rgb.green+","+rgb.blue+")";
88            }
89        };
90
91    }) (jQuery);
92CoPublisher.JournalMetrics = CoPublisher.JournalMetrics || {};
93CoPublisher.JournalMetrics.Model = CoPublisher.JournalMetrics.Model || (function() {
94
95        'use strict';
96
97        //privates
98        var _monthAsString = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct", "Nov", "Dec"];
99        var _categories;
100        var _series;
101        var _windowWidth;
102        var _max;
103
104        var calculateMaxNumberOfBars = function calculateMaxNumberOfBars() {
105            //console.log("sWidth "+window.innerWidth);
106            var width = _windowWidth || window.innerWidth;
107            return width < 1024 ? 8 : 9;
108        };
109
110        var amountOfElementsToStockUp = function calculateAmountOfElementsToStockUp(categoriesLength){
111
112            if(categoriesLength < _max)
113            {
114                var currentMonthCount = categoriesLength;
115                return _max - currentMonthCount;
116            }
117
118            return 0;
119        };
120
121        var calculateDateToStart = function calculateDateToStart(categoriesLength){
122
123            var now = new Date(Date.now());
124            var thisMonthAsString = now.getFullYear()+ ' ' + _monthAsString[now.getMonth()];
125            var lastDate = categoriesLength > 0 ? _categories[categoriesLength-1] : thisMonthAsString;
126
127            var splitedDate = lastDate.split(' ',2);
128            return new Date(splitedDate[0]+" 01, "+splitedDate[1]);
129
130        };
131
132        var generateData = function generateSeriesAndCategories(last,maxRuns) {
133            var newElement;
134
135            for(var index = 1; index <= maxRuns ; index ++) {
136
137                last.setMonth(last.getMonth() + 1);
138                //console.log(index);
139                newElement = _monthAsString[last.getMonth()]+" "+last.getFullYear();
140                _categories.push(newElement);
141                _series[0]['data'].push(0);
142                _series[1]['data'].push(0);
143                _series[2]['data'].push(0);
144            }
145        };
146
147        //public interface
148        return {
149            init: function(categories,series,windowWidth) {
150                _categories = categories;
151                _series = series;
152                _windowWidth = windowWidth;
153                _max = calculateMaxNumberOfBars();
154                var categoriesLength = _categories.length;
155
156                var numberOfElementsToStockUp = amountOfElementsToStockUp(categoriesLength);
157                var last = calculateDateToStart(categoriesLength);
158                generateData(last,numberOfElementsToStockUp);
159
160            },
161            getSeries: function() {
162                return _series;
163            },
164            getCategories: function() {
165                return _categories;
166            },
167            getXAxisMin: function() {
168                return _categories.length - _max;
169            },
170            getXAxisMax: function() {
171                return _categories.length - 1;
172            }
173        };
174
175    })();
176
177CoPublisher.JournalMetrics.View = CoPublisher.JournalMetrics.View || (
178        function ($) {
179
180            'use strict';
181
182            var _chartSelector;
183            var _viewModel;
184            var _default = {
185                mainColor: '#606060',
186                borderColor: '#DEDEDE',
187                local: 'en-GB'
188            };
189            var _settings;
190
191            var renderHighChart = function renderJournalMetricBarChart() {
192
193                var highChartInit = function() {
194                    //console.log('load highchart');
195                    var chart = this, counter = 0;
196
197                    $.each(chart.legend.allItems, function(i, item){
198                        var $check = $(item.checkbox),
199                            left = parseFloat($check.css('left')),
200                            label = item.legendItem,
201                            parentID = $check.parent().attr('id'),
202                            checkBoxID = parentID+'--category-selector-'+counter;
203
204                        $check.css({
205                            left: (left - item.checkboxOffset + 18 ) + 'px'
206                        }).attr('checked','checked').attr('id',checkBoxID);
207
208                        $('<label/>')
209                            .attr('for',checkBoxID)
210                            .css('position',$check.css('position'))
211                            .css('width','16')
212                            .css('height',$check.css('height'))
213                            .css('left',$check.css('left'))
214                            .css('top',$check.css('top'))
215                            .addClass('checked')
216                            .insertBefore( $check )
217                            .on( "click", function() {
218
219                                var labelID = $(this).attr('for'),
220                                                res = labelID.split("--"),
221                                                parentId = res[0],
222                                                elem = res[1].split('-'),
223                                                childNum = parseInt(elem[elem.length-1], 10),
224                                                rectSelector = '#'+parentId+' .highcharts-legend-item rect'; 
225
226                                $(rectSelector).each(function(index, item){
227
228                                    if(index == childNum)
229                                    {
230                                        console.log('trigger click on rest '+index);
231                                        $(item).trigger('click');
232
233                                        return false;
234                                    }
235
236                                });
237
238                        } );
239
240                        counter++;
241                    });
242                };
243
244                var toLocalString = function (number) {
245
246                    if(typeof number === 'number' && typeof number.toLocaleStr
246ing === "function" )
247                        return number.toLocaleString(_settings.local);
248
249                    return number;
250                };
251
252                var legendItemClickedActions = function(event) {
253                    var clickedCheckBox = event.currentTarget.checkbox;
254                    var checkedCurrent = !$(clickedCheckBox).prop('checked');
255
256                    $(clickedCheckBox).prop('checked', checkedCurrent);
257
258                    var $fakeCheckBox = $(event.currentTarget.checkbox).prev();
259
260                    var isChecked = $fakeCheckBox.hasClass('checked');
261
262                    if(isChecked)
263                        $fakeCheckBox.removeClass('checked');
264                    else
265                        $fakeCheckBox.addClass('checked');
266                };
267
268                $(_chartSelector).highcharts({
269                    credits: false,
270                    scrollbar: {
271                        enabled: true,
272                        barBackgroundColor: _settings.mainColor,
273                        barBorderRadius: 3,
274                        barBorderWidth: 0,
275                        barBorderColor: _settings.borderColor,
276                        buttonBackgroundColor: '#FFF',
277                        buttonBorderWidth: 0,
278                        buttonBorderRadius: 0,
279                        buttonArrowColor: _settings.mainColor,
280                        rifleColor: _settings.mainColor,
281                        trackBackgroundColor: 'none',
282                        trackBorderWidth: 0,
283                        trackBorderRadius: 0,
284                        trackBorderColor: '#fff'
285                    },
286                    chart: {
287                        type: 'column',
288                        marginBottom: 65,
289                        events: {
290                            load: highChartInit
291                        }
292                    },
293                    colors:    ['#69CD4B', '#DC5046', '#398CDA'],
294                    title: {
295                        text: ''
296                    },
297                    xAxis: {
298                        categories: _viewModel.getCategories(),
299                        min: _viewModel.getXAxisMin(),
300                        max: _viewModel.getXAxisMax()
301                    },
302                    yAxis: {
303                        min: 0,
304                        title: {
305                            text: ''
306                        },
307                        stackLabels: {
308                            enabled: true,
309                            style: {
310                                fontWeight: 'bold',
311                                color: _settings.mainColor
312                            },
313                            formatter: function() {
314                                if(this.total > 0)
315                                    return toLocalString(this.total);
316
317                                return null;
318                            }
319                        }
320                    },
321                    legend: {
322                        align: 'center',
323                        x: 0,
324                        verticalAlign: 'bottom',
325                        y: 10,
326                        floating: false,
327                        backgroundColor: 'white',
328                        borderColor: '#CCC',
329                        borderWidth: 1,
330                        shadow: false,
331                        itemStyle: {
332                            fontWeight: 'normal',
333                            color: _settings.mainColor
334                        },
335                        itemHiddenStyle: {
336                            color: _settings.mainColor
337                        }
338                    },
339                    tooltip: {
340                        borderRadius: 0,
341                        formatter: function() {
342                            return '<b>'+ this.x +'</b><br/>'+
343                                this.series.name +': '+ toLocalString(this.y) +'<br/>'+
344                                'Total: '+ toLocalString(this.point.stackTotal);
345                        }
346                    },
347                    plotOptions: {
348                        line: {
349                            animation: false
350                        },
351                        series: {
352                            showCheckbox:true,
353                            selected:true,
354                            animation: false,
355                            dataLabels:{
356                                enabled:true,
357                                color: 'white',
358                                formatter:function(){
359
360                                        return toLocalString(this.y);
361                                },
362                                style: {
363                                    textShadow: '1px 1px 1px #000'
364                                },
365                                overflow: false,
366                                inside: true
367                            },
368                            events: {
369                                legendItemClick: legendItemClickedActions
370                            }
371                        },
372                        column: {
373                            animation: true,
374                            stacking: 'normal'
375                        }
376
377
378                    },
379                    series: _viewModel.getSeries()
380                });
381
382                /*
383                 Resize Arrow Dimension
384                 d = M 8 4 L 8 10 5 7 => M 9 2 L 9 12 3 7
385                 d = M 6 4 L 6 10 9 7 => M 5 2 L 5 12 11 7
386
387                 I'm to lazy to parse
388                 */
389                $('.highcharts-scrollbar > g > path').each(function(index, value){
390
391                    var dimension = $(value).attr('d');
392                    switch(dimension)
393                    {
394                        case 'M 8 4 L 8 10 5 7':
395                            $(value).attr('d','M 9 2 L 9 12 3 7');
396                            break;
397                        case 'M 6 4 L 6 10 9 7':
398                            $(value).attr('d','M 5 2 L 5 12 11 7');
399                            break;
400                    }
401                });
402
403            };
404
405
406//public interface
407            return {
408                init: function(chartContainer,model,config) {
409                    _chartSelector = chartContainer;
410                    _viewModel = model;
411                    _settings = $.extend({}, _default, config);
412                },
413                render: function(){
414                    renderHighChart();
415                }
416            };
417        }) (jQuery);//import

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.