PageSourceSearch

https://www.springerpub.com/static/version1789146322/base/Magento/…/js/lib/knockout/bindings/simple-checked.js

js springerpub.com collected 2026-09-24 08:47:42 UTC 2,138 bytes, 77 lines download raw bytes

1/**
2 * Copyright © Magento, Inc. All rights reserved.
3 * See COPYING.txt for license details.
4 */
5define([
6    'ko',
7    '../template/renderer'
8], function (ko, renderer) {
9    'use strict';
10
11    ko.bindingHandlers.simpleChecked = {
12        'after': ['attr'],
13
14        /**
15         * Implements same functionality as a standard 'simpleChecked' binding,
16         * but with a difference that it wont' change values array if
17         * value of DOM element changes.
18         */
19        init: function (element, valueAccessor) {
20            var isCheckbox = element.type === 'checkbox',
21                isRadio = element.type === 'radio',
22                updateView,
23                updateModel;
24
25            if (!isCheckbox && !isRadio) {
26                return;
27            }
28
29            /**
30             * Updates checked observable
31             */
32            updateModel = function () {
33                var  modelValue = ko.dependencyDetection.ignore(valueAccessor),
34                    isChecked = element.checked;
35
36                if (ko.computedContext.isInitial()) {
37                    return;
38                }
39
40                if (modelValue.peek() === isChecked) {
41                    return;
42                }
43
44                if (isRadio && !isChecked) {
45                    return;
46                }
47
48                modelValue(isChecked);
49            };
50
51            /**
52             * Updates checkbox state
53             */
54            updateView = function () {
55                var modelValue = ko.utils.unwrapObservable(valueAccessor());
56
57                element.checked = !!modelValue;
58            };
59
60            ko.utils.registerEventHandler(element, 'change', updateModel);
61
62            ko.computed(updateModel, null, {
63                disposeWhenNodeIsRemoved: element
64            });
65            ko.computed(updateView, null, {
66                disposeWhenNodeIsRemoved: element
67            });
68        }
69    };
70
71    ko.expressionRewriting._twoWayBindings.simpleChecked = true;
72
73    renderer.addAttribute('simpleChecked');
74    renderer.addAttribute('simple-checked', {
75        binding: 'simpleChecked'
76    });
77});

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.