| 19 | }; |
| 20 | |
| 21 | var serializer = function (replacer, cycleReplacer) { |
| 22 | var stack = [], keys = []; |
| 23 | |
| 24 | if (cycleReplacer == null) cycleReplacer = function (key, value) { |
| 25 | if (stack[0] === value) return "[Circular ~]"; |
| 26 | return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]" |
| 27 | }; |
| 28 | |
| 29 | return function (key, value) { |
| 30 | if (stack.length > 0) { |
| 31 | var thisPos = stack.indexOf(this); |
| 32 | ~thisPos ? stack.splice(thisPos + 1) : stack.push(this); |
| 33 | ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key); |
| 34 | if (~stack.indexOf(value)) value = cycleReplacer.call(this, key, value) |
| 35 | } |
| 36 | else stack.push(value); |
| 37 | |
| 38 | return replacer == null ? value : replacer.call(this, key, value) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | var newWidgetCanvas = function (w, h) { |
| 43 | var div = $('<div class="Field-remoteWidget" style="width:' + w + 'px; height:' + h + 'px;"><div class="Field-closebox">✕</div></div>')[0]; |