+ lc = "abcdefghijklmnopqrstuvwxyz"
+ uc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ cc_lca = lc.charCodeAt 0
+ cc_lcz = lc.charCodeAt 25
+ cc_uca = uc.charCodeAt 0
+ cc_ucz = uc.charCodeAt 25
+ cc_0 = '0'.charCodeAt 0
+ cc_9 = '9'.charCodeAt 0
+ # takes an array of positive integers, and encodes it as a string
+ pickle = (a) ->
+ ret = ''
+ for i in a
+ cs = lc
+ r = ''
+ while i > 0 or r is ''
+ digit = i % cs.length
+ i -= digit
+ i /= cs.length
+ r = cs.charAt(digit) + r
+ cs = uc
+ ret += r
+ return ret
+ pickle_widgets = ->
+ ret = '0' # version of this encoding scheme
+ for id, w of widget_layer.all
+ if CSS_CLASS_TO_PICKLE_TYPE[w.css_class]?
+ ret += CSS_CLASS_TO_PICKLE_TYPE[w.css_class]
+ ret += pickle w.as_array()
+ return ret
+ save = ->
+ window.location.hash = pickle_widgets()
+ load = (str) ->
+ return if str.charAt(1) isnt '0'
+ wtype = null
+ args = []
+ ii = 0
+ load_1 = (next_type) ->
+ unless wtype?
+ if next_type?
+ wtype = next_type
+ return
+ w = PICKLE_TYPE_TO_WIDGET_CLASS[wtype]::from_array svg: svg, args
+ widget_layer.all[w.id] = w
+ wtype = next_type
+ args = []
+ ii = 0
+ for i in [2...str.length]
+ c = str.charCodeAt(i)
+ if cc_0 <= c <= cc_9
+ load_1 c - cc_0
+ else if cc_lca <= c <= cc_lcz
+ ii *= lc.length
+ ii += c - cc_lca
+ args.push ii
+ ii = 0
+ else if cc_uca <= c <= cc_ucz
+ ii *= lc.length
+ ii += c - cc_uca
+ load_1 null