PageSourceSearch

https://elizabethyarnell.net/wp-content/plugins/woffice-core/exten…/js/woffice-time-tracking.js?ver=7.1.2

js elizabethyarnell.net collected 2026-10-02 16:14:21 UTC 4,757 bytes, 164 lines download raw bytes

1/**
2 * Woffice Time Tracking JS
3 *
4 * @type {{wrapper: *, init: WofficeTimeTracking.init}}
5 */
6var WofficeTimeTracking = {
7
8    wrapper: null,
9    isClockActive: false,
10
11    /**
12     * Live time clock, increases every minute
13     */
14    liveClock: function() {
15
16        var self = this,
17            $clock = self.wrapper.find('.woffice-time-tracking-view > .woffice-time-tracking_time-displayed');
18
19        var timeString = $clock.html();
20
21        if (!timeString) {
22            return;
23        }
24
25        var timeArray  = timeString.split(':');
26        var t          = new Date();
27
28        t.setHours(timeArray[0]);
29        t.setMinutes(timeArray[1]);
30        t.setSeconds(timeArray[2]);
31
32        this.liveTime = setInterval(function () {
33            if (!self.isClockActive) {
34                return;
35            }
36
37            t.setSeconds(t.getSeconds() + 1);
38
39            var hours = t.getHours();
40            hours = (hours.toString().length === 1) ? '0' + hours.toString() : hours.toString();
41
42            var minutes = t.getMinutes();
43            minutes = (minutes.toString().length === 1) ? '0' + minutes.toString() : minutes.toString();
44
45            var seconds = t.getSeconds();
46            seconds = (seconds.toString().length === 1) ? '0' + seconds.toString() : seconds.toString();
47
48            $clock.html(hours +':'+ minutes +':'+ seconds);
49        }, 1000);
50
51    },
52
53    /**
54     * Switch between the timer and the history tab
55     */
56    switchTab: function () {
57
58        var self = this,
59            $toggle = self.wrapper.find('.woffice-time-tracking-history-toggle'),
60            $tabs = self.wrapper.find('.woffice-time-tracking-view'),
61            $icon = self.wrapper.find('.woffice-time-tracking-history-toggle i');
62
63        $toggle.toggleClass('is-history');
64
65        if ($toggle.hasClass('is-history')) {
66            $tabs.first().fadeOut();
67            $tabs.last().fadeIn();
68            $icon.removeClass('fa-history');
69            $icon.addClass('fa-times');
70        } else {
71            $tabs.first().fadeIn();
72            $tabs.last().fadeOut();
73            $icon.addClass('fa-history');
74            $icon.removeClass('fa-times');
75        }
76
77    },
78
79    /**
80     * Change the state: stop || start
81     *
82     * @param {Event} e
83     */
84    stateChange: function (e) {
85        var self = this,
86            $target = jQuery(e.target);
87
88        $target = (['a'].indexOf($target.get(0).tagName) !== -1) ? $target : $target.closest('a');
89
90        var action = $target.data('action');
91        var $btnStart = self.wrapper.find('.woffice-time-tracking-actions .woffice-time-tracking-state-toggle.start'),
92            $btnStop  = self.wrapper.find('.woffice-time-tracking-actions .woffice-time-tracking-state-toggle.stop');
93
94        if (action === 'modal') {
95            jQuery('#woffice-time-tracking-meta').modal('show');
96            return ;
97        }
98
99        if (action !== 'modal') {
100            self.isClockActive = !self.isClockActive;
101            self.wrapper.toggleClass('is-tracking');
102            self.wrapper.addClass('is-loading');
103
104            jQuery.post(WOFFICE_TIME_TRACKING.ajax_url, {
105                action: 'woffice_time_tracking',
106                _wpnonce: WOFFICE_TIME_TRACKING.time_tracking_nonce,
107                tracking_action: action,
108                tracking_meta: jQuery('input[name="woffice-time-tracking-meta"]').val()
109            }).done(function () {
110
111                if (action === 'start') {
112                    $btnStart.addClass('d-none');
113                    $btnStop.removeClass('d-none');
114                    jQuery('#woffice-time-tracking-meta').modal('hide');
115                }
116                else {
117                    $btnStop.addClass('d-none');
118                    $btnStart.removeClass('d-none');
119                }
120
121                self.wrapper.removeClass('is-loading');
122            });
123        }
124    },
125
126    /**
127     * Init the widget
128     */
129    init: function () {
130
131        var self = this;
132
133        self.wrapper = jQuery('.woffice-time-tracking');
134
135        self.wrapper.find('[data-toggle="popover"]').popover();
136
137        // If we are currently tracking
138        if(self.wrapper.hasClass('is-tracking')) {
139            self.isClockActive = true;
140        }
141
142        // Clock:
143        self.liveClock();
144
145        // Tracking state
146        jQuery('.woffice-time-tracking-state-toggle').on('click', function (e) {
147            e.preventDefault();
148            self.stateChange(e);
149        });
150
151        // Show history
152        self.wrapper.find('.woffice-time-tracking-history-toggle').on('click', function (e) {
153            e.preventDefault();
154            self.switchTab();
155        });
156
157    }
158
159};
160
161// Starts it!
162jQuery( document ).ready(function() {
163    WofficeTimeTracking.init();
164});

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.