1 | function appendDiv(){
|
2 | $('body').append('<div id="div"></div>');
|
3 | }
|
4 |
|
5 | function appendObject(){
|
6 | $('#div').append('<div id="domObject" data-attr="blank"></div>');
|
7 | }
|
8 |
|
9 | function appendInputs(){
|
10 | $('#div').append('<input type="text" id="input1" />');
|
11 | $('#div').append('<input type="text" id="input2" />');
|
12 | $('#div').append('<input type="text" id="input3" />');
|
13 | window.$inputA = $('#input1');
|
14 | window.$inputB = $('#input2');
|
15 | window.$inputC = $('#input3');
|
16 | window.inputA = $inputA[0];
|
17 | window.inputB = $inputB[0];
|
18 | window.inputC = $inputC[0];
|
19 | }
|
20 |
|
21 | function appendTextarea(){
|
22 | $('#div').append('<textarea id="textarea"></textarea>');
|
23 | window.$textarea = $('#textarea');
|
24 | window.textarea = $textarea[0];
|
25 | }
|
26 |
|
27 | function appendSelect(){
|
28 | $('#div').append('<select id="select"><option value=""></option><option value="valid">Valid</option><option value="valid2">Valid2</option></select>');
|
29 | window.$select = $('#select');
|
30 | window.select = $select[0];
|
31 | }
|
32 |
|
33 | function appendRadio(){
|
34 | $('#div').append('<div id="radio"><input type="radio" name="radio" value="radioA" id="radioA" /><input type="radio" name="radio" value="radioB" id="radioB" /><input type="radio" name="radio" value="radioC" id="radioC" /></div>');
|
35 | window.$radioFields = $('#radio');
|
36 | window.radioFields = $radioFields[0].children;
|
37 |
|
38 | $radioFields = $radioFields.children();
|
39 | $radioFields.each(function(){
|
40 | window['$'+this.id] = $(this);
|
41 | window[this.id] = this;
|
42 | });
|
43 |
|
44 | }
|
45 |
|
46 | function appendCheckbox(){
|
47 | $('#div').append('<div id="checkbox"><input type="checkbox" name="checkbox" value="checkboxA" id="checkboxA" /><input type="checkbox" name="checkbox" value="checkboxB" id="checkboxB" /><input type="checkbox" name="checkbox" value="checkboxC" id="checkboxC" /></div>');
|
48 | window.$checkboxFields = $('#checkbox');
|
49 | window.checkboxFields = $checkboxFields[0].children;
|
50 |
|
51 | $checkboxFields = $checkboxFields.children();
|
52 | $checkboxFields.each(function(){
|
53 | window['$'+this.id] = $(this);
|
54 | window[this.id] = this;
|
55 | });
|
56 |
|
57 | }
|
58 |
|
59 | function appendRegEls(){
|
60 | $('#div').append('<div id="reg"><h1 id="reg-h1">The following <span id="reg-h1-span">text is {{verb}}</span> big and ugly</h1></div>');
|
61 | $('#div').append('<div id="regTwo"><h1 id="regTwo-h1">The following <span id="regTwo-h1-span">text is {{verb}} {{nounOne}}</span> and {{nounTwo}}</h1></div>');
|
62 | $('#div').append('<div id="regThree"><h1 id="regThree-h1">The following <span id="regThree-h1-span">text should have this: {{word}}, {{word}}</span> twice</h1></div>');
|
63 | $('#div').append('<div id="regFour"><h1 id="regFour-h1">The following {{wordA}} <span id="regFour-h1-span">and {{wordB}}</span> replaced correctly</h1></div>');
|
64 | window.$regA = $('#reg');
|
65 | window.$regAH1 = $('#reg-h1');
|
66 | window.$regAH1Span = $('#reg-h1-span');
|
67 | window.$regB = $('#regTwo');
|
68 | window.$regBH1 = $('#regTwo-h1');
|
69 | window.$regBH1Span = $('#regTwo-h1-span');
|
70 | window.$regC = $('#regThree');
|
71 | window.$regCH1 = $('#regThree-h1');
|
72 | window.$regCH1Span = $('#regThree-h1-span');
|
73 | window.$regD = $('#regFour');
|
74 | window.$regDH1 = $('#regFour-h1');
|
75 | window.$regDH1Span = $('#regFour-h1-span');
|
76 | window.regA = $regA[0];
|
77 | window.regAH1 = $regAH1[0];
|
78 | window.regAH1Span = $regAH1Span[0];
|
79 | window.regB = $regB[0];
|
80 | window.regBH1 = $regBH1[0];
|
81 | window.regBH1Span = $regBH1Span[0];
|
82 | window.regC = $regC[0];
|
83 | window.regCH1 = $regCH1[0];
|
84 | window.regCH1Span = $regCH1Span[0];
|
85 | window.regD = $regD[0];
|
86 | window.regDH1 = $regDH1[0];
|
87 | window.regDH1Span = $regDH1Span[0];
|
88 | }
|
89 |
|
90 | function createObjects(){
|
91 | window.objectA = {
|
92 | prop1: "some string",
|
93 | prop2: "another string",
|
94 | prop3: 1,
|
95 | prop4: 2,
|
96 | prop5: function(){return "some function";},
|
97 | prop6: function(){return "another function";},
|
98 | };
|
99 |
|
100 | window.objectB = {
|
101 | prop1: "some string",
|
102 | prop2: "another string",
|
103 | prop3: 1,
|
104 | prop4: 2,
|
105 | prop5: function(){return "some function";},
|
106 | prop6: function(){return "another function";},
|
107 | };
|
108 |
|
109 | window.objectC = {
|
110 | prop1: "some string",
|
111 | prop2: "another string",
|
112 | prop3: 1,
|
113 | prop4: 2,
|
114 | prop5: function(){return "some function";},
|
115 | prop6: function(){return "another function";},
|
116 | };
|
117 | }
|
118 |
|
119 | function createArrays(){
|
120 | window.arrayA = [0,1,2,3,4,5,6,7,8,9];
|
121 | window.arrayB = [0,1,2,3,4,5,6,7,8,9];
|
122 | window.arrayC = [0,1,2,3,4,5,6,7,8,9];
|
123 | }
|
124 |
|
125 | function createFns(){
|
126 | window.fnA = function(){return true};
|
127 | window.fnB = function(){return true};
|
128 | window.fnC = function(){return true};
|
129 | }
|
130 |
|
131 |
|
132 | if (typeof window !== 'undefined') {
|
133 | var createEventEmitters = function(){
|
134 | window.eventEmitterA = regA;
|
135 | window.eventEmitterB = regB;
|
136 | window.eventEmitterC = regC;
|
137 | window.$eventEmitterA = $regA;
|
138 | window.$eventEmitterB = $regB;
|
139 | window.$eventEmitterC = $regC;
|
140 |
|
141 | HTMLElement.prototype.on = HTMLElement.prototype.addEventListener;
|
142 | HTMLElement.prototype.removeListener = HTMLElement.prototype.removeEventListener;
|
143 | HTMLElement.prototype.inheritedProp = 'someProp';
|
144 | HTMLElement.prototype.emit = function(eventName){
|
145 | var event = document.createEvent('Event');
|
146 | event.initEvent(eventName, true, false);
|
147 | this.dispatchEvent(event);
|
148 | };
|
149 |
|
150 | $eventEmitterA.customListener = $eventEmitterB.customListener = $eventEmitterC.customListener = $.fn.on
|
151 | $eventEmitterA.customEmitter = $eventEmitterB.customEmitter = $eventEmitterC.customEmitter = $.fn.trigger
|
152 | }
|
153 |
|
154 |
|
155 | var startSandbox = function(){
|
156 | appendDiv();
|
157 | appendObject();
|
158 | appendInputs();
|
159 | appendTextarea();
|
160 | appendSelect();
|
161 | appendRadio();
|
162 | appendCheckbox();
|
163 | appendRegEls();
|
164 | createObjects();
|
165 | createArrays();
|
166 | createFns();
|
167 | createEventEmitters();
|
168 | }
|
169 |
|
170 | var restartSandbox = function(){
|
171 | $('#div').remove();
|
172 | startSandbox();
|
173 | }
|
174 |
|
175 |
|
176 | } else {
|
177 | var createEventEmitters = function(){
|
178 | Events = require('events');
|
179 | window.eventEmitterA = new Events();
|
180 | window.eventEmitterB = new Events();
|
181 | window.eventEmitterC = new Events();
|
182 | window.$eventEmitterA = new Events();
|
183 | window.$eventEmitterB = new Events();
|
184 | window.$eventEmitterC = new Events();
|
185 |
|
186 | Events.prototype.inheritedProp = 'someProp';
|
187 | $eventEmitterA.customListener = $eventEmitterB.customListener = $eventEmitterC.customListener = Events.prototype.on
|
188 | $eventEmitterA.customEmitter = $eventEmitterB.customEmitter = $eventEmitterC.customEmitter = Events.prototype.emit
|
189 | }
|
190 |
|
191 |
|
192 | var startSandbox = function(){
|
193 | createObjects();
|
194 | createArrays();
|
195 | createFns();
|
196 | createEventEmitters();
|
197 | }
|
198 |
|
199 | var restartSandbox = function(){
|
200 | startSandbox();
|
201 | }
|
202 |
|
203 | module.exports = {startSandbox:startSandbox, restartSandbox:restartSandbox};
|
204 | }
|
205 |
|