all.js 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607
  1. /* ---- lib/Class.coffee ---- */
  2. (function() {
  3. var Class,
  4. slice = [].slice;
  5. Class = (function() {
  6. function Class() {}
  7. Class.prototype.trace = true;
  8. Class.prototype.log = function() {
  9. var args;
  10. args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
  11. if (!this.trace) {
  12. return;
  13. }
  14. if (typeof console === 'undefined') {
  15. return;
  16. }
  17. args.unshift("[" + this.constructor.name + "]");
  18. console.log.apply(console, args);
  19. return this;
  20. };
  21. Class.prototype.logStart = function() {
  22. var args, name;
  23. name = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
  24. if (!this.trace) {
  25. return;
  26. }
  27. this.logtimers || (this.logtimers = {});
  28. this.logtimers[name] = +(new Date);
  29. if (args.length > 0) {
  30. this.log.apply(this, ["" + name].concat(slice.call(args), ["(started)"]));
  31. }
  32. return this;
  33. };
  34. Class.prototype.logEnd = function() {
  35. var args, ms, name;
  36. name = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
  37. ms = +(new Date) - this.logtimers[name];
  38. this.log.apply(this, ["" + name].concat(slice.call(args), ["(Done in " + ms + "ms)"]));
  39. return this;
  40. };
  41. return Class;
  42. })();
  43. window.Class = Class;
  44. }).call(this);
  45. /* ---- lib/Promise.coffee ---- */
  46. (function() {
  47. var Promise,
  48. slice = [].slice;
  49. Promise = (function() {
  50. Promise.when = function() {
  51. var args, fn, i, len, num_uncompleted, promise, task, task_id, tasks;
  52. tasks = 1 <= arguments.length ? slice.call(arguments, 0) : [];
  53. num_uncompleted = tasks.length;
  54. args = new Array(num_uncompleted);
  55. promise = new Promise();
  56. fn = function(task_id) {
  57. return task.then(function() {
  58. args[task_id] = Array.prototype.slice.call(arguments);
  59. num_uncompleted--;
  60. if (num_uncompleted === 0) {
  61. return promise.complete.apply(promise, args);
  62. }
  63. });
  64. };
  65. for (task_id = i = 0, len = tasks.length; i < len; task_id = ++i) {
  66. task = tasks[task_id];
  67. fn(task_id);
  68. }
  69. return promise;
  70. };
  71. function Promise() {
  72. this.resolved = false;
  73. this.end_promise = null;
  74. this.result = null;
  75. this.callbacks = [];
  76. }
  77. Promise.prototype.resolve = function() {
  78. var back, callback, i, len, ref;
  79. if (this.resolved) {
  80. return false;
  81. }
  82. this.resolved = true;
  83. this.data = arguments;
  84. if (!arguments.length) {
  85. this.data = [true];
  86. }
  87. this.result = this.data[0];
  88. ref = this.callbacks;
  89. for (i = 0, len = ref.length; i < len; i++) {
  90. callback = ref[i];
  91. back = callback.apply(callback, this.data);
  92. }
  93. if (this.end_promise) {
  94. return this.end_promise.resolve(back);
  95. }
  96. };
  97. Promise.prototype.fail = function() {
  98. return this.resolve(false);
  99. };
  100. Promise.prototype.then = function(callback) {
  101. if (this.resolved === true) {
  102. callback.apply(callback, this.data);
  103. return;
  104. }
  105. this.callbacks.push(callback);
  106. return this.end_promise = new Promise();
  107. };
  108. return Promise;
  109. })();
  110. window.Promise = Promise;
  111. /*
  112. s = Date.now()
  113. log = (text) ->
  114. console.log Date.now()-s, Array.prototype.slice.call(arguments).join(", ")
  115. log "Started"
  116. cmd = (query) ->
  117. p = new Promise()
  118. setTimeout ( ->
  119. p.resolve query+" Result"
  120. ), 100
  121. return p
  122. back = cmd("SELECT * FROM message").then (res) ->
  123. log res
  124. return "Return from query"
  125. .then (res) ->
  126. log "Back then", res
  127. log "Query started", back
  128. */
  129. }).call(this);
  130. /* ---- lib/Prototypes.coffee ---- */
  131. (function() {
  132. String.prototype.startsWith = function(s) {
  133. return this.slice(0, s.length) === s;
  134. };
  135. String.prototype.endsWith = function(s) {
  136. return s === '' || this.slice(-s.length) === s;
  137. };
  138. String.prototype.repeat = function(count) {
  139. return new Array(count + 1).join(this);
  140. };
  141. window.isEmpty = function(obj) {
  142. var key;
  143. for (key in obj) {
  144. return false;
  145. }
  146. return true;
  147. };
  148. }).call(this);
  149. /* ---- lib/maquette.js ---- */
  150. (function (root, factory) {
  151. if (typeof define === 'function' && define.amd) {
  152. // AMD. Register as an anonymous module.
  153. define(['exports'], factory);
  154. } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
  155. // CommonJS
  156. factory(exports);
  157. } else {
  158. // Browser globals
  159. factory(root.maquette = {});
  160. }
  161. }(this, function (exports) {
  162. 'use strict';
  163. ;
  164. ;
  165. ;
  166. ;
  167. var NAMESPACE_W3 = 'http://www.w3.org/';
  168. var NAMESPACE_SVG = NAMESPACE_W3 + '2000/svg';
  169. var NAMESPACE_XLINK = NAMESPACE_W3 + '1999/xlink';
  170. // Utilities
  171. var emptyArray = [];
  172. var extend = function (base, overrides) {
  173. var result = {};
  174. Object.keys(base).forEach(function (key) {
  175. result[key] = base[key];
  176. });
  177. if (overrides) {
  178. Object.keys(overrides).forEach(function (key) {
  179. result[key] = overrides[key];
  180. });
  181. }
  182. return result;
  183. };
  184. // Hyperscript helper functions
  185. var same = function (vnode1, vnode2) {
  186. if (vnode1.vnodeSelector !== vnode2.vnodeSelector) {
  187. return false;
  188. }
  189. if (vnode1.properties && vnode2.properties) {
  190. if (vnode1.properties.key !== vnode2.properties.key) {
  191. return false;
  192. }
  193. return vnode1.properties.bind === vnode2.properties.bind;
  194. }
  195. return !vnode1.properties && !vnode2.properties;
  196. };
  197. var toTextVNode = function (data) {
  198. return {
  199. vnodeSelector: '',
  200. properties: undefined,
  201. children: undefined,
  202. text: data.toString(),
  203. domNode: null
  204. };
  205. };
  206. var appendChildren = function (parentSelector, insertions, main) {
  207. for (var i = 0; i < insertions.length; i++) {
  208. var item = insertions[i];
  209. if (Array.isArray(item)) {
  210. appendChildren(parentSelector, item, main);
  211. } else {
  212. if (item !== null && item !== undefined) {
  213. if (!item.hasOwnProperty('vnodeSelector')) {
  214. item = toTextVNode(item);
  215. }
  216. main.push(item);
  217. }
  218. }
  219. }
  220. };
  221. // Render helper functions
  222. var missingTransition = function () {
  223. throw new Error('Provide a transitions object to the projectionOptions to do animations');
  224. };
  225. var DEFAULT_PROJECTION_OPTIONS = {
  226. namespace: undefined,
  227. eventHandlerInterceptor: undefined,
  228. styleApplyer: function (domNode, styleName, value) {
  229. // Provides a hook to add vendor prefixes for browsers that still need it.
  230. domNode.style[styleName] = value;
  231. },
  232. transitions: {
  233. enter: missingTransition,
  234. exit: missingTransition
  235. }
  236. };
  237. var applyDefaultProjectionOptions = function (projectorOptions) {
  238. return extend(DEFAULT_PROJECTION_OPTIONS, projectorOptions);
  239. };
  240. var checkStyleValue = function (styleValue) {
  241. if (typeof styleValue !== 'string') {
  242. throw new Error('Style values must be strings');
  243. }
  244. };
  245. var setProperties = function (domNode, properties, projectionOptions) {
  246. if (!properties) {
  247. return;
  248. }
  249. var eventHandlerInterceptor = projectionOptions.eventHandlerInterceptor;
  250. var propNames = Object.keys(properties);
  251. var propCount = propNames.length;
  252. for (var i = 0; i < propCount; i++) {
  253. var propName = propNames[i];
  254. /* tslint:disable:no-var-keyword: edge case */
  255. var propValue = properties[propName];
  256. /* tslint:enable:no-var-keyword */
  257. if (propName === 'className') {
  258. throw new Error('Property "className" is not supported, use "class".');
  259. } else if (propName === 'class') {
  260. if (domNode.className) {
  261. // May happen if classes is specified before class
  262. domNode.className += ' ' + propValue;
  263. } else {
  264. domNode.className = propValue;
  265. }
  266. } else if (propName === 'classes') {
  267. // object with string keys and boolean values
  268. var classNames = Object.keys(propValue);
  269. var classNameCount = classNames.length;
  270. for (var j = 0; j < classNameCount; j++) {
  271. var className = classNames[j];
  272. if (propValue[className]) {
  273. domNode.classList.add(className);
  274. }
  275. }
  276. } else if (propName === 'styles') {
  277. // object with string keys and string (!) values
  278. var styleNames = Object.keys(propValue);
  279. var styleCount = styleNames.length;
  280. for (var j = 0; j < styleCount; j++) {
  281. var styleName = styleNames[j];
  282. var styleValue = propValue[styleName];
  283. if (styleValue) {
  284. checkStyleValue(styleValue);
  285. projectionOptions.styleApplyer(domNode, styleName, styleValue);
  286. }
  287. }
  288. } else if (propName === 'key') {
  289. continue;
  290. } else if (propValue === null || propValue === undefined) {
  291. continue;
  292. } else {
  293. var type = typeof propValue;
  294. if (type === 'function') {
  295. if (propName.lastIndexOf('on', 0) === 0) {
  296. if (eventHandlerInterceptor) {
  297. propValue = eventHandlerInterceptor(propName, propValue, domNode, properties); // intercept eventhandlers
  298. }
  299. if (propName === 'oninput') {
  300. (function () {
  301. // record the evt.target.value, because IE and Edge sometimes do a requestAnimationFrame between changing value and running oninput
  302. var oldPropValue = propValue;
  303. propValue = function (evt) {
  304. evt.target['oninput-value'] = evt.target.value;
  305. // may be HTMLTextAreaElement as well
  306. oldPropValue.apply(this, [evt]);
  307. };
  308. }());
  309. }
  310. domNode[propName] = propValue;
  311. }
  312. } else if (type === 'string' && propName !== 'value' && propName !== 'innerHTML') {
  313. if (projectionOptions.namespace === NAMESPACE_SVG && propName === 'href') {
  314. domNode.setAttributeNS(NAMESPACE_XLINK, propName, propValue);
  315. } else {
  316. domNode.setAttribute(propName, propValue);
  317. }
  318. } else {
  319. domNode[propName] = propValue;
  320. }
  321. }
  322. }
  323. };
  324. var updateProperties = function (domNode, previousProperties, properties, projectionOptions) {
  325. if (!properties) {
  326. return;
  327. }
  328. var propertiesUpdated = false;
  329. var propNames = Object.keys(properties);
  330. var propCount = propNames.length;
  331. for (var i = 0; i < propCount; i++) {
  332. var propName = propNames[i];
  333. // assuming that properties will be nullified instead of missing is by design
  334. var propValue = properties[propName];
  335. var previousValue = previousProperties[propName];
  336. if (propName === 'class') {
  337. if (previousValue !== propValue) {
  338. throw new Error('"class" property may not be updated. Use the "classes" property for conditional css classes.');
  339. }
  340. } else if (propName === 'classes') {
  341. var classList = domNode.classList;
  342. var classNames = Object.keys(propValue);
  343. var classNameCount = classNames.length;
  344. for (var j = 0; j < classNameCount; j++) {
  345. var className = classNames[j];
  346. var on = !!propValue[className];
  347. var previousOn = !!previousValue[className];
  348. if (on === previousOn) {
  349. continue;
  350. }
  351. propertiesUpdated = true;
  352. if (on) {
  353. classList.add(className);
  354. } else {
  355. classList.remove(className);
  356. }
  357. }
  358. } else if (propName === 'styles') {
  359. var styleNames = Object.keys(propValue);
  360. var styleCount = styleNames.length;
  361. for (var j = 0; j < styleCount; j++) {
  362. var styleName = styleNames[j];
  363. var newStyleValue = propValue[styleName];
  364. var oldStyleValue = previousValue[styleName];
  365. if (newStyleValue === oldStyleValue) {
  366. continue;
  367. }
  368. propertiesUpdated = true;
  369. if (newStyleValue) {
  370. checkStyleValue(newStyleValue);
  371. projectionOptions.styleApplyer(domNode, styleName, newStyleValue);
  372. } else {
  373. projectionOptions.styleApplyer(domNode, styleName, '');
  374. }
  375. }
  376. } else {
  377. if (!propValue && typeof previousValue === 'string') {
  378. propValue = '';
  379. }
  380. if (propName === 'value') {
  381. if (domNode[propName] !== propValue && domNode['oninput-value'] !== propValue) {
  382. domNode[propName] = propValue;
  383. // Reset the value, even if the virtual DOM did not change
  384. domNode['oninput-value'] = undefined;
  385. }
  386. // else do not update the domNode, otherwise the cursor position would be changed
  387. if (propValue !== previousValue) {
  388. propertiesUpdated = true;
  389. }
  390. } else if (propValue !== previousValue) {
  391. var type = typeof propValue;
  392. if (type === 'function') {
  393. throw new Error('Functions may not be updated on subsequent renders (property: ' + propName + '). Hint: declare event handler functions outside the render() function.');
  394. }
  395. if (type === 'string' && propName !== 'innerHTML') {
  396. if (projectionOptions.namespace === NAMESPACE_SVG && propName === 'href') {
  397. domNode.setAttributeNS(NAMESPACE_XLINK, propName, propValue);
  398. } else {
  399. domNode.setAttribute(propName, propValue);
  400. }
  401. } else {
  402. if (domNode[propName] !== propValue) {
  403. domNode[propName] = propValue;
  404. }
  405. }
  406. propertiesUpdated = true;
  407. }
  408. }
  409. }
  410. return propertiesUpdated;
  411. };
  412. var findIndexOfChild = function (children, sameAs, start) {
  413. if (sameAs.vnodeSelector !== '') {
  414. // Never scan for text-nodes
  415. for (var i = start; i < children.length; i++) {
  416. if (same(children[i], sameAs)) {
  417. return i;
  418. }
  419. }
  420. }
  421. return -1;
  422. };
  423. var nodeAdded = function (vNode, transitions) {
  424. if (vNode.properties) {
  425. var enterAnimation = vNode.properties.enterAnimation;
  426. if (enterAnimation) {
  427. if (typeof enterAnimation === 'function') {
  428. enterAnimation(vNode.domNode, vNode.properties);
  429. } else {
  430. transitions.enter(vNode.domNode, vNode.properties, enterAnimation);
  431. }
  432. }
  433. }
  434. };
  435. var nodeToRemove = function (vNode, transitions) {
  436. var domNode = vNode.domNode;
  437. if (vNode.properties) {
  438. var exitAnimation = vNode.properties.exitAnimation;
  439. if (exitAnimation) {
  440. domNode.style.pointerEvents = 'none';
  441. var removeDomNode = function () {
  442. if (domNode.parentNode) {
  443. domNode.parentNode.removeChild(domNode);
  444. }
  445. };
  446. if (typeof exitAnimation === 'function') {
  447. exitAnimation(domNode, removeDomNode, vNode.properties);
  448. return;
  449. } else {
  450. transitions.exit(vNode.domNode, vNode.properties, exitAnimation, removeDomNode);
  451. return;
  452. }
  453. }
  454. }
  455. if (domNode.parentNode) {
  456. domNode.parentNode.removeChild(domNode);
  457. }
  458. };
  459. var checkDistinguishable = function (childNodes, indexToCheck, parentVNode, operation) {
  460. var childNode = childNodes[indexToCheck];
  461. if (childNode.vnodeSelector === '') {
  462. return; // Text nodes need not be distinguishable
  463. }
  464. var properties = childNode.properties;
  465. var key = properties ? properties.key === undefined ? properties.bind : properties.key : undefined;
  466. if (!key) {
  467. for (var i = 0; i < childNodes.length; i++) {
  468. if (i !== indexToCheck) {
  469. var node = childNodes[i];
  470. if (same(node, childNode)) {
  471. if (operation === 'added') {
  472. throw new Error(parentVNode.vnodeSelector + ' had a ' + childNode.vnodeSelector + ' child ' + 'added, but there is now more than one. You must add unique key properties to make them distinguishable.');
  473. } else {
  474. throw new Error(parentVNode.vnodeSelector + ' had a ' + childNode.vnodeSelector + ' child ' + 'removed, but there were more than one. You must add unique key properties to make them distinguishable.');
  475. }
  476. }
  477. }
  478. }
  479. }
  480. };
  481. var createDom;
  482. var updateDom;
  483. var updateChildren = function (vnode, domNode, oldChildren, newChildren, projectionOptions) {
  484. if (oldChildren === newChildren) {
  485. return false;
  486. }
  487. oldChildren = oldChildren || emptyArray;
  488. newChildren = newChildren || emptyArray;
  489. var oldChildrenLength = oldChildren.length;
  490. var newChildrenLength = newChildren.length;
  491. var transitions = projectionOptions.transitions;
  492. var oldIndex = 0;
  493. var newIndex = 0;
  494. var i;
  495. var textUpdated = false;
  496. while (newIndex < newChildrenLength) {
  497. var oldChild = oldIndex < oldChildrenLength ? oldChildren[oldIndex] : undefined;
  498. var newChild = newChildren[newIndex];
  499. if (oldChild !== undefined && same(oldChild, newChild)) {
  500. textUpdated = updateDom(oldChild, newChild, projectionOptions) || textUpdated;
  501. oldIndex++;
  502. } else {
  503. var findOldIndex = findIndexOfChild(oldChildren, newChild, oldIndex + 1);
  504. if (findOldIndex >= 0) {
  505. // Remove preceding missing children
  506. for (i = oldIndex; i < findOldIndex; i++) {
  507. nodeToRemove(oldChildren[i], transitions);
  508. checkDistinguishable(oldChildren, i, vnode, 'removed');
  509. }
  510. textUpdated = updateDom(oldChildren[findOldIndex], newChild, projectionOptions) || textUpdated;
  511. oldIndex = findOldIndex + 1;
  512. } else {
  513. // New child
  514. createDom(newChild, domNode, oldIndex < oldChildrenLength ? oldChildren[oldIndex].domNode : undefined, projectionOptions);
  515. nodeAdded(newChild, transitions);
  516. checkDistinguishable(newChildren, newIndex, vnode, 'added');
  517. }
  518. }
  519. newIndex++;
  520. }
  521. if (oldChildrenLength > oldIndex) {
  522. // Remove child fragments
  523. for (i = oldIndex; i < oldChildrenLength; i++) {
  524. nodeToRemove(oldChildren[i], transitions);
  525. checkDistinguishable(oldChildren, i, vnode, 'removed');
  526. }
  527. }
  528. return textUpdated;
  529. };
  530. var addChildren = function (domNode, children, projectionOptions) {
  531. if (!children) {
  532. return;
  533. }
  534. for (var i = 0; i < children.length; i++) {
  535. createDom(children[i], domNode, undefined, projectionOptions);
  536. }
  537. };
  538. var initPropertiesAndChildren = function (domNode, vnode, projectionOptions) {
  539. addChildren(domNode, vnode.children, projectionOptions);
  540. // children before properties, needed for value property of <select>.
  541. if (vnode.text) {
  542. domNode.textContent = vnode.text;
  543. }
  544. setProperties(domNode, vnode.properties, projectionOptions);
  545. if (vnode.properties && vnode.properties.afterCreate) {
  546. vnode.properties.afterCreate(domNode, projectionOptions, vnode.vnodeSelector, vnode.properties, vnode.children);
  547. }
  548. };
  549. createDom = function (vnode, parentNode, insertBefore, projectionOptions) {
  550. var domNode, i, c, start = 0, type, found;
  551. var vnodeSelector = vnode.vnodeSelector;
  552. if (vnodeSelector === '') {
  553. domNode = vnode.domNode = document.createTextNode(vnode.text);
  554. if (insertBefore !== undefined) {
  555. parentNode.insertBefore(domNode, insertBefore);
  556. } else {
  557. parentNode.appendChild(domNode);
  558. }
  559. } else {
  560. for (i = 0; i <= vnodeSelector.length; ++i) {
  561. c = vnodeSelector.charAt(i);
  562. if (i === vnodeSelector.length || c === '.' || c === '#') {
  563. type = vnodeSelector.charAt(start - 1);
  564. found = vnodeSelector.slice(start, i);
  565. if (type === '.') {
  566. domNode.classList.add(found);
  567. } else if (type === '#') {
  568. domNode.id = found;
  569. } else {
  570. if (found === 'svg') {
  571. projectionOptions = extend(projectionOptions, { namespace: NAMESPACE_SVG });
  572. }
  573. if (projectionOptions.namespace !== undefined) {
  574. domNode = vnode.domNode = document.createElementNS(projectionOptions.namespace, found);
  575. } else {
  576. domNode = vnode.domNode = document.createElement(found);
  577. }
  578. if (insertBefore !== undefined) {
  579. parentNode.insertBefore(domNode, insertBefore);
  580. } else {
  581. parentNode.appendChild(domNode);
  582. }
  583. }
  584. start = i + 1;
  585. }
  586. }
  587. initPropertiesAndChildren(domNode, vnode, projectionOptions);
  588. }
  589. };
  590. updateDom = function (previous, vnode, projectionOptions) {
  591. var domNode = previous.domNode;
  592. var textUpdated = false;
  593. if (previous === vnode) {
  594. return false; // By contract, VNode objects may not be modified anymore after passing them to maquette
  595. }
  596. var updated = false;
  597. if (vnode.vnodeSelector === '') {
  598. if (vnode.text !== previous.text) {
  599. var newVNode = document.createTextNode(vnode.text);
  600. domNode.parentNode.replaceChild(newVNode, domNode);
  601. vnode.domNode = newVNode;
  602. textUpdated = true;
  603. return textUpdated;
  604. }
  605. } else {
  606. if (vnode.vnodeSelector.lastIndexOf('svg', 0) === 0) {
  607. projectionOptions = extend(projectionOptions, { namespace: NAMESPACE_SVG });
  608. }
  609. if (previous.text !== vnode.text) {
  610. updated = true;
  611. if (vnode.text === undefined) {
  612. domNode.removeChild(domNode.firstChild); // the only textnode presumably
  613. } else {
  614. domNode.textContent = vnode.text;
  615. }
  616. }
  617. updated = updateChildren(vnode, domNode, previous.children, vnode.children, projectionOptions) || updated;
  618. updated = updateProperties(domNode, previous.properties, vnode.properties, projectionOptions) || updated;
  619. if (vnode.properties && vnode.properties.afterUpdate) {
  620. vnode.properties.afterUpdate(domNode, projectionOptions, vnode.vnodeSelector, vnode.properties, vnode.children);
  621. }
  622. }
  623. if (updated && vnode.properties && vnode.properties.updateAnimation) {
  624. vnode.properties.updateAnimation(domNode, vnode.properties, previous.properties);
  625. }
  626. vnode.domNode = previous.domNode;
  627. return textUpdated;
  628. };
  629. var createProjection = function (vnode, projectionOptions) {
  630. return {
  631. update: function (updatedVnode) {
  632. if (vnode.vnodeSelector !== updatedVnode.vnodeSelector) {
  633. throw new Error('The selector for the root VNode may not be changed. (consider using dom.merge and add one extra level to the virtual DOM)');
  634. }
  635. updateDom(vnode, updatedVnode, projectionOptions);
  636. vnode = updatedVnode;
  637. },
  638. domNode: vnode.domNode
  639. };
  640. };
  641. ;
  642. // The other two parameters are not added here, because the Typescript compiler creates surrogate code for desctructuring 'children'.
  643. exports.h = function (selector) {
  644. var properties = arguments[1];
  645. if (typeof selector !== 'string') {
  646. throw new Error();
  647. }
  648. var childIndex = 1;
  649. if (properties && !properties.hasOwnProperty('vnodeSelector') && !Array.isArray(properties) && typeof properties === 'object') {
  650. childIndex = 2;
  651. } else {
  652. // Optional properties argument was omitted
  653. properties = undefined;
  654. }
  655. var text = undefined;
  656. var children = undefined;
  657. var argsLength = arguments.length;
  658. // Recognize a common special case where there is only a single text node
  659. if (argsLength === childIndex + 1) {
  660. var onlyChild = arguments[childIndex];
  661. if (typeof onlyChild === 'string') {
  662. text = onlyChild;
  663. } else if (onlyChild !== undefined && onlyChild.length === 1 && typeof onlyChild[0] === 'string') {
  664. text = onlyChild[0];
  665. }
  666. }
  667. if (text === undefined) {
  668. children = [];
  669. for (; childIndex < arguments.length; childIndex++) {
  670. var child = arguments[childIndex];
  671. if (child === null || child === undefined) {
  672. continue;
  673. } else if (Array.isArray(child)) {
  674. appendChildren(selector, child, children);
  675. } else if (child.hasOwnProperty('vnodeSelector')) {
  676. children.push(child);
  677. } else {
  678. children.push(toTextVNode(child));
  679. }
  680. }
  681. }
  682. return {
  683. vnodeSelector: selector,
  684. properties: properties,
  685. children: children,
  686. text: text === '' ? undefined : text,
  687. domNode: null
  688. };
  689. };
  690. /**
  691. * Contains simple low-level utility functions to manipulate the real DOM.
  692. */
  693. exports.dom = {
  694. /**
  695. * Creates a real DOM tree from `vnode`. The [[Projection]] object returned will contain the resulting DOM Node in
  696. * its [[Projection.domNode|domNode]] property.
  697. * This is a low-level method. Users wil typically use a [[Projector]] instead.
  698. * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
  699. * objects may only be rendered once.
  700. * @param projectionOptions - Options to be used to create and update the projection.
  701. * @returns The [[Projection]] which also contains the DOM Node that was created.
  702. */
  703. create: function (vnode, projectionOptions) {
  704. projectionOptions = applyDefaultProjectionOptions(projectionOptions);
  705. createDom(vnode, document.createElement('div'), undefined, projectionOptions);
  706. return createProjection(vnode, projectionOptions);
  707. },
  708. /**
  709. * Appends a new childnode to the DOM which is generated from a [[VNode]].
  710. * This is a low-level method. Users wil typically use a [[Projector]] instead.
  711. * @param parentNode - The parent node for the new childNode.
  712. * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
  713. * objects may only be rendered once.
  714. * @param projectionOptions - Options to be used to create and update the [[Projection]].
  715. * @returns The [[Projection]] that was created.
  716. */
  717. append: function (parentNode, vnode, projectionOptions) {
  718. projectionOptions = applyDefaultProjectionOptions(projectionOptions);
  719. createDom(vnode, parentNode, undefined, projectionOptions);
  720. return createProjection(vnode, projectionOptions);
  721. },
  722. /**
  723. * Inserts a new DOM node which is generated from a [[VNode]].
  724. * This is a low-level method. Users wil typically use a [[Projector]] instead.
  725. * @param beforeNode - The node that the DOM Node is inserted before.
  726. * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function.
  727. * NOTE: [[VNode]] objects may only be rendered once.
  728. * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
  729. * @returns The [[Projection]] that was created.
  730. */
  731. insertBefore: function (beforeNode, vnode, projectionOptions) {
  732. projectionOptions = applyDefaultProjectionOptions(projectionOptions);
  733. createDom(vnode, beforeNode.parentNode, beforeNode, projectionOptions);
  734. return createProjection(vnode, projectionOptions);
  735. },
  736. /**
  737. * Merges a new DOM node which is generated from a [[VNode]] with an existing DOM Node.
  738. * This means that the virtual DOM and the real DOM will have one overlapping element.
  739. * Therefore the selector for the root [[VNode]] will be ignored, but its properties and children will be applied to the Element provided.
  740. * This is a low-level method. Users wil typically use a [[Projector]] instead.
  741. * @param domNode - The existing element to adopt as the root of the new virtual DOM. Existing attributes and childnodes are preserved.
  742. * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]] objects
  743. * may only be rendered once.
  744. * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
  745. * @returns The [[Projection]] that was created.
  746. */
  747. merge: function (element, vnode, projectionOptions) {
  748. projectionOptions = applyDefaultProjectionOptions(projectionOptions);
  749. vnode.domNode = element;
  750. initPropertiesAndChildren(element, vnode, projectionOptions);
  751. return createProjection(vnode, projectionOptions);
  752. }
  753. };
  754. /**
  755. * Creates a [[CalculationCache]] object, useful for caching [[VNode]] trees.
  756. * In practice, caching of [[VNode]] trees is not needed, because achieving 60 frames per second is almost never a problem.
  757. * For more information, see [[CalculationCache]].
  758. *
  759. * @param <Result> The type of the value that is cached.
  760. */
  761. exports.createCache = function () {
  762. var cachedInputs = undefined;
  763. var cachedOutcome = undefined;
  764. var result = {
  765. invalidate: function () {
  766. cachedOutcome = undefined;
  767. cachedInputs = undefined;
  768. },
  769. result: function (inputs, calculation) {
  770. if (cachedInputs) {
  771. for (var i = 0; i < inputs.length; i++) {
  772. if (cachedInputs[i] !== inputs[i]) {
  773. cachedOutcome = undefined;
  774. }
  775. }
  776. }
  777. if (!cachedOutcome) {
  778. cachedOutcome = calculation();
  779. cachedInputs = inputs;
  780. }
  781. return cachedOutcome;
  782. }
  783. };
  784. return result;
  785. };
  786. /**
  787. * Creates a {@link Mapping} instance that keeps an array of result objects synchronized with an array of source objects.
  788. * See {@link http://maquettejs.org/docs/arrays.html|Working with arrays}.
  789. *
  790. * @param <Source> The type of source items. A database-record for instance.
  791. * @param <Target> The type of target items. A [[Component]] for instance.
  792. * @param getSourceKey `function(source)` that must return a key to identify each source object. The result must either be a string or a number.
  793. * @param createResult `function(source, index)` that must create a new result object from a given source. This function is identical
  794. * to the `callback` argument in `Array.map(callback)`.
  795. * @param updateResult `function(source, target, index)` that updates a result to an updated source.
  796. */
  797. exports.createMapping = function (getSourceKey, createResult, updateResult) {
  798. var keys = [];
  799. var results = [];
  800. return {
  801. results: results,
  802. map: function (newSources) {
  803. var newKeys = newSources.map(getSourceKey);
  804. var oldTargets = results.slice();
  805. var oldIndex = 0;
  806. for (var i = 0; i < newSources.length; i++) {
  807. var source = newSources[i];
  808. var sourceKey = newKeys[i];
  809. if (sourceKey === keys[oldIndex]) {
  810. results[i] = oldTargets[oldIndex];
  811. updateResult(source, oldTargets[oldIndex], i);
  812. oldIndex++;
  813. } else {
  814. var found = false;
  815. for (var j = 1; j < keys.length; j++) {
  816. var searchIndex = (oldIndex + j) % keys.length;
  817. if (keys[searchIndex] === sourceKey) {
  818. results[i] = oldTargets[searchIndex];
  819. updateResult(newSources[i], oldTargets[searchIndex], i);
  820. oldIndex = searchIndex + 1;
  821. found = true;
  822. break;
  823. }
  824. }
  825. if (!found) {
  826. results[i] = createResult(source, i);
  827. }
  828. }
  829. }
  830. results.length = newSources.length;
  831. keys = newKeys;
  832. }
  833. };
  834. };
  835. /**
  836. * Creates a [[Projector]] instance using the provided projectionOptions.
  837. *
  838. * For more information, see [[Projector]].
  839. *
  840. * @param projectionOptions Options that influence how the DOM is rendered and updated.
  841. */
  842. exports.createProjector = function (projectorOptions) {
  843. var projector;
  844. var projectionOptions = applyDefaultProjectionOptions(projectorOptions);
  845. projectionOptions.eventHandlerInterceptor = function (propertyName, eventHandler, domNode, properties) {
  846. return function () {
  847. // intercept function calls (event handlers) to do a render afterwards.
  848. projector.scheduleRender();
  849. return eventHandler.apply(properties.bind || this, arguments);
  850. };
  851. };
  852. var renderCompleted = true;
  853. var scheduled;
  854. var stopped = false;
  855. var projections = [];
  856. var renderFunctions = [];
  857. // matches the projections array
  858. var doRender = function () {
  859. scheduled = undefined;
  860. if (!renderCompleted) {
  861. return; // The last render threw an error, it should be logged in the browser console.
  862. }
  863. renderCompleted = false;
  864. for (var i = 0; i < projections.length; i++) {
  865. var updatedVnode = renderFunctions[i]();
  866. projections[i].update(updatedVnode);
  867. }
  868. renderCompleted = true;
  869. };
  870. projector = {
  871. scheduleRender: function () {
  872. if (!scheduled && !stopped) {
  873. scheduled = requestAnimationFrame(doRender);
  874. }
  875. },
  876. stop: function () {
  877. if (scheduled) {
  878. cancelAnimationFrame(scheduled);
  879. scheduled = undefined;
  880. }
  881. stopped = true;
  882. },
  883. resume: function () {
  884. stopped = false;
  885. renderCompleted = true;
  886. projector.scheduleRender();
  887. },
  888. append: function (parentNode, renderMaquetteFunction) {
  889. projections.push(exports.dom.append(parentNode, renderMaquetteFunction(), projectionOptions));
  890. renderFunctions.push(renderMaquetteFunction);
  891. },
  892. insertBefore: function (beforeNode, renderMaquetteFunction) {
  893. projections.push(exports.dom.insertBefore(beforeNode, renderMaquetteFunction(), projectionOptions));
  894. renderFunctions.push(renderMaquetteFunction);
  895. },
  896. merge: function (domNode, renderMaquetteFunction) {
  897. projections.push(exports.dom.merge(domNode, renderMaquetteFunction(), projectionOptions));
  898. renderFunctions.push(renderMaquetteFunction);
  899. },
  900. replace: function (domNode, renderMaquetteFunction) {
  901. var vnode = renderMaquetteFunction();
  902. createDom(vnode, domNode.parentNode, domNode, projectionOptions);
  903. domNode.parentNode.removeChild(domNode);
  904. projections.push(createProjection(vnode, projectionOptions));
  905. renderFunctions.push(renderMaquetteFunction);
  906. },
  907. detach: function (renderMaquetteFunction) {
  908. for (var i = 0; i < renderFunctions.length; i++) {
  909. if (renderFunctions[i] === renderMaquetteFunction) {
  910. renderFunctions.splice(i, 1);
  911. return projections.splice(i, 1)[0];
  912. }
  913. }
  914. throw new Error('renderMaquetteFunction was not found');
  915. }
  916. };
  917. return projector;
  918. };
  919. }));
  920. /* ---- utils/Animation.coffee ---- */
  921. (function() {
  922. var Animation;
  923. Animation = (function() {
  924. function Animation() {}
  925. Animation.prototype.slideDown = function(elem, props) {
  926. var cstyle, h, margin_bottom, margin_top, padding_bottom, padding_top, transition;
  927. if (elem.offsetTop > 2000) {
  928. return;
  929. }
  930. h = elem.offsetHeight;
  931. cstyle = window.getComputedStyle(elem);
  932. margin_top = cstyle.marginTop;
  933. margin_bottom = cstyle.marginBottom;
  934. padding_top = cstyle.paddingTop;
  935. padding_bottom = cstyle.paddingBottom;
  936. transition = cstyle.transition;
  937. elem.style.boxSizing = "border-box";
  938. elem.style.overflow = "hidden";
  939. elem.style.transform = "scale(0.6)";
  940. elem.style.opacity = "0";
  941. elem.style.height = "0px";
  942. elem.style.marginTop = "0px";
  943. elem.style.marginBottom = "0px";
  944. elem.style.paddingTop = "0px";
  945. elem.style.paddingBottom = "0px";
  946. elem.style.transition = "none";
  947. setTimeout((function() {
  948. elem.className += " animate-inout";
  949. elem.style.height = h + "px";
  950. elem.style.transform = "scale(1)";
  951. elem.style.opacity = "1";
  952. elem.style.marginTop = margin_top;
  953. elem.style.marginBottom = margin_bottom;
  954. elem.style.paddingTop = padding_top;
  955. return elem.style.paddingBottom = padding_bottom;
  956. }), 1);
  957. return elem.addEventListener("transitionend", function() {
  958. elem.classList.remove("animate-inout");
  959. elem.style.transition = elem.style.transform = elem.style.opacity = elem.style.height = null;
  960. elem.style.boxSizing = elem.style.marginTop = elem.style.marginBottom = null;
  961. elem.style.paddingTop = elem.style.paddingBottom = elem.style.overflow = null;
  962. return elem.removeEventListener("transitionend", arguments.callee, false);
  963. });
  964. };
  965. Animation.prototype.slideUp = function(elem, remove_func, props) {
  966. if (elem.offsetTop > 1000) {
  967. return remove_func();
  968. }
  969. elem.className += " animate-back";
  970. elem.style.boxSizing = "border-box";
  971. elem.style.height = elem.offsetHeight + "px";
  972. elem.style.overflow = "hidden";
  973. elem.style.transform = "scale(1)";
  974. elem.style.opacity = "1";
  975. elem.style.pointerEvents = "none";
  976. setTimeout((function() {
  977. elem.style.height = "0px";
  978. elem.style.marginTop = "0px";
  979. elem.style.marginBottom = "0px";
  980. elem.style.paddingTop = "0px";
  981. elem.style.paddingBottom = "0px";
  982. elem.style.transform = "scale(0.8)";
  983. elem.style.borderTopWidth = "0px";
  984. elem.style.borderBottomWidth = "0px";
  985. return elem.style.opacity = "0";
  986. }), 1);
  987. return elem.addEventListener("transitionend", function(e) {
  988. if (e.propertyName === "opacity" || e.elapsedTime >= 0.6) {
  989. elem.removeEventListener("transitionend", arguments.callee, false);
  990. return remove_func();
  991. }
  992. });
  993. };
  994. Animation.prototype.slideUpInout = function(elem, remove_func, props) {
  995. elem.className += " animate-inout";
  996. elem.style.boxSizing = "border-box";
  997. elem.style.height = elem.offsetHeight + "px";
  998. elem.style.overflow = "hidden";
  999. elem.style.transform = "scale(1)";
  1000. elem.style.opacity = "1";
  1001. elem.style.pointerEvents = "none";
  1002. setTimeout((function() {
  1003. elem.style.height = "0px";
  1004. elem.style.marginTop = "0px";
  1005. elem.style.marginBottom = "0px";
  1006. elem.style.paddingTop = "0px";
  1007. elem.style.paddingBottom = "0px";
  1008. elem.style.transform = "scale(0.8)";
  1009. elem.style.borderTopWidth = "0px";
  1010. elem.style.borderBottomWidth = "0px";
  1011. return elem.style.opacity = "0";
  1012. }), 1);
  1013. return elem.addEventListener("transitionend", function(e) {
  1014. if (e.propertyName === "opacity" || e.elapsedTime >= 0.6) {
  1015. elem.removeEventListener("transitionend", arguments.callee, false);
  1016. return remove_func();
  1017. }
  1018. });
  1019. };
  1020. Animation.prototype.showRight = function(elem, props) {
  1021. elem.className += " animate";
  1022. elem.style.opacity = 0;
  1023. elem.style.transform = "TranslateX(-20px) Scale(1.01)";
  1024. setTimeout((function() {
  1025. elem.style.opacity = 1;
  1026. return elem.style.transform = "TranslateX(0px) Scale(1)";
  1027. }), 1);
  1028. return elem.addEventListener("transitionend", function() {
  1029. elem.classList.remove("animate");
  1030. return elem.style.transform = elem.style.opacity = null;
  1031. });
  1032. };
  1033. Animation.prototype.show = function(elem, props) {
  1034. var delay, ref;
  1035. delay = ((ref = arguments[arguments.length - 2]) != null ? ref.delay : void 0) * 1000 || 1;
  1036. elem.style.opacity = 0;
  1037. setTimeout((function() {
  1038. return elem.className += " animate";
  1039. }), 1);
  1040. setTimeout((function() {
  1041. return elem.style.opacity = 1;
  1042. }), delay);
  1043. return elem.addEventListener("transitionend", function() {
  1044. elem.classList.remove("animate");
  1045. elem.style.opacity = null;
  1046. return elem.removeEventListener("transitionend", arguments.callee, false);
  1047. });
  1048. };
  1049. Animation.prototype.hide = function(elem, remove_func, props) {
  1050. var delay, ref;
  1051. delay = ((ref = arguments[arguments.length - 2]) != null ? ref.delay : void 0) * 1000 || 1;
  1052. elem.className += " animate";
  1053. setTimeout((function() {
  1054. return elem.style.opacity = 0;
  1055. }), delay);
  1056. return elem.addEventListener("transitionend", function(e) {
  1057. if (e.propertyName === "opacity") {
  1058. return remove_func();
  1059. }
  1060. });
  1061. };
  1062. Animation.prototype.addVisibleClass = function(elem, props) {
  1063. return setTimeout(function() {
  1064. return elem.classList.add("visible");
  1065. });
  1066. };
  1067. return Animation;
  1068. })();
  1069. window.Animation = new Animation();
  1070. }).call(this);
  1071. /* ---- utils/Dollar.coffee ---- */
  1072. (function() {
  1073. window.$ = function(selector) {
  1074. if (selector.startsWith("#")) {
  1075. return document.getElementById(selector.replace("#", ""));
  1076. }
  1077. };
  1078. }).call(this);
  1079. /* ---- utils/ZeroFrame.coffee ---- */
  1080. (function() {
  1081. var ZeroFrame,
  1082. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  1083. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  1084. hasProp = {}.hasOwnProperty;
  1085. ZeroFrame = (function(superClass) {
  1086. extend(ZeroFrame, superClass);
  1087. function ZeroFrame(url) {
  1088. this.onCloseWebsocket = bind(this.onCloseWebsocket, this);
  1089. this.onOpenWebsocket = bind(this.onOpenWebsocket, this);
  1090. this.onRequest = bind(this.onRequest, this);
  1091. this.onMessage = bind(this.onMessage, this);
  1092. this.url = url;
  1093. this.waiting_cb = {};
  1094. this.wrapper_nonce = document.location.href.replace(/.*wrapper_nonce=([A-Za-z0-9]+).*/, "$1");
  1095. this.connect();
  1096. this.next_message_id = 1;
  1097. this.history_state = {};
  1098. this.init();
  1099. }
  1100. ZeroFrame.prototype.init = function() {
  1101. return this;
  1102. };
  1103. ZeroFrame.prototype.connect = function() {
  1104. this.target = window.parent;
  1105. window.addEventListener("message", this.onMessage, false);
  1106. this.cmd("innerReady");
  1107. window.addEventListener("beforeunload", (function(_this) {
  1108. return function(e) {
  1109. _this.log("save scrollTop", window.pageYOffset);
  1110. _this.history_state["scrollTop"] = window.pageYOffset;
  1111. return _this.cmd("wrapperReplaceState", [_this.history_state, null]);
  1112. };
  1113. })(this));
  1114. return this.cmd("wrapperGetState", [], (function(_this) {
  1115. return function(state) {
  1116. if (state != null) {
  1117. _this.history_state = state;
  1118. }
  1119. _this.log("restore scrollTop", state, window.pageYOffset);
  1120. if (window.pageYOffset === 0 && state) {
  1121. return window.scroll(window.pageXOffset, state.scrollTop);
  1122. }
  1123. };
  1124. })(this));
  1125. };
  1126. ZeroFrame.prototype.onMessage = function(e) {
  1127. var cmd, message;
  1128. message = e.data;
  1129. cmd = message.cmd;
  1130. if (cmd === "response") {
  1131. if (this.waiting_cb[message.to] != null) {
  1132. return this.waiting_cb[message.to](message.result);
  1133. } else {
  1134. return this.log("Websocket callback not found:", message);
  1135. }
  1136. } else if (cmd === "wrapperReady") {
  1137. return this.cmd("innerReady");
  1138. } else if (cmd === "ping") {
  1139. return this.response(message.id, "pong");
  1140. } else if (cmd === "wrapperOpenedWebsocket") {
  1141. return this.onOpenWebsocket();
  1142. } else if (cmd === "wrapperClosedWebsocket") {
  1143. return this.onCloseWebsocket();
  1144. } else {
  1145. return this.onRequest(cmd, message.params);
  1146. }
  1147. };
  1148. ZeroFrame.prototype.onRequest = function(cmd, message) {
  1149. return this.log("Unknown request", message);
  1150. };
  1151. ZeroFrame.prototype.response = function(to, result) {
  1152. return this.send({
  1153. "cmd": "response",
  1154. "to": to,
  1155. "result": result
  1156. });
  1157. };
  1158. ZeroFrame.prototype.cmd = function(cmd, params, cb) {
  1159. if (params == null) {
  1160. params = {};
  1161. }
  1162. if (cb == null) {
  1163. cb = null;
  1164. }
  1165. return this.send({
  1166. "cmd": cmd,
  1167. "params": params
  1168. }, cb);
  1169. };
  1170. ZeroFrame.prototype.send = function(message, cb) {
  1171. if (cb == null) {
  1172. cb = null;
  1173. }
  1174. message.wrapper_nonce = this.wrapper_nonce;
  1175. message.id = this.next_message_id;
  1176. this.next_message_id += 1;
  1177. this.target.postMessage(message, "*");
  1178. if (cb) {
  1179. return this.waiting_cb[message.id] = cb;
  1180. }
  1181. };
  1182. ZeroFrame.prototype.onOpenWebsocket = function() {
  1183. return this.log("Websocket open");
  1184. };
  1185. ZeroFrame.prototype.onCloseWebsocket = function() {
  1186. return this.log("Websocket close");
  1187. };
  1188. return ZeroFrame;
  1189. })(Class);
  1190. window.ZeroFrame = ZeroFrame;
  1191. }).call(this);
  1192. /* ---- PluginList.coffee ---- */
  1193. (function() {
  1194. var PluginList,
  1195. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  1196. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  1197. hasProp = {}.hasOwnProperty;
  1198. PluginList = (function(superClass) {
  1199. extend(PluginList, superClass);
  1200. function PluginList(plugins) {
  1201. this.handleDeleteClick = bind(this.handleDeleteClick, this);
  1202. this.handleUpdateClick = bind(this.handleUpdateClick, this);
  1203. this.handleResetClick = bind(this.handleResetClick, this);
  1204. this.handleCheckboxChange = bind(this.handleCheckboxChange, this);
  1205. this.savePluginStatus = bind(this.savePluginStatus, this);
  1206. this.plugins = plugins;
  1207. }
  1208. PluginList.prototype.savePluginStatus = function(plugin, is_enabled) {
  1209. Page.cmd("pluginConfigSet", [plugin.source, plugin.inner_path, "enabled", is_enabled], (function(_this) {
  1210. return function(res) {
  1211. if (res === "ok") {
  1212. return Page.updatePlugins();
  1213. } else {
  1214. return Page.cmd("wrapperNotification", ["error", res.error]);
  1215. }
  1216. };
  1217. })(this));
  1218. return Page.projector.scheduleRender();
  1219. };
  1220. PluginList.prototype.handleCheckboxChange = function(e) {
  1221. var node, plugin, value;
  1222. node = e.currentTarget;
  1223. plugin = node["data-plugin"];
  1224. node.classList.toggle("checked");
  1225. value = node.classList.contains("checked");
  1226. return this.savePluginStatus(plugin, value);
  1227. };
  1228. PluginList.prototype.handleResetClick = function(e) {
  1229. var node, plugin;
  1230. node = e.currentTarget;
  1231. plugin = node["data-plugin"];
  1232. return this.savePluginStatus(plugin, null);
  1233. };
  1234. PluginList.prototype.handleUpdateClick = function(e) {
  1235. var node, plugin;
  1236. node = e.currentTarget;
  1237. plugin = node["data-plugin"];
  1238. node.classList.add("loading");
  1239. Page.cmd("pluginUpdate", [plugin.source, plugin.inner_path], (function(_this) {
  1240. return function(res) {
  1241. if (res === "ok") {
  1242. Page.cmd("wrapperNotification", ["done", "Plugin " + plugin.name + " updated to latest version"]);
  1243. Page.updatePlugins();
  1244. } else {
  1245. Page.cmd("wrapperNotification", ["error", res.error]);
  1246. }
  1247. return node.classList.remove("loading");
  1248. };
  1249. })(this));
  1250. return false;
  1251. };
  1252. PluginList.prototype.handleDeleteClick = function(e) {
  1253. var node, plugin;
  1254. node = e.currentTarget;
  1255. plugin = node["data-plugin"];
  1256. if (plugin.loaded) {
  1257. Page.cmd("wrapperNotification", ["info", "You can only delete plugin that are not currently active"]);
  1258. return false;
  1259. }
  1260. node.classList.add("loading");
  1261. Page.cmd("wrapperConfirm", ["Delete " + plugin.name + " plugin?", "Delete"], (function(_this) {
  1262. return function(res) {
  1263. if (!res) {
  1264. node.classList.remove("loading");
  1265. return false;
  1266. }
  1267. return Page.cmd("pluginRemove", [plugin.source, plugin.inner_path], function(res) {
  1268. if (res === "ok") {
  1269. Page.cmd("wrapperNotification", ["done", "Plugin " + plugin.name + " deleted"]);
  1270. Page.updatePlugins();
  1271. } else {
  1272. Page.cmd("wrapperNotification", ["error", res.error]);
  1273. }
  1274. return node.classList.remove("loading");
  1275. });
  1276. };
  1277. })(this));
  1278. return false;
  1279. };
  1280. PluginList.prototype.render = function() {
  1281. return h("div.plugins", this.plugins.map((function(_this) {
  1282. return function(plugin) {
  1283. var base, descr, enabled_default, is_changed, is_pending, marker_title, ref, tag_delete, tag_source, tag_update, tag_version;
  1284. if (!plugin.info) {
  1285. return;
  1286. }
  1287. descr = plugin.info.description;
  1288. if ((base = plugin.info)["default"] == null) {
  1289. base["default"] = "enabled";
  1290. }
  1291. if (plugin.info["default"]) {
  1292. descr += " (default: " + plugin.info["default"] + ")";
  1293. }
  1294. tag_version = "";
  1295. tag_source = "";
  1296. tag_delete = "";
  1297. if (plugin.source !== "builtin") {
  1298. tag_update = "";
  1299. if ((ref = plugin.site_info) != null ? ref.rev : void 0) {
  1300. if (plugin.site_info.rev > plugin.info.rev) {
  1301. tag_update = h("a.version-update.button", {
  1302. href: "#Update+plugin",
  1303. onclick: _this.handleUpdateClick,
  1304. "data-plugin": plugin
  1305. }, "Update to rev" + plugin.site_info.rev);
  1306. }
  1307. } else {
  1308. tag_update = h("span.version-missing", "(unable to get latest vesion: update site missing)");
  1309. }
  1310. tag_version = h("span.version", ["rev" + plugin.info.rev + " ", tag_update]);
  1311. tag_source = h("div.source", [
  1312. "Source: ", h("a", {
  1313. "href": "/" + plugin.source,
  1314. "target": "_top"
  1315. }, plugin.site_title ? plugin.site_title : plugin.source), " /" + plugin.inner_path
  1316. ]);
  1317. tag_delete = h("a.delete", {
  1318. "href": "#Delete+plugin",
  1319. onclick: _this.handleDeleteClick,
  1320. "data-plugin": plugin
  1321. }, "Delete plugin");
  1322. }
  1323. enabled_default = plugin.info["default"] === "enabled";
  1324. if (plugin.enabled !== plugin.loaded || plugin.updated) {
  1325. marker_title = "Change pending";
  1326. is_pending = true;
  1327. } else {
  1328. marker_title = "Changed from default status (click to reset to " + plugin.info["default"] + ")";
  1329. is_pending = false;
  1330. }
  1331. is_changed = plugin.enabled !== enabled_default && plugin.owner === "builtin";
  1332. return h("div.plugin", {
  1333. key: plugin.name
  1334. }, [
  1335. h("div.title", [h("h3", [plugin.name, tag_version]), h("div.description", [descr, tag_source, tag_delete])]), h("div.value.value-right", h("div.checkbox", {
  1336. onclick: _this.handleCheckboxChange,
  1337. "data-plugin": plugin,
  1338. classes: {
  1339. checked: plugin.enabled
  1340. }
  1341. }, h("div.checkbox-skin")), h("a.marker", {
  1342. href: "#Reset",
  1343. title: marker_title,
  1344. onclick: _this.handleResetClick,
  1345. "data-plugin": plugin,
  1346. classes: {
  1347. visible: is_pending || is_changed,
  1348. pending: is_pending
  1349. }
  1350. }, "\u2022"))
  1351. ]);
  1352. };
  1353. })(this)));
  1354. };
  1355. return PluginList;
  1356. })(Class);
  1357. window.PluginList = PluginList;
  1358. }).call(this);
  1359. /* ---- UiPluginManager.coffee ---- */
  1360. (function() {
  1361. var UiPluginManager,
  1362. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  1363. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  1364. hasProp = {}.hasOwnProperty;
  1365. window.h = maquette.h;
  1366. UiPluginManager = (function(superClass) {
  1367. extend(UiPluginManager, superClass);
  1368. function UiPluginManager() {
  1369. this.renderBottomRestart = bind(this.renderBottomRestart, this);
  1370. this.handleRestartClick = bind(this.handleRestartClick, this);
  1371. this.render = bind(this.render, this);
  1372. this.createProjector = bind(this.createProjector, this);
  1373. this.updatePlugins = bind(this.updatePlugins, this);
  1374. this.onOpenWebsocket = bind(this.onOpenWebsocket, this);
  1375. return UiPluginManager.__super__.constructor.apply(this, arguments);
  1376. }
  1377. UiPluginManager.prototype.init = function() {
  1378. this.plugin_list_builtin = new PluginList();
  1379. this.plugin_list_custom = new PluginList();
  1380. this.plugins_changed = null;
  1381. this.need_restart = null;
  1382. return this;
  1383. };
  1384. UiPluginManager.prototype.onOpenWebsocket = function() {
  1385. this.cmd("wrapperSetTitle", "Plugin manager - ZeroNet");
  1386. this.cmd("serverInfo", {}, (function(_this) {
  1387. return function(server_info) {
  1388. return _this.server_info = server_info;
  1389. };
  1390. })(this));
  1391. return this.updatePlugins();
  1392. };
  1393. UiPluginManager.prototype.updatePlugins = function(cb) {
  1394. return this.cmd("pluginList", [], (function(_this) {
  1395. return function(res) {
  1396. var item, plugins_builtin, plugins_custom;
  1397. _this.plugins_changed = (function() {
  1398. var i, len, ref, results;
  1399. ref = res.plugins;
  1400. results = [];
  1401. for (i = 0, len = ref.length; i < len; i++) {
  1402. item = ref[i];
  1403. if (item.enabled !== item.loaded || item.updated) {
  1404. results.push(item);
  1405. }
  1406. }
  1407. return results;
  1408. })();
  1409. plugins_builtin = (function() {
  1410. var i, len, ref, results;
  1411. ref = res.plugins;
  1412. results = [];
  1413. for (i = 0, len = ref.length; i < len; i++) {
  1414. item = ref[i];
  1415. if (item.source === "builtin") {
  1416. results.push(item);
  1417. }
  1418. }
  1419. return results;
  1420. })();
  1421. _this.plugin_list_builtin.plugins = plugins_builtin.sort(function(a, b) {
  1422. return a.name.localeCompare(b.name);
  1423. });
  1424. plugins_custom = (function() {
  1425. var i, len, ref, results;
  1426. ref = res.plugins;
  1427. results = [];
  1428. for (i = 0, len = ref.length; i < len; i++) {
  1429. item = ref[i];
  1430. if (item.source !== "builtin") {
  1431. results.push(item);
  1432. }
  1433. }
  1434. return results;
  1435. })();
  1436. _this.plugin_list_custom.plugins = plugins_custom.sort(function(a, b) {
  1437. return a.name.localeCompare(b.name);
  1438. });
  1439. _this.projector.scheduleRender();
  1440. return typeof cb === "function" ? cb() : void 0;
  1441. };
  1442. })(this));
  1443. };
  1444. UiPluginManager.prototype.createProjector = function() {
  1445. this.projector = maquette.createProjector();
  1446. this.projector.replace($("#content"), this.render);
  1447. return this.projector.replace($("#bottom-restart"), this.renderBottomRestart);
  1448. };
  1449. UiPluginManager.prototype.render = function() {
  1450. var ref;
  1451. if (!this.plugin_list_builtin.plugins) {
  1452. return h("div.content");
  1453. }
  1454. return h("div.content", [h("div.section", [((ref = this.plugin_list_custom.plugins) != null ? ref.length : void 0) ? [h("h2", "Installed third-party plugins"), this.plugin_list_custom.render()] : void 0, h("h2", "Built-in plugins"), this.plugin_list_builtin.render()])]);
  1455. };
  1456. UiPluginManager.prototype.handleRestartClick = function() {
  1457. this.restart_loading = true;
  1458. setTimeout(((function(_this) {
  1459. return function() {
  1460. return Page.cmd("serverShutdown", {
  1461. restart: true
  1462. });
  1463. };
  1464. })(this)), 300);
  1465. Page.projector.scheduleRender();
  1466. return false;
  1467. };
  1468. UiPluginManager.prototype.renderBottomRestart = function() {
  1469. var ref;
  1470. return h("div.bottom.bottom-restart", {
  1471. classes: {
  1472. visible: (ref = this.plugins_changed) != null ? ref.length : void 0
  1473. }
  1474. }, h("div.bottom-content", [
  1475. h("div.title", "Some plugins status has been changed"), h("a.button.button-submit.button-restart", {
  1476. href: "#Restart",
  1477. classes: {
  1478. loading: this.restart_loading
  1479. },
  1480. onclick: this.handleRestartClick
  1481. }, "Restart ZeroNet client")
  1482. ]));
  1483. };
  1484. return UiPluginManager;
  1485. })(ZeroFrame);
  1486. window.Page = new UiPluginManager();
  1487. window.Page.createProjector();
  1488. }).call(this);