~holger-seelig/cobweb.js/trunk

« back to all changes in this revision

Viewing changes to cobweb.js/cobweb/Execution/BindableStack.js

  • Committer: Holger Seelig
  • Date: 2017-08-22 04:53:24 UTC
  • Revision ID: holger.seelig@yahoo.de-20170822045324-4of4xxgt79669gbt
Switched to npm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: JavaScript; coding: utf-8; tab-width: 3; indent-tabs-mode: tab; c-basic-offset: 3 -*-
2
 
 *******************************************************************************
3
 
 *
4
 
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
 
 *
6
 
 * Copyright create3000, Scheffelstraße 31a, Leipzig, Germany 2011.
7
 
 *
8
 
 * All rights reserved. Holger Seelig <holger.seelig@yahoo.de>.
9
 
 *
10
 
 * The copyright notice above does not evidence any actual of intended
11
 
 * publication of such source code, and is an unpublished work by create3000.
12
 
 * This material contains CONFIDENTIAL INFORMATION that is the property of
13
 
 * create3000.
14
 
 *
15
 
 * No permission is granted to copy, distribute, or create derivative works from
16
 
 * the contents of this software, in whole or in part, without the prior written
17
 
 * permission of create3000.
18
 
 *
19
 
 * NON-MILITARY USE ONLY
20
 
 *
21
 
 * All create3000 software are effectively free software with a non-military use
22
 
 * restriction. It is free. Well commented source is provided. You may reuse the
23
 
 * source in any way you please with the exception anything that uses it must be
24
 
 * marked to indicate is contains 'non-military use only' components.
25
 
 *
26
 
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27
 
 *
28
 
 * Copyright 2015, 2016 Holger Seelig <holger.seelig@yahoo.de>.
29
 
 *
30
 
 * This file is part of the Cobweb Project.
31
 
 *
32
 
 * Cobweb is free software: you can redistribute it and/or modify it under the
33
 
 * terms of the GNU General Public License version 3 only, as published by the
34
 
 * Free Software Foundation.
35
 
 *
36
 
 * Cobweb is distributed in the hope that it will be useful, but WITHOUT ANY
37
 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
38
 
 * A PARTICULAR PURPOSE. See the GNU General Public License version 3 for more
39
 
 * details (a copy is included in the LICENSE file that accompanied this code).
40
 
 *
41
 
 * You should have received a copy of the GNU General Public License version 3
42
 
 * along with Cobweb.  If not, see <http://www.gnu.org/licenses/gpl.html> for a
43
 
 * copy of the GPLv3 License.
44
 
 *
45
 
 * For Silvio, Joy and Adi.
46
 
 *
47
 
 ******************************************************************************/
48
 
 
49
 
 
50
 
define ([
51
 
        "jquery",
52
 
        "cobweb/Basic/X3DBaseNode",
53
 
],
54
 
function ($, X3DBaseNode)
55
 
{
56
 
"use strict";
57
 
 
58
 
        function BindableStack (executionContext, layer, defaultNode)
59
 
        {
60
 
                X3DBaseNode .call (this, executionContext);
61
 
 
62
 
                this .layer = layer;
63
 
                this .array = [ defaultNode ];
64
 
        }
65
 
 
66
 
        BindableStack .prototype = $.extend (Object .create (X3DBaseNode .prototype),
67
 
        {
68
 
                constructor: BindableStack,
69
 
                getTypeName: function ()
70
 
                {
71
 
                        return "BindableStack";
72
 
                },
73
 
                getComponentName: function ()
74
 
                {
75
 
                        return "Cobweb";
76
 
                },
77
 
                getContainerField: function ()
78
 
                {
79
 
                        return "bindableStack";
80
 
                },
81
 
                get: function ()
82
 
                {
83
 
                        return this .array;
84
 
                },
85
 
                top: function ()
86
 
                {
87
 
                        return this .array [this .array .length - 1];
88
 
                },
89
 
                forcePush: function (node)
90
 
                {
91
 
                        node .isBound_  = true;
92
 
                        node .bindTime_ = this .getBrowser () .getCurrentTime ();
93
 
 
94
 
                        this .push (node);
95
 
                },
96
 
                push: function (node)
97
 
                {
98
 
                        if (this .array .length === 0)
99
 
                                return;
100
 
 
101
 
                        if (node === this .array [0])
102
 
                                return;
103
 
 
104
 
                        var top = this .top ();
105
 
 
106
 
                        if (node !== top)
107
 
                        {
108
 
                                this .pushOnTop (node);
109
 
 
110
 
                                if (top .isBound_ .getValue ())
111
 
                                {
112
 
                                        top .set_bind_ = false;
113
 
                                        top .isBound_  = false;
114
 
                                }
115
 
 
116
 
                                if (! node .isBound_ .getValue ())
117
 
                                {
118
 
                                        node .isBound_  = true;
119
 
                                        node .bindTime_ = this .getBrowser () .getCurrentTime ();
120
 
                                        node .transitionStart (top);
121
 
                                }
122
 
 
123
 
                                this .pushOnTop (node);
124
 
 
125
 
                                this .addNodeEvent ();
126
 
                        }
127
 
                },
128
 
                pushOnTop: function (node)
129
 
                {
130
 
                        var index = this .array .indexOf (node);
131
 
 
132
 
                        if (index > -1)
133
 
                                this .array .splice (index, 1);
134
 
 
135
 
                        this .array .push (node);
136
 
                },
137
 
                remove: function (node)
138
 
                {
139
 
                        if (node === this .array [0])
140
 
                                return;
141
 
 
142
 
                        // If on top, pop node.
143
 
 
144
 
                        var top = this .top ();
145
 
 
146
 
                        if (node === top)
147
 
                                return this .pop (node);
148
 
 
149
 
                        // Simply remove.
150
 
 
151
 
                        var index = this .array .indexOf (node);
152
 
 
153
 
                        if (index > -1)
154
 
                                this .array .splice (index, 1);
155
 
                },
156
 
                pop: function (node)
157
 
                {
158
 
                        if (node === this .array [0])
159
 
                                return;
160
 
 
161
 
                        var top = this .top ();
162
 
                        
163
 
                        if (node === top)
164
 
                        {
165
 
                                if (node .isBound_ .getValue ())
166
 
                                        node .isBound_ = false;
167
 
 
168
 
                                if (this .array .length === 0)
169
 
                                        return;
170
 
 
171
 
                                this .array .pop ();
172
 
 
173
 
                                top = this .top ();
174
 
 
175
 
                                if (! top .isBound_ .getValue ())
176
 
                                {
177
 
                                        top .set_bind_ = true;
178
 
                                        top .isBound_  = true;
179
 
                                        top .bindTime_ = this .getBrowser () .getCurrentTime ();
180
 
                                        top .transitionStart (node);
181
 
                                }
182
 
 
183
 
                                this .addNodeEvent ();
184
 
                        }
185
 
                },
186
 
        });
187
 
 
188
 
        return BindableStack;
189
 
});
 
 
b'\\ No newline at end of file'