Best JavaScript code snippet using appium-xcuitest-driver
studio.prc.js
Source:studio.prc.js
1if (typeof module !== 'undefined') {2 var studio = require ('./studio') . studio;3 var prolog = require ('./prolog') . prolog;4}5studio . setResource (['prolog', 'studio'],6function (root, directory) {7 var list = new function () {8 this . code = function (el) {9 if (el . type === 0) {root . log (root . list () . join (' ')); return true;}10 if (el . type === 2) {11 el . type = 0;12 var l = root . list ();13 for (var ind in l) el = el . setNativePair (l [ind]);14 return true;15 }16 if (el . type === 1) {17 var first = el . left;18 if (first . type === 2) {first . setNative (root . list () . join (' ')); return true;}19 el = el . right;20 if (first . type === 3) {21 if (el . type === 0) {root . log (root . listAtom (first . left) . join ('\n')); return true;}22 if (el . type === 2) {23 el . type = 0;24 var clause = first . left . firstClause;25 while (clause !== null) {26 el . setPair ();27 clause . duplicate (el . left); el . left . left . left . setAtom (first . left);28 el = el . right;29 clause = clause . left . left . left;30 }31 return true;32 }33 if (el . type === 1) {el . left . setNative (root . listAtom (first . left) . join ('\n') + '\n'); return true;}34 }35 if (first . type === 6) {36 first = first . left;37 if (typeof (first) !== 'string') return false;38 if (el . type === 2) {39 el . type = 0;40 var directory = root . searchDirectory (first);41 if (directory === null) return false;42 var atom = directory . firstAtom;43 while (atom !== null) {el . setPair (); el . left . setAtom (atom); el = el . right; atom = atom . next;}44 return true;45 }46 var listing = root . list (first);47 if (listing === null) return false;48 if (el . type === 0) {root . log (listing . join (' ')); return true;}49 if (el . type === 1) {el . left . setNative (listing . join (' ')); return true;}50 }51 }52 return false;53 };54 };55 var pp = new function () {56 this . code = function (el) {57 var out = '';58 while (el . type === 1) {out += root . getValue (el . left); el = el . right;}59 root . log (out);60 return true;61 };62 };63 var sum = new function () {64 this . code = function (el) {65 if (! el . type === 1) return false;66 var e1 = el . left; el = el . right; if (! el . type === 1) return false;67 var e2 = el . left; el = el . right;68 var e3 = el . type === 1 ? el . left : el;69 if (e1 . type === 6) {70 if (e2 . type === 6) {e3 . setNative (e1 . left + e2 . left); return true;}71 if (e2 . type === 3) {e3 . setNative (e1 . left + e2 . left . name); return true;}72 }73 if (e1 . type === 3) {74 if (e2 . type === 6) {e3 . setNative (e1 . left . name + e2 . left); return true;}75 if (e2 . type === 3) {e3 . setNative (e1 . left . name + e2 . left . name); return true;}76 }77 if (e3 . type === 6) {78 if (e2 . type === 6) {e1 . setNative (Number (e3 . left) - Number (e2 . left)); return true;}79 if (e1 . type === 6) {e2 . setNative (Number (e3 . left) - Number (e1 . left)); return true;}80 }81 return false;82 };83 };84 var add = new function () {85 this . code = function (el) {86 if (el . type !== 1) return false;87 var result = null, sum = 0;88 if (el . left . type === 2) {result = el . left; el = el . right; if (el . type !== 1) {result . setNative (0); return true;}}89 switch (el . left . type) {90 case 6: sum = el . left . left; el = el . right; break;91 case 3: sum = el . left . left . name; el = el . right; break;92 default: break;93 }94 while (el . type === 1) {95 switch (el . left . type) {96 case 6: sum += el . left . left; break;97 case 1:98 var sub = 1, ell = el . left;99 while (ell . type === 1) {sub *= Number (ell . left . left); ell = ell . right;}100 sum += sub;101 break;102 case 3: sum += el . left . left . name; break;103 case 2: el . left . setNative (sum); break;104 default: break;105 }106 el = el . right;107 }108 if (result === null) return true;109 result . setNative (sum === null ? 0 : sum); return true;110 };111 };112 var mult = new function () {113 this . code = function (el) {114 if (! el . type === 1) return false;115 var result = null, ret = 1;116 if (el . left . type === 2) {result = el . left; el = el . right;}117 while (el . type === 1) {118 switch (el . left . type) {119 case 6: ret *= el . left . left; break;120 case 2: el . left . setNative (ret); break;121 default: break;122 }123 el = el . right;124 }125 if (result === null) return true;126 result . setNative (ret); return true;127 };128 };129 var addd = function (delta) {130 this . code = function (el) {131 if (el . type !== 1) return false;132 var left = el . left, ret = NaN;133 switch (left . type) {134 case 6: ret = left . left + delta; break;135 case 3: ret = left . left . name + delta; break;136 default: break;137 }138 el = el . right; if (el . type === 1) el = el . left;139 el . setNative (ret); return true;140 };141 };142 var add1 = new addd (1), sub1 = new addd (-1);143 var zero_param = function (value) {144 this . code = function (el) {if (el . type === 1) el = el . left; el . setNative (value); return true;};145 };146 var one_param = function (f, rev) {147 this . code = function (el) {148 if (el . type !== 1) return false;149 var a = el . left; el = el . right; if (el . type === 1) el = el . left;150 if (a . type === 6) {el . setNative (f (a . left)); return true;}151 if (el . type === 6) {a . setNative (rev (el . left)); return true;}152 return false;153 };154 };155 var logical_one_param = function (f) {156 this . code = function (el) {157 if (el . type !== 1) return false;158 var a = el . left; el = el . right; if (el . type === 1) el = el . left;159 switch (a . type) {160 case 6: el . setNative (f (a . left)); return true;161 case 3: el . setNative (f (a . left . name)); return true;162 default: break;163 }164 return false;165 };166 };167 var two_params = function (f, rev, esc) {168 this . code = function (el) {169 if (el . type !== 1) return false;170 var a = el . left; el = el . right; if (el . type !== 1) return false;171 var n = el . left; el = el . right; if (el . type === 1) el = el . left;172 if (a . type === 6) {173 if (n . type === 6) {el . setNative (f (a . left, n . left)); return true;}174 if (el . type === 6) {n . setNative (rev (a . left, el . left)); return true;}175 }176 if (n . type === 6) {a . setNative (esc (n . left, el . left)); return true;}177 };178 };179 var logical_two_params = function (f) {180 this . code = function (el) {181 if (el . type !== 1) return false;182 var a = el . left; if (a . type !== 6) return false;183 el = el . right; if (el . type !== 1) return false;184 var b = el . left; if (b . type !== 6) return false;185 el = el . right; if (el . type === 1) el = el . left;186 el . setNative (f (a . left, b . left)); return true;187 };188 };189 var comparator = function (f) {190 this . code = function (el) {191 if (el . type !== 1) return el . type === 0;192 var first = el . left;193 switch (first . type) {194 case 6: first = first . left; break;195 case 3: first = first . left . name; break;196 default: return false;197 }198 el = el . right;199 while (el . type === 1) {200 var next = el . left;201 switch (next . type) {202 case 6: next = next . left; break;203 case 3: next = next . left . name; break;204 default: return false;205 }206 if (! f (first, next)) return false;207 first = next;208 el = el . right;209 }210 return true;211 };212 };213 var and = new logical_two_params (function (a, b) {return a & b;});214 var or = new logical_two_params (function (a, b) {return a | b;});215 var xor = new logical_two_params (function (a, b) {return a ^ b;});216 var shiftl = new logical_two_params (function (a, b) {return a << b;});217 var shiftr = new logical_two_params (function (a, b) {return a >> b;});218 var shiftrr = new logical_two_params (function (a, b) {return a >>> b;});219 var neg = new logical_one_param (function (a) {return ~ a;});220 var greater = new comparator (function (a, b) {return a > b;});221 var greater_eq = new comparator (function (a, b) {return a >= b;});222 var less = new comparator (function (a, b) {return a < b;});223 var less_eq = new comparator (function (a, b) {return a <= b;});224 var sub = {225 code: function (el) {226 if (el . type !== 1) return false;227 var a = el . left; el = el . right;228 if (el . type !== 1) {229 if (a . type === 6) {el . setNative (- a . left); return true;}230 if (el . type === 6) {a . setNative (- el . left); return true;}231 return false;232 }233 var b = el . left; el = el . right;234 if (el . type === 0) {235 if (a . type === 6) {b . setNative (- a . left); return true;}236 if (b . type === 6) {a . setNative (- b . left); return true;}237 }238 if (el . type === 1) el = el . left;239 if (a . type === 6) {240 if (b . type === 6) {el . setNative (a . left - b . left); return true;}241 if (el . type === 6) {n . setNative (a . left - el . left); return true;}242 }243 if (b . type === 6) {a . setNative (b . left + el . left); return true;}244 }245 };246 var divmod = {247 code: function (el) {248 if (el . type !== 1) return false;249 var a = el . left; if (a . type !== 6) return false; a = a . left; el = el . right; if (el . type !== 1) return false;250 var b = el . left; if (b . type !== 6) return false; b = b . left; el = el . right;251 if (el . type !== 1) {el . setNative (a % b); return true;}252 el . left . setNative (a % b); el = el . right;253 if (el . type === 1) el . left . setNative (Math . trunc (a / b));254 else if (el . type !== 0) el . setNative (Math . trunc (a / b));255 return true;256 }257 };258 var comparator_runner = function (f) {259 this . code = function (el) {260 if (el . type !== 1) return false;261 var ret = el . left; el = el . right; if (el . type !== 1) return false;262 var comp = el . left; el = el . right;263 while (el . type === 1) {264 var e = el . left;265 switch (e . type) {266 case 6:267 switch (comp . type) {268 case 6: if (f (comp . left, e . left)) comp = e; break;269 case 3: if (f (comp . left . name, e . left)) comp = e; break;270 default: return false;271 }272 break;273 case 3:274 switch (comp . type) {275 case 6: if (f (comp . left, e . left . name)) comp = e; break;276 case 3: if (f (comp . left . name, e . left . name)) comp = e; break;277 default: return false;278 }279 break;280 default: return false;281 }282 el = el . right;283 }284 ret . type = comp . type;285 ret . left = comp . left;286 return true;287 };288 };289 var rnd = new function () {290 this . code = function (el) {291 var params = [];292 var ret = null;293 while (el . type === 1) {294 switch (el . left . type) {295 case 2: ret = el . left; break;296 case 6: params . push (el . left . left);297 default: break;298 }299 el = el . right;300 }301 if (ret === null) return false;302 switch (params . length) {303 case 0: ret . setNative (Math . random ()); return true;304 case 1: ret . setNative (Math . random () + params [0]); return true;305 case 2: ret . setNative (Math . random () * (params [1] - params [0]) + params [0]); return true;306 default: break;307 }308 return false;309 };310 };311 var random_permutation = {312 code: function (el) {313 if (el . type !== 1) return false;314 var a = el . left; el = el . right;315 if (a . type === 1) {316 var accu = [];317 while (a . type === 1) {accu . push (a . left); a = a . right;}318 studio . random_permutation (accu);319 if (el . type === 1) el = el . left;320 el . type = 0;321 for (var ind in accu) {el . setPair (); accu [ind] . duplicate (el . left); el = el . right;}322 return true;323 }324 if (a . type === 0) {if (el . type === 1) el = el . left; el . type = 0; return true;}325 if (a . type === 6) {326 a = a . left; if (typeof (a) !== 'number') return false;327 if (el . type !== 1) return false;328 var b = el . left; if (b . type !== 6) return false; b = b . left; if (typeof (b) !== 'number') return false;329 el = el . right; if (el . type !== 1) return false;330 var c = el . left; if (c . type !== 6) return false; c = c . left; if (typeof (c) !== 'number') return false;331 el = el . right; if (el . type === 1) el = el . left;332 var accu = [];333 for (var ind = 0; ind < b; ind++) accu . push (a + ind * c);334 studio . random_permutation (accu);335 el . type = 0;336 for (var ind in accu) {el . setPair (); el . left . setNative (accu [ind]); el = el . right;}337 return true;338 }339 return false;340 }341 };342 var stack = function (method) {343 var stacker = function (atom) {344 var q = [];345 this . code = function (el) {346 if (el . type === 0) return atom . setMachine (null);347 while (el . type === 1) {348 var left = el . left;349 if (left . type === 2) {var ell = q [method] (); if (ell === undefined) return false; ell . duplicate (left);}350 else q . push (left);351 el = el . right;352 }353 if (el . type === 2) {354 el . type = 0;355 for (var ind in q) {el . setPair (); q [ind] . duplicate (el . left); el = el . right;}356 }357 return true;358 };359 };360 this . code = function (el) {361 if (el . type === 1) el = el . left;362 if (el . type === 2) el . setAtom (new prolog . Atom ());363 if (el . type !== 3) return false;364 if (el . left . machine !== null) return false;365 return el . left . setMachine (new stacker (el . left));366 };367 };368 var accumulator = new function () {369 var accu = function (atom) {370 var accu = new prolog . Element ();371 this . code = function (el, resolution) {372 if (el . type === 0) return atom . setMachine (null);373 while (el . type === 1) {374 resolution . reset ();375 var e = new prolog . Element ();376 e . type = 1;377 e . left = resolution . match_product (el . left, true);378 e . right = resolution . match_product (accu, false);379 accu = e;380 el = el . right;381 }382 if (el . type === 2) accu . duplicate (el);383 return true;384 };385 };386 this . code = function (el) {387 if (el . type === 1) el = el . left;388 if (el . type === 2) el . setAtom (new prolog . Atom ());389 if (el . type !== 3) return false;390 if (el . left . machine !== null) return false;391 return el . left . setMachine (new accu (el . left));392 };393 };394 var constant = new function () {395 var constantor = function (atom, value) {396 this . code = function (el) {397 if (el . type === 0) return atom . setMachine (null);398 if (el . type === 1) el = el . left;399 value . duplicate (el);400 return true;401 };402 };403 this . code = function (el) {404 if (el . type !== 1) return false;405 var atom = el . left;406 if (atom . type === 2) atom . setAtom (new prolog . Atom ());407 if (atom . type !== 3 || atom . left . machine !== null) return false;408 el = el . right; if (el . type === 1) el = el . left;409 return atom . left . setMachine (new constantor (atom, el));410 };411 };412 var variable = new function () {413 var variabler = function (atom, value) {414 this . code = function (el) {415 if (el . type === 1) {el . left . duplicate (value); return true;}416 if (el . type === 2) {value . duplicate (el); return true;}417 if (el . type === 0) return atom . setMachine (null);418 return false;419 };420 };421 this . code = function (el) {422 var atom = null;423 if (el . type === 1) {atom = el . left; el = el . right; if (el . type === 1) el = el . left;} else atom = el;424 if (atom . type === 2) atom . setAtom (new prolog . Atom);425 if (atom . left . machine !== null) return false;426 return atom . left . setMachine (new variabler (atom . left, atom === el ? new prolog . Element () : el));427 };428 // [VARIABLE : atom] [VARIABLE atom] [VARIABLE atom : value] [VARIABLE atom value]429 };430 var array = new function () {431 var arrayer = function (atom) {432 var content = {};433 this . code = function (el) {434 if (el . type === 0) return atom . setMachine (null);435 var keys = [];436 var ret = null;437 var key;438 while (el . type === 1) {439 key = el . left;440 switch (key . type) {441 case 6: keys . push (key . left); break;442 case 3: keys . push (key . left . name); break;443 case 2: if (ret !== null) return false; ret = key; break;444 default: return false;445 }446 el = el . right;447 }448 switch (el . type) {449 case 0: break;450 case 6: keys . push (el . left); break;451 case 3: keys . push (el . left . name); break;452 case 2: if (ret !== null) return false; ret = el; break;453 default: return false;454 }455 if (ret !== null) key = keys . pop (); else {ret = key; keys . pop (); key = keys . pop ();}456 var selector = content;457 for (var ind in keys) {458 if (selector [keys [ind]] === undefined) selector = (selector [keys [ind]] = {});459 else selector = selector [keys [ind]];460 }461 if (ret . type === 2) selector [key] . duplicate (ret);462 else selector [key] = ret;463 return true;464 };465 };466 this . code = function (el) {467 if (el . type === 1) el = el . left;468 if (el . type === 2) el . setAtom (new prolog . Atom ());469 if (el . type !== 3 || el . left . machine !== null) return false;470 return el . left . setMachine (new arrayer (el . left));471 };472 };473 var text_list = {474 code: function (el) {475 if (el . type !== 1) return false;476 var text = el . left; el = el . right;477 if (text . type === 2) {478 if (el . type === 1 && el . left . type === 1) el = el . left;479 var ret = [];480 while (el . type === 1) {if (el . left . type === 6) ret . push (Number (el . left . left)); el = el . right;}481 text . setNative (String . fromCharCode . apply (this, ret));482 return true;483 }484 if (text . type === 3) text = text . left . name;485 else if (text . type === 6) text = String (text . left);486 else return false;487 if (el . type === 1) el = el . left;488 el . type = 0;489 for (var ind in text) el = el . setNativePair (text . charCodeAt (ind));490 return true;491 }492 };493 var text_term = {494 code: function (el) {495 if (el . type !== 1) return false;496 var text = el . left;497 el = el . right;498 if (text . type === 6 && typeof (text . left) === 'string') {499 var reader = new prolog . Reader (root, text . left);500 el . type = 0;501 var e = reader . getElement ();502 while (e !== null) {503 el . type = 1;504 el . left = e;505 el . right = new prolog . Element ();506 el = el . right;507 reader . vars = [];508 e = reader . getElement ();509 }510 return true;511 }512 var area = [];513 while (el . type === 1) {area . push (root . getValue (el . left)); el = el . right;}514 text . setNative (area . join (' '));515 return true;516 }517 };518 var e32 = {519 code: function (el) {520 if (el . type !== 1) return false;521 var e = el . left;522 if (e . type === 6) {523 e = Number (e . left);524 if (e === Infinity || e === -Infinity || Number . isNaN (e)) return false;525 el = el . right;526 while (e !== 0) {527 el = el . setNativePair (e & 0xff);528 e = e >>> 8;529 }530 return true;531 }532 el = el . right;533 var accu = 0;534 var shift = 0;535 while (el . type === 1) {536 var sub = el . left;537 if (sub . type === 6) {538 sub = sub . left;539 if (sub === Infinity || sub === -Infinity || Number . isNaN (sub)) return false;540 accu += sub << shift; shift += 8;541 }542 el = el . right;543 }544 e . setNative (accu);545 return true;546 }547 };548 var write = {549 code: function (el) {550 var params = [];551 var accu = []552 while (el . type === 1) {553 var e = el . left;554 if (e . type === 6) accu . push (typeof (e . left) === 'number' ? String . fromCharCode (e . left) : e . left);555 if (e . type === 3) accu . push (e . left . name);556 if (e . type === 2) accu . push ('%c');557 if (e . type === 4) {params . push (accu . join ('')); accu = [];}558 while (e . type === 1) {accu . push (root . getValue (e . left)); e = e . right;}559 el = el . right;560 }561 params . push (accu . join (''));562 root . log . apply (this, params);563 return true;564 }565 };566 var cd = {567 code: function (el) {568 while (el . type === 1) {569 var e = el . left;570 switch (e . type) {571 case 0: studio . cd (); break;572 case 3: studio . cd (e . left . name); break;573 case 6: studio . cd (e . left); break;574 case 2: e . setNative (studio . pwd ()); break;575 }576 el = el . right;577 }578 if (el . type === 2) el . setNative (studio . pwd ());579 return true;580 }581 };582 var search_directories = {583 code: function (el) {584 if (el . type === 0) {root . log ("SEARCH DIRECTORIES:"); root . log (studio . search ()); return true;}585 if (el . type === 2) {586 var searches = studio . search ();587 el . type = 0;588 for (var ind in searches) el = el . setNativePair (searches [ind]);589 return true;590 }591 while (el . type === 1) {592 var e = el . left;593 if (e . type === 0) studio . eraseSearch ();594 if (e . type === 6) studio . search (e . left);595 el = el . right;596 }597 return true;598 }599 };600 var file_writer = new function () {601 var writer = function (atom, file_name) {602 var text = [];603 this . code = function (el) {604 if (el . type === 0) {studio . writeFile (file_name, text . join ('')); return atom . setMachine (null);}605 while (el . type === 1) {606 var e = el . left;607 if (e . type === 6) text . push (typeof (e . left) === 'number' ? String . fromCharCode (e . left) : e . left);608 if (e . type === 3) text . push (e . left . name);609 while (e . type === 1) {text . push (root . getValue (e . left)); e = e . right;}610 el = el . right;611 }612 return true;613 };614 };615 this . code = function (el) {616 var atom = null, file_name = null;617 while (el . type === 1) {618 var left = el . left;619 if (left . type === 3) atom = left;620 if (left . type === 2) {atom = left; atom . setAtom (new prolog . Atom ());}621 if (left . type === 6) file_name = String (left . left);622 el = el . right;623 }624 if (atom === null || file_name === null || atom . left . machine !== null) return false;625 return atom . left . setMachine (new writer (atom . left, file_name));626 };627 };628 var file_reader = new function () {629 var reader = function (atom, content) {630 var fr = new prolog . Reader (root, content);631 this . code = function (el) {632 if (el . type === 0) return atom . setMachine (null);633 while (el . type === 1) {634 var e = fr . getElement ();635 if (e === null) {atom . setMachine (null); return false;}636 e . duplicate (el . left);637 el = el . right;638 }639 return true;640 };641 };642 this . code = function (el) {643 var atom = null, file_name = null;644 while (el . type === 1) {645 var left = el . left;646 if (left . type === 3) atom = left;647 if (left . type === 2) {atom = left; atom . setAtom (new prolog . Atom ());}648 if (left . type === 6) file_name = String (left . left);649 el = el . right;650 }651 if (atom === null || file_name === null || atom . left . machine !== null) return false;652 var content = studio . readFile (file_name);653 if (content === null) return false;654 return atom . left . setMachine (new reader (atom . left, content));655 };656 };657 var create_file = {658 code: function (el) {659 if (el . type !== 1) return false;660 var file_name = el . left; if (file_name . type !== 6) return false; file_name = String (file_name . left);661 el = el . right;662 var text = [];663 while (el . type === 1) {664 var e = el . left;665 if (e . type === 6) text . push (typeof (e . left) === 'number' ? String . fromCharCode (e . left) : e . left);666 if (e . type === 3) text . push (e . left . name);667 while (e . type === 1) {text . push (root . getValue (e . left)); e = e . right;}668 el = el . right;669 }670 studio . writeFile (file_name, text . join (''));671 return true;672 }673 };674 var open_file = {675 code: function (el) {676 if (el . type !== 1) return false;677 var file_name = el . left; if (file_name . type !== 6) return false; file_name = String (file_name . left);678 el = el . right;679 if (el . type === 1) el = el . left;680 var content = studio . readFile (file_name);681 if (content === null) return false;682 el . setNative (content);683 return true;684 }685 };686 var erase_file = {687 code: function (el) {688 if (el . type === 1) el = el . left;689 if (el . type !== 6) return false;690 studio . erase_file (String (el . left));691 return true;692 }693 };694 var importer = function (no_overwrite) {695 this . code = function (el) {696 var command = new prolog . Element ();697 while (el . type === 1) {698 var e = el . left;699 if (e . type === 6) command = root . load (String (e . left), no_overwrite);700 if (command === null) return false;701 el = el . right;702 }703 if (el . type === 2) command . duplicate (el);704 return true;705 };706 };707 var timestamp = {708 code: function (el) {709 if (el . type !== 1) el . setPair ();710 var stamp = el . left; el = el . right;711 if (el . type !== 1) el . setPair ();712 var year = el . left; el = el . right;713 if (el . type !== 1) el . setPair ();714 var month = el . left; el = el . right;715 if (el . type !== 1) el . setPair ();716 var day = el . left; el = el . right;717 if (el . type !== 1) el . setPair ();718 var week_day = el . left; el = el . right;719 if (el . type !== 1) el . setPair ();720 var hour = el . left; el = el . right;721 if (el . type !== 1) el . setPair ();722 var minute = el . left; el = el . right;723 if (el . type !== 1) el . setPair ();724 var second = el . left; el = el . right;725 if (el . type !== 1) el . setPair ();726 var millisecond = el . left;727 if (year . type === 2 || year . type === 0) {728 var date = new Date ();729 if (stamp . type === 6) date . setTime (Number (stamp . left));730 else stamp . setNative (date . getTime ());731 year . setNative (date . getFullYear ());732 month . setNative (date . getMonth () + 1);733 day . setNative (date . getDate ());734 week_day . setNative (date . getDay ());735 hour . setNative (date . getHours ());736 minute . setNative (date . getMinutes ());737 second . setNative (date . getSeconds ());738 millisecond . setNative (date . getMilliseconds ());739 return true;740 }741 var date = new Date ();742 if (year . type === 6) date . setFullYear (Number (year . left));743 if (month . type === 6) date . setMonth (Number (month . left) - 1);744 if (day . type === 6) date . setDate (Number (day . left));745 if (hour . type === 6) date . setHours (Number (hour . left));746 if (minute . type === 6) date . setMinutes (Number (minute . left));747 if (second . type === 6) date . setSeconds (Number (second . left));748 if (millisecond . type === 6) date . setMilliseconds (Number (millisecond . left));749 if (stamp . type !== 6) stamp . setNative (date . getTime ());750 if (year . type !== 6) year . setNative (date . getFullYear ());751 if (month . type !== 6) month . setNative (date . getMonth () + 1);752 if (day . type !== 6) day . setNative (date . getDate ());753 if (week_day . type !== 6) week_day . setNative (date . getDay ());754 if (hour . type !== 6) hour . setNative (date . getHours ());755 if (minute . type !== 6) minute . setNative (date . getMinutes ());756 if (second . type !== 6) second . setNative (date . getSeconds ());757 if (millisecond . type !== 6) millisecond . setNative (date . getMilliseconds ());758 return true;759 }760 };761 var delallcl = {762 code: function (el) {763 if (el . type === 1) el = el . left;764 if (el . type !== 3) return false;765 el = el . left; if (el . Protected || el . machine !== null) return false;766 el . firstClause = null; return true;767 }768 };769 var CL = {770 code: function (el) {771 var atom = null, index = null, clause = null;772 while (el . type === 1) {773 var e = el . left;774 if (e . type === 3) atom = e . left;775 if (e . type === 6) index = e;776 if (e . type === 2) {if (index === null) index = e; else clause = e;}777 if (e . type === 1) clause = e;778 el = el . right;779 }780 if (el . type === 3) atom = el . left;781 if (el . type === 6) index = el;782 if (el . type === 2) {if (index === null) index = el; else if (clause === null) clause = el;}783 if (atom === null || index === null) return false;784 if (clause === null) {index . setNative (atom . clauseCount ()); return true;}785 if (index . type === 6) {786 index = index . left;787 if (typeof (index) !== 'number' || index < 0) return false;788 var cl = atom . raw_clause_pointer (index);789 if (cl === null) return false;790 cl . duplicate (clause);791 clause . left . left . setAtom (atom);792 return true;793 }794 return false;795 }796 };797 var addcl = {798 code: function (el) {799 if (el . type !== 1) return false;800 var ind = el . left;801 if (ind . type === 1) {802 if (ind . left . type === 3) return el . duplicate () . attach ();803 el = el . right;804 if (el . type === 1) el = el . left;805 if (el . type === 6) return ind . duplicate () . attach (el . left);806 }807 if (ind . type !== 6) return false;808 el = el . right . duplicate ();809 if (el . attach (ind . left)) return true;810 if (el . type !== 1) return false;811 return el . left . attach (ind . left);812 }813 };814 var addcl0 = {815 code: function (el) {el = el . duplicate (); if (el . attach (0)) return true; if (el . type !== 1) return false; return el . left . attach (0);}816 };817 var DELCL = {818 code: function (el) {819 var atom = null, index = null;820 while (el . type === 1) {821 var e = el . left;822 if (e . type === 6) index = e . left;823 if (e . type === 3) atom = e . left;824 el = el . right;825 }826 if (atom === null || index === null) return false;827 return atom . delcl (index);828 }829 };830 var auto_atoms = {code: function (el) {root . auto_atoms = true; return true;}};831 var scripted_atoms = {code: function (el) {root . auto_atoms = false; return true;}};832 var create_atom = {833 code: function (el) {834 if (el . type === 3) return true;835 if (el . type === 2) {el . setAtom (new prolog . Atom ()); return true;}836 if (el . type !== 1) return false;837 var sub = el . left; el = el . right; if (el . type === 1) el = el . left;838 if (sub . type === 3) return true;839 if (sub . type === 2) {840 if (el . type === 6) {sub . setAtom (new prolog . Atom (el . left)); return true;}841 if (el . type === 0) {sub . setAtom (new prolog . Atom ()); return true;}842 }843 if (sub . type === 6) {844 if (el . type === 2) {el . setAtom (new prolog . Atom (sub . left)); return true;}845 if (el . type === 0) {if (typeof (sub . left) !== 'string') return false; root . createAtom (sub . left); return true;}846 }847 return false;848 }849 };850 var create_atoms = {851 code: function (el) {852 while (el . type === 1) {853 var e = el . left;854 if (e . type === 2) e . setAtom (new prolog . Atom ());855 else if (e . type !== 3) return false;856 el = el . right;857 }858 return true;859 }860 };861 var search_atom = function (search) {862 this . code = function (el) {863 var module = null, name = null, atom = null;864 while (el . type === 1) {865 var sub = el . left;866 if (sub . type === 6) {if (module === null) module = sub; else name = sub;} else if (sub . type === 2) atom = sub;867 el = el . right;868 }869 if (el . type === 6) {if (module === null) module = el; else name = el;} else if (el . type === 2) atom = el;870 if (atom === null) return false;871 if (module === null) {atom . setAtom (root . createAtom ()); return true;}872 if (name === null) {var sub = root [search] (module . left); if (sub === null) return false; atom . setAtom (sub); return true;}873 var sub = root [search] (name . left, module . left); if (sub === null) return false; atom . setAtom (sub); return true;874 };875 };876 var unique_atoms = new function () {877 var process = function (directory, atom) {878 var area = [];879 var dir = root . root;880 while (dir !== null) {881 var sub = dir . firstAtom;882 if (directory !== dir) {883 while (sub !== null) {if (sub !== atom && sub . name === atom . name) area . push ({atom: sub, directory: dir}); sub = sub . next;}884 }885 dir = dir . next;886 }887 return area;888 };889 var setArea = function (list, area) {890 for (var ind in area) {891 list . setPair ();892 list . left . setPair ();893 list . left . left . setAtom (area [ind] . atom);894 list . left . right . setPair ();895 list . left . right . left . setNative (area [ind] . directory . name);896 list = list . right;897 }898 };899 var writeArea = function (area) {for (var ind in area) {root . log ('@', area [ind] . directory . name, area [ind] . atom . name);}};900 this . code = function (el) {901 var list = null, atoms = [], directories = [];902 while (el . type === 1) {903 var e = el . left;904 switch (e . type) {905 case 2: list = e; break; case 3: atoms . push (e . left); break; case 6: directories . push (e . left); break; default: break;}906 el = el . right;907 }908 switch (el . type) {case 2: list = el; break; case 3: atoms . push (el . left); break; case 6: directories . push (el . left); break; default: break;}909 if (list !== null) list . type = 0;910 if (atoms . length < 1 && directories . length < 1) {911 var dir = root . root;912 var area = [];913 while (dir !== null) {914 var atom = dir . firstAtom;915 while (atom !== null) {916 area = area . concat (process (dir, atom));917 atom = atom . next;918 }919 dir = dir . next;920 }921 if (list !== null) {setArea (list, area); return true;}922 writeArea (area);923 return area . length < 1;924 }925 if (atoms . length > 0 && directories . length > 0) {926 var area = [];927 for (var ind in directories) {928 var dir = root . searchDirectory (directories [ind]);929 if (dir === null) return false;930 for (var sub in atoms) area = area . concat (process (dir, atoms [sub]));931 }932 if (list !== null) {setArea (list, area); return true;}933 writeArea (area);934 return area . length < 1;935 }936 if (atoms . length > 0) {937 var area = [];938 for (var ind in atoms) area = area . concat (process (null, atoms [ind]));939 if (list !== null) {setArea (list, area); return true;}940 writeArea (area);941 return area . length < 1;942 }943 if (directories . length > 0) {944 area = [];945 for (var ind in directories) {946 var dir = root . searchDirectory (directories [ind]);947 if (dir === null) return false;948 var atom = dir . firstAtom;949 while (atom !== null) {950 area = area . concat (process (dir, atom));951 atom = atom . next;952 }953 }954 if (list != null) {setArea (list, area); return true;}955 writeArea (area);956 return area . length < 1;957 }958 return false;959 };960 };961 var has_machine = {962 code: function (el) {963 if (el . type === 1) el = el . left;964 if (el . type === 3) return el . left . machine !== null;965 if (el . type === 6) {966 var dir = root . searchDirectory (el . left);967 if (dir === null) return false;968 return dir . service_class !== null;969 }970 return false;971 }972 };973 var remove_module = {974 code: function (el) {975 while (el . type === 1) {976 if (el . left . type !== 6 || ! root . drop (el . left . left)) return false;977 el = el . right;978 }979 return true;980 }981 };982 var create_module = {983 code: function (el) {984 if (el . type === 0) {root . close (); return true;}985 if (el . type === 1) el = el . left;986 if (el . type !== 6) return false;987 root . createDirectory (el . left);988 return true;989 }990 };991 var attach_service = {992 code: function (el) {993 if (el . type !== 1) return false;994 var name = el . left; if (name . type !== 6) return false; name = name . left; el = el . right;995 if (el . type === 0) {996 var service = studio . getService (name); if (service === null) return false;997 root . root . service_class = new service (root, root . root);998 return true;999 }1000 name = root . searchDirectory (name); if (name === null) return false;1001 if (el . type !== 1) return false;1002 var service = el . left; if (service . type !== 6) return false;1003 service = studio . getService (service . left); if (service === null) return false;1004 name . service_class = new service (root, name);1005 return true;1006 }1007 };1008 var Alert = {code: function (el) {if (el . type === 1) el = el . left; alert (el . type === 6 ? el . left : root . getValue (el)); return true;}};1009 var Confirm = {code: function (el) {if (el . type === 1) el = el . left; return confirm (el . type === 6 ? el . left: root . getValue (el));}};1010 var Prompt = {1011 code: function (el) {1012 var command = null, def = null, variable = null;1013 while (el . type === 1) {1014 var e = el . left;1015 if (e . type === 2) variable = e;1016 else {var msg = e . type === 6 ? e . left : root . getValue (e); if (command === null) command = msg; else def = msg;}1017 el = el . right;1018 }1019 var ret = def === null ? prompt (command) : prompt (command, def);1020 if (ret === null) return false;1021 if (variable !== null) variable . setNative (ret);1022 return true;1023 }1024 };1025 var ProcessTimeout_atom = root . search ('ProcessTimeout');1026 var timeouter = function (atom, clear, id) {1027 this . code = function (el) {clear (id); atom . setMachine (null); return true;}1028 };1029 var SetTimeout = function (set, clear) {1030 this . code = function (el) {1031 if (el . type !== 1) return false;1032 var interval = el . left; if (interval . type !== 6) return false; el = el . right;1033 if (el . type !== 1) return false;1034 var timeout = el . left; if (timeout . type !== 3 || timeout . left . machine !== null) return false;1035 return timeout . left . setMachine (new timeouter (timeout . left, clear, set (function () {root . resolution (el);}, interval . left)));1036 };1037 };1038 this . getNativeCode = function (name) {1039 switch (name) {1040 case 'list': return list;1041 case 'pp': return pp;1042 case 'write': return write;1043 case 'cd': return cd;1044 case 'search_directories': return search_directories;1045 case 'file_writer': return file_writer;1046 case 'file_reader': return file_reader;1047 case 'create_file': return create_file;1048 case 'open_file': return open_file;1049 case 'erase_file': return erase_file;1050 case 'import': return new importer (true);1051 case 'load': return new importer (false);1052 case 'remove_module': return remove_module;1053 case 'create_module': return create_module;1054 case 'attach_service': return attach_service;1055 case 'sum': return sum;1056 case 'add': return add;1057 case 'sub': return sub;1058 case 'mult': return mult;1059 case 'times': return new two_params (function (a, b) {return a * b;}, function (a, c) {return c / a;}, function (b, c) {return c / b;});1060 case 'div': return new two_params (function (a, b) {return a / b;}, function (a, c) {return a / c;}, function (b, c) {return b * c;});1061 case 'mod': return divmod;1062 case 'e': return new zero_param (Math . E);1063 case 'pi': return new zero_param (Math . PI);1064 case 'abs': return new logical_one_param (function (a) {return Math . abs (a);});1065 case 'trunc': return new logical_one_param (function (a) {return Math . trunc (a);});1066 case 'floor': return new logical_one_param (function (a) {return Math . floor (a);});1067 case 'ceil': return new logical_one_param (function (a) {return Math . ceil (a);});1068 case 'round': return new logical_one_param (function (a) {return Math . round (a);});1069 case 'add1': return add1;1070 case 'sub1': return sub1;1071 case 'and': return and;1072 case 'or': return or;1073 case 'xor': return xor;1074 case '<<': return shiftl;1075 case '>>': return shiftr;1076 case '>>>': return shiftrr;1077 case 'neg': return neg;1078 case 'degrad': return new one_param (function (a) {return a * Math . PI / 180;}, function (a) {return a * 180 / Math . PI;});1079 case 'sin': return new one_param (function (a) {return Math . sin (a);}, function (a) {return Math . asin (a);});1080 case 'cos': return new one_param (function (a) {return Math . cos (a);}, function (a) {return Math . acos (a);});1081 case 'tan': return new one_param (function (a) {return Math . tan (a);}, function (a) {return Math . atan (a);});1082 case 'cotan': return new one_param (function (a) {return 1 / Math . tan (a);}, function (a) {return Math . PI / 2 - Math . atan (a);});1083 case 'asin': return new one_param (function (a) {return Math . asin (a);}, function (a) {return Math . sin (a);});1084 case 'acos': return new one_param (function (a) {return Math . acos (a);}, function (a) {return Math . cos (a);});1085 case 'atan': return new one_param (function (a) {return Math . atan (a);}, function (a) {return Math . tan (a);});1086 case 'acotan': return new one_param (function (a) {return Math . PI / 2 - Math . atan (a);}, function (a) {return 1 / Math . tan (a);});1087 case 'atan2': return new logical_two_params (function (a, b) {return Math . atan2 (a, b);});1088 case 'pow': return new two_params (function (a, n) {return Math . pow (a, n);}, function (a, x) {return Math . log (x) / Math . log (a);}, function (n, x) {return Math . pow (x, 1 / n);});1089 case 'exp': return new one_param (function (n) {return Math . exp (n);}, function (x) {return Math . log (x);});1090 case 'log': return new two_params (function (a, x) {return Math . log (x) / Math . log (a);}, function (a, n) {return Math . pow (a, n);}, function (x, n) {return Math . pow (x, 1 / n);});1091 case 'log2': return new one_param (function (x) {return Math . log2 (x);}, function (n) {return Math . pow (2, n);});1092 case 'log10': return new one_param (function (x) {return Math . log10 (x);}, function (n) {return Math . pow (10, n);});1093 case 'ln': return new one_param (function (x) {return Math . log (x);}, function (n) {return Math . exp (n);});1094 case 'greater': return greater;1095 case 'greater_eq': return greater_eq;1096 case 'less': return less;1097 case 'less_eq': return less_eq;1098 case 'min': return new comparator_runner (function (a, b) {return a > b;});1099 case 'max': return new comparator_runner (function (a, b) {return a < b;});1100 case 'rnd': return rnd;1101 case 'series': return random_permutation;1102 case 'timestamp': return timestamp;1103 case 'alert': return Alert;1104 case 'confirm': return Confirm;1105 case 'prompt': return Prompt;1106 case 'setTimeout': return new SetTimeout (setTimeout, clearTimeout);1107 case 'setInterval': return new SetTimeout (setInterval, clearInterval);1108 case 'delallcl': return delallcl;1109 case 'CL': return CL;1110 case 'addcl': return addcl;1111 case 'addcl0': return addcl0;1112 case 'DELCL': return DELCL;1113 case 'auto_atoms': return auto_atoms;1114 case 'scripted_atoms': return scripted_atoms;1115 case 'create_atom': return create_atom;1116 case 'create_atoms': return create_atoms;1117 case 'search_atom': return new search_atom ('search');1118 case 'search_atom_c': return new search_atom ('searchC');1119 case 'unique_atoms': return unique_atoms;1120 case 'e32': return e32;1121 case 'atom?': return {code: function (el) {if (el . type === 1) el = el . left; return el . type === 3;}};1122 case 'integer?': return {code: function (el) {if (el . type === 1) el = el . left; return el . type === 6 && Number . isInteger (el . left);}};1123 case 'double?': return {code: function (el) {if (el . type === 1) el = el . left; return el . type === 6 && typeof (el . left) === 'number' && ! Number . isInteger (el . left);}};1124 case 'number?': return {code: function (el) {if (el . type === 1) el = el . left; return el . type === 6 && typeof (el . left) === 'number';}};1125 case 'text?': return {code: function (el) {if (el . type === 1) el = el . left; return el . type === 6 && typeof (el . left) === 'string';}};1126 case 'var?': return {code: function (el) {if (el . type === 1) el = el . left; return el . type === 2;}};1127 case 'head?': return {code: function (el) {if (el . type === 1) el = el . left; return el . type === 6;}};1128 case 'machine?': return has_machine;1129 case 'text_list': return text_list;1130 case 'text_term': return text_term;1131 case 'CONSTANT': return constant;1132 case 'VARIABLE': return variable;1133 case 'ACCUMULATOR': return accumulator;1134 case 'STACK': return new stack ('pop');1135 case 'QUEUE': return new stack ('shift');1136 case 'ARRAY': return array;1137 default: break;1138 }1139 return null;1140 };1141 var nav_atom = root . search ('navigator');1142 if (nav_atom !== null) {1143 if (typeof navigator !== 'undefined') {1144 for (var ind in navigator) {1145 nav = navigator [ind];1146 if (typeof (nav) === 'number' || typeof (nav) === 'string') {1147 var clause = new prolog . Element ();1148 clause . setPair ();1149 var el = clause . left;1150 el . setPair (); el . left . setAtom (nav_atom);1151 el = el . right; el . setPair (); el . left . setNative (ind);1152 el = el . right; el . setPair (); el . left . setNative (navigator [ind]);1153 clause . attach ();1154 }1155 }1156 }1157 }1158}1159);1160studio . setResource (['studio.prc'], `1161program studio #machine := ' prolog . studio '1162 [1163 e pi1164 abs trunc floor ceil round1165 add1 ++ sub1 --1166 and & or | xor ^ neg ~ << >> >>>1167 sum times add + sub - mult div mod %1168 degrad sin cos tan cotan asin acos atan acotan atan21169 pow exp log log2 log10 ln1170 rnd grnd series random_permutation1171 greater greater_eq less less_eq > >= => < <= =< min max1172 ; I/O1173 timestamp1174 operating_system implementation version navigator1175 command exit1176 list pp write1177 cd search_directories file_writer file_reader create_file open_file erase_file import load batch1178 remove_module create_module attach_service1179 ; JavaScript1180 alert confirm prompt Prompt setTimeout setInterval SetTimeout SetInterval1181 ; CLAUSE1182 delallcl CL cl addcl addcl0 DELCL delcl OVERWRITE overwrite1183 auto_atoms scripted_atoms unique_atoms create_atom create_atoms search_atom search_atom_c1184 ; TERM1185 e32 atom? integer? double? number? text? var? head? machine? text_list text_term1186 ; META1187 CONSTANT VARIABLE var ACCUMULATOR STACK QUEUE ARRAY1188 eq = <> !1189 ONE TRY PROBE SELECT LENGTH AT ONLIST INLIST NODUP1190 ALL APPEND REVERSE MAP MEMBER REPLACE1191 WHILE FOREVER forever REPEAT FOR IF inc dec1192 ISALL isall isallq isallr1193 not res1194 ]1195#machine list := 'list'1196#machine pp := 'pp'1197#machine write := 'write'1198#machine cd := 'cd'1199#machine search_directories := 'search_directories'1200#machine file_writer := 'file_writer'1201#machine file_reader := 'file_reader'1202#machine create_file := 'create_file'1203#machine open_file := 'open_file'1204#machine erase_file := 'erase_file'1205#machine import := 'import'1206#machine load := 'load'1207#machine remove_module := 'remove_module'1208#machine create_module := 'create_module'1209#machine attach_service := 'attach_service'1210#machine e := 'e'1211#machine pi := 'pi'1212#machine abs := 'abs'1213#machine trunc := 'trunc'1214#machine floor := 'floor'1215#machine ceil := 'ceil'1216#machine round := 'round'1217#machine add1 := 'add1'1218#machine ++ := 'add1'1219#machine sub1 := 'sub1'1220#machine -- := 'sub1'1221#machine sum := 'sum'1222#machine add := 'add'1223#machine + := 'add'1224#machine sub := 'sub'1225#machine - := 'sub'1226#machine mult := 'mult'1227#machine times := 'times'1228#machine div := 'div'1229#machine mod := 'mod'1230#machine % := 'mod'1231#machine and := 'and'1232#machine & := 'and'1233#machine or := 'or'1234#machine | := 'or'1235#machine xor := 'xor'1236#machine ^ := 'xor'1237#machine << := '<<'1238#machine >> := '>>'1239#machine >>> := '>>>'1240#machine neg := 'neg'1241#machine ~ := 'neg'1242#machine degrad := 'degrad'1243#machine sin := 'sin'1244#machine cos := 'cos'1245#machine tan := 'tan'1246#machine cotan := 'cotan'1247#machine asin := 'asin'1248#machine acos := 'acos'1249#machine atan := 'atan'1250#machine acotan := 'acotan'1251#machine atan2 := 'atan2'1252#machine pow := 'pow'1253#machine exp := 'exp'1254#machine log := 'log'1255#machine log2 := 'log2'1256#machine log10 := 'log10'1257#machine ln := 'ln'1258#machine rnd := 'rnd'1259#machine series := 'series'1260#machine random_permutation := 'series'1261#machine greater := 'greater'1262#machine > := 'greater'1263#machine greater_eq := 'greater_eq'1264#machine >= := 'greater_eq'1265#machine => := 'greater_eq'1266#machine less := 'less'1267#machine < := 'less'1268#machine less_eq := 'less_eq'1269#machine <= := 'less_eq'1270#machine =< := 'less_eq'1271#machine min := 'min'1272#machine max := 'max'1273#machine timestamp := 'timestamp'1274#machine alert := 'alert'1275#machine confirm := 'confirm'1276#machine prompt := 'prompt'1277#machine setTimeout := 'setTimeout'1278#machine setInterval := 'setInterval'1279#machine delallcl := 'delallcl'1280#machine CL := 'CL'1281#machine addcl := 'addcl'1282#machine addcl0 := 'addcl0'1283#machine DELCL := 'DELCL'1284#machine auto_atoms := 'auto_atoms'1285#machine scripted_atoms := 'scripted_atoms'1286#machine create_atom := 'create_atom'1287#machine create_atoms := 'create_atoms'1288#machine search_atom := 'search_atom'1289#machine search_atom_c := 'search_atom_c'1290#machine unique_atoms := 'unique_atoms'1291#machine e32 := 'e32'1292#machine atom? := 'atom?'1293#machine integer? := 'integer?'1294#machine double? := 'double?'1295#machine number? := 'number?'1296#machine text? := 'text?'1297#machine var? := 'var?'1298#machine head? := 'head?'1299#machine machine? := 'machine?'1300#machine text_list := 'text_list'1301#machine text_term := 'text_term'1302#machine CONSTANT := 'CONSTANT'1303#machine VARIABLE := 'VARIABLE'1304#machine ACCUMULATOR := 'ACCUMULATOR'1305#machine STACK := 'STACK'1306#machine QUEUE := 'QUEUE'1307#machine ARRAY := 'ARRAY'1308[[eq *x *x]]1309[[= *x *x]]1310[[<> *x *x] / fail]1311[[<> * *]]1312[[! : *x] *x / fail]1313[[! : *]]1314[[not : *x] *x / fail]1315[[not : *]]1316[[res : *command] : *command]1317[[ONE :*o][res :*o]/]1318[[ALL :*o][res : *o] fail]1319[[ALL :*]]1320[[TRY :*o]:*o]1321[[TRY :*o]]1322[[PROBE :*o][ONE :*o] fail]1323[[PROBE :*o]]1324[[SELECT] / fail]1325[[SELECT *branch : *] : *branch]1326[[SELECT * : *branches] / [SELECT : *branches]]1327[[APPEND [] *l *l]]1328[[APPEND [*head : *tail] *l [*head : *new]]/1329 [APPEND *tail *l *new]]1330[[LENGTH [] 0]]1331[[LENGTH [*head : *tail] *length] [LENGTH *tail *l] [sum *l 1 *length]]1332[[AT *from *from *e [*e : *]]]1333[[AT *from *to *e [* : *list]] [++ *from *next] / [AT *next *to *e *list]]1334[[AT *index *element *list] / [AT 0 *index *element *list]]1335[[ONLIST *x [*x : *]]]1336[[ONLIST *x [* : *l]] [ONLIST *x *l]]1337[[INLIST *l *x [*x : *l]]]1338[[INLIST [*h : *l] *x [*h : *ll]] [INLIST *l *x *ll]]1339[[NODUP [] []]/]1340[[NODUP [*x : *t] *result] [ONLIST *x *t] / [NODUP *t *result]]1341[[NODUP [*x : *t] [*x : *result]] / [NODUP *t *result]]1342[[MAP [] [] []]]1343[[MAP [[*x *y] : *xyt] [*x : *xt] [*y : *yt]] / [MAP *xyt *xt *yt]]1344[[MEMBER *x [*x : *]]]1345[[MEMBER *x [* : *l]] [MEMBER *x *l]]1346[[REPLACE *x [*x : *l] *l]]1347[[REPLACE *x [*h : *l] [*h : *ll]] [REPLACE *x *l *ll]]1348[[REPLACE *x [*x : *l] *y [*y : *l]]]1349[[REPLACE *x [*h : *l] *y [*h : *ll]] [REPLACE *x *l *y *ll]]1350[[WHILE *condition : *call] [not not : *condition] / [PROBE : *call] / [WHILE *condition : *call]]1351[[WHILE : *]]1352[[FOREVER : *instructions] [PROBE : *instructions] / [FOREVER : *instructions]]1353[[forever : *instructions] [res : *instructions] / [forever : *instructions]]1354[[REPEAT *ind : *instructions] [less 0 *ind] [PROBE : *instructions] [sub1 *ind *next] / [REPEAT *next : *instructions]]1355[[REPEAT : *]]1356[[FOR * [] : *] /]1357[[FOR *head [*head : *] : *call] [ONE : *call] fail]1358[[FOR *head [* : *tail] : *call] / [FOR *head *tail : *call]]1359[[FOR *index *index *index *step : *call] [TRY : *call]/]1360[[FOR *index *index *to *step : *call] [ONE : *call] fail]1361[[FOR *index *from *to *step : *call]1362 [add *from *step *next] /1363 [FOR *index *next *to *step : *call]]1364[[IF *condition *then] *condition / [TRY *then] /]1365[[IF *condition *then] /]1366[[IF *condition *then *else] *condition / [TRY *then] /]1367[[IF *condition *then *else] [TRY *else] /]1368[[REVERSE *l1 *l2] [REVERSE *l1 [] *l2]]1369[[REVERSE [] *x *x]]1370[[REVERSE [*head : *tail] *l0 *list] [REVERSE *tail [*head : *l0] *list]]1371[[var]]1372[[var *var : *vars] [var? *var] / [VARIABLE *var] / [var : *vars]]1373[[var [*var *value] : *vars] / [VARIABLE *var *value] / [var : *vars]]1374[[var *var : *vars] [VARIABLE *var] / [var : *vars]]1375[[inc *var] [*var : *value] [add *value 1 *new] [*var *new]]1376[[inc *var *inc] [*var : *value] [add *value *inc *new] [*var *new]]1377[[dec *var] [*var : *value] [sub *value 1 *new] [*var *new]]1378[[dec *var *dec] [*var : *value] [sub *value *dec *new] [*var *new]]1379[[ISALL *atom *template : *call]1380 [res : *call]1381 [*atom *template] fail1382]1383[[ISALL : *]]1384[[isall *list *template : *call]1385 [ACCUMULATOR *atom]1386 [ISALL *atom *template : *call]1387 [*atom : *list] /1388]1389[[isallq *list *template : *call]1390 [QUEUE *atom]1391 [ISALL *atom *template : *call]1392 [*atom : *list] /1393]1394[[isallr *list *template : *call]1395 [ACCUMULATOR *atom]1396 [ISALL *atom *template : *call]1397 [*atom : *reversed_list]1398 [REVERSE *reversed_list *list] /1399]1400[[grnd : *command] [rnd : *command]]1401[[grnd : *command] / [grnd : *command]]1402[[batch *text] [file_reader *text *batch] [batch [batch] *batch]]1403[[batch [exit] *batch] [*batch] /]1404[[batch * *batch] [*batch *command] *command / [batch *command *batch]]1405[[batch * *batch] [*batch] / fail]1406[[cl *x] / [cl 0 *y *x]]1407[[cl *x *y] / [cl 0 *x *y]]1408[[cl *x *x [[*a:*b]:*c]] [CL *x *a [[*a:*b]:*c]]]1409[[cl *x *y [[*a:*b]:*c]] [add *x 1 *x2] / [CL *x2 *a *X] [cl *x2 *y [[*a:*b]:*c]]]1410[[delcl [[*a:*b]:*c]] [cl *x [[*a:*b]:*c]] [DELCL *x *a]]1411[[OVERWRITE *index [[*atom : *parameters] : *body]] [DELCL *atom *index] [addcl *index [*atom : *parameters] : *body]]1412[[overwrite [[*a:*b]:*c] [[*a:*h]:*i]] [cl *x [[*a:*b]:*c]] [OVERWRITE *x [[*a:*h]:*i]]]1413[[operating_system *op] [navigator 'appName' *op]]1414[[implementation 'JavaScript']]1415[[version 2019 1]]1416[[Prompt *x : *command] [prompt *y : *command] [text_term *y *x]]1417[[SetInterval *interval *timeout : *command] [create_atoms *timeout] / [setInterval *interval *timeout : *command]]1418[[SetInterval *interval : *command] [create_atoms *timeout] [setInterval *interval *timeout : *command]]1419[[SetTimeout *interval *timeout : *command] [create_atoms *timeout] / [setTimeout *interval *timeout [*timeout] : *command]]1420[[SetTimeout *interval : *command] [create_atoms *timeout] [setTimeout *interval *timeout [*timeout] : *command]]1421[[exit : *]]1422protect [not]1423end ....
validation_test.js
Source:validation_test.js
1TestCase("formerlyValidation", {2 3 "test should set valid": function () {4 var el = createElement("text", "");5 var ret = el.checkValidity();6 7 assertTrue(ret);8 assertTrue(el.validity.valid);9 }10 11});12TestCase("formerlyValidationValueMissing", {13 14 "test should set valueMissing": function () {15 var el = createElement("text", "", { required: "required" });16 17 var ret = el.checkValidity();18 19 assertInvalid(ret, el, 'valueMissing');20 },21 22 "test should not set valueMissing": function () {23 var el = createElement("text", "A value", { required: "required" }, "valid");24 25 var ret = el.checkValidity();26 27 assertValid(ret, el, 'valueMissing');28 },29 30 "test should not validate an element where willValidate is false": function () {31 var el = createElement('image', "", { required: "required" });32 33 var ret = el.checkValidity();34 35 assertValid(ret, el, 'valueMissing');36 }37 38});39TestCase("formerlyValidationTypeMismatchNumber", {40 41 "test should set typeMismatch for invalid number": function () {42 var el = createElement("number", "nonumber");43 44 var ret = el.checkValidity();45 46 assertInvalid(ret, el, 'typeMismatch');47 },48 49 "test should not set typeMismatch for valid number": function () {50 var el = createElement("number", "5");51 52 var ret = el.checkValidity();53 54 assertValid(ret, el, 'typeMismatch');55 },56 57 "test should not set typeMismatch for empty string": function () {58 var el = createElement("number", "");59 60 var ret = el.checkValidity();61 62 assertValid(ret, el, 'typeMismatch');63 }64});65TestCase("formerlyValidationTypeMismatchRange", {66 67 "test should set typeMismatch for invalid range": function () {68 var el = createElement("range", "norange");69 70 var ret = el.checkValidity();71 72 assertInvalid(ret, el, 'typeMismatch');73 },74 75 "test should not set typeMismatch for valid range": function () {76 var el = createElement("range", "5");77 78 var ret = el.checkValidity();79 80 assertValid(ret, el, 'typeMismatch');81 },82 83 "test should set typeMismatch for empty string": function () {84 var el = createElement("range", "");85 86 var ret = el.checkValidity();87 88 assertInvalid(ret, el, 'typeMismatch');89 }90});91TestCase("formerlyValidationTypeMismatchEmail", {92 93 "test should set typeMismatch for invalid email": function () {94 var el = createElement("email", "noemail");95 96 var ret = el.checkValidity();97 98 assertInvalid(ret, el, 'typeMismatch');99 },100 101 "test should not set typeMismatch for valid email": function () {102 var el = createElement("email", "email@company.com");103 104 var ret = el.checkValidity();105 106 assertValid(ret, el, 'typeMismatch');107 },108 109 "test should not set typeMismatch for empty string": function () {110 var el = createElement("email", "");111 112 var ret = el.checkValidity();113 114 assertValid(ret, el, 'typeMismatch');115 }116 117 // TODO: More tests with different e-mail addresses118 // TODO: multiple e-mail addresses119 120});121TestCase("formerlyValidationTypeMismatchUrl", {122 123 "test should set typeMismatch for invalid url": function () {124 var el = createElement("url", "nourl");125 126 var ret = el.checkValidity();127 assertInvalid(ret, el, 'typeMismatch');128 },129 130 "test should set typeMismatch for a relative url": function () {131 var el = createElement("url", "//www.relative.com/");132 133 var ret = el.checkValidity();134 assertInvalid(ret, el, 'typeMismatch');135 },136 137 "test should not set typeMismatch for valid url": function () {138 var el = createElement("url", "http://www.valid.com/");139 140 var ret = el.checkValidity();141 assertValid(ret, el, 'typeMismatch');142 },143 "test should not set typeMismatch for valid url surrounded by spaces": function () {144 var el = createElement("url", " http://www.valid.com/ ");145 146 var ret = el.checkValidity();147 assertValid(ret, el, 'typeMismatch');148 },149 "test should not set typeMismatch for empty string": function () {150 var el = createElement("url", "");151 152 var ret = el.checkValidity();153 154 assertValid(ret, el, 'typeMismatch');155 }156});157TestCase("formerlyValidationTypeMismatchDateTime", {158 159 "test should set typeMismatch for invalid datetime": function () {160 var el = createElement("datetime", "nodatetime");161 162 var ret = el.checkValidity();163 164 assertInvalid(ret, el, 'typeMismatch');165 },166 "test should not set typeMismatch for valid datetime": function () {167 var el = createElement("datetime", "2012-08-07T18:45Z");168 169 var ret = el.checkValidity();170 171 assertValid(ret, el, 'typeMismatch');172 },173 174 "test should accept empty string": function () {175 var el = createElement("datetime", "");176 177 var ret = el.checkValidity();178 179 assertValid(ret, el, 'typeMismatch');180 },181 "test should not accept invalid date": function () {182 var el = createElement("datetime", "2012-08-32T18:45Z");183 184 var ret = el.checkValidity();185 186 assertInvalid(ret, el, 'typeMismatch');187 },188 "test should not accept invalid time": function () {189 var el = createElement("datetime", "2012-08-07T18:60Z");190 191 var ret = el.checkValidity();192 193 assertInvalid(ret, el, 'typeMismatch');194 },195 "test should accept positive time zone": function () {196 var el = createElement("datetime", "2012-08-07T18:45+01:00");197 198 var ret = el.checkValidity();199 200 assertValid(ret, el, 'typeMismatch');201 },202 "test should accept negative time zone": function () {203 var el = createElement("datetime", "2012-08-07T18:45-01:00");204 205 var ret = el.checkValidity();206 207 assertValid(ret, el, 'typeMismatch');208 },209 "test should not accept invalid time zone": function () {210 var el = createElement("datetime", "2012-08-07T18:45-01:60");211 212 var ret = el.checkValidity();213 214 assertInvalid(ret, el, 'typeMismatch');215 },216 "test should not accept missing time zone": function () {217 var el = createElement("datetime", "2012-08-07T18:45");218 219 var ret = el.checkValidity();220 221 assertInvalid(ret, el, 'typeMismatch');222 }223});224TestCase("formerlyValidationTypeMismatchDateTimeLocal", {225 226 "test should set typeMismatch for invalid datetime-local": function () {227 var el = createElement("datetime-local", "nodatetime");228 229 var ret = el.checkValidity();230 231 assertInvalid(ret, el, 'typeMismatch');232 },233 "test should not set typeMismatch for valid datetime-local": function () {234 var el = createElement("datetime-local", "2012-08-07T18:45");235 236 var ret = el.checkValidity();237 238 assertValid(ret, el, 'typeMismatch');239 },240 "test should accept empty string": function () {241 var el = createElement("datetime-local", "");242 243 var ret = el.checkValidity();244 245 assertValid(ret, el, 'typeMismatch');246 },247 "test should not accept invalid date": function () {248 var el = createElement("datetime-local", "2012-08-32T18:45");249 250 var ret = el.checkValidity();251 252 assertInvalid(ret, el, 'typeMismatch');253 },254 "test should not accept date only": function () {255 var el = createElement("datetime-local", "2012-08-07");256 257 var ret = el.checkValidity();258 259 assertInvalid(ret, el, 'typeMismatch');260 },261 "test should not accept invalid time": function () {262 var el = createElement("datetime-local", "2012-08-07T18:60");263 264 var ret = el.checkValidity();265 266 assertInvalid(ret, el, 'typeMismatch');267 },268 "test should not accept time zone": function () {269 var el = createElement("datetime-local", "2012-08-07T18:45Z");270 271 var ret = el.checkValidity();272 273 assertInvalid(ret, el, 'typeMismatch');274 }275 276});277TestCase("formerlyValidationTypeMismatchDate", {278 279 "test should set typeMismatch for invalid date": function () {280 var el = createElement("date", "nodate");281 282 var ret = el.checkValidity();283 284 assertInvalid(ret, el, 'typeMismatch');285 },286 "test should not set typeMismatch for valid date": function () {287 var el = createElement("date", "2012-08-07");288 289 var ret = el.checkValidity();290 291 assertValid(ret, el, 'typeMismatch');292 },293 294 "test should accept empty string": function () {295 var el = createElement("date", "");296 297 var ret = el.checkValidity();298 299 assertValid(ret, el, 'typeMismatch');300 },301 "test should accept years with more than five digits": function () {302 var el = createElement("date", "12012-08-07");303 304 var ret = el.checkValidity();305 306 assertValid(ret, el, 'typeMismatch');307 },308 "test should not accept less than four digit year": function () {309 var el = createElement("date", "12-08-02");310 311 var ret = el.checkValidity();312 313 assertInvalid(ret, el, 'typeMismatch');314 },315 "test should not accept year zero": function () {316 var el = createElement("date", "0000-08-07");317 318 var ret = el.checkValidity();319 320 assertInvalid(ret, el, 'typeMismatch');321 },322 "test should accept year 1": function () {323 var el = createElement("date", "0001-08-07");324 325 var ret = el.checkValidity();326 327 assertValid(ret, el, 'typeMismatch');328 },329 "test should not accept single digits in month and day": function () {330 var el = createElement("date", "2012-8-2");331 332 var ret = el.checkValidity();333 334 assertInvalid(ret, el, 'typeMismatch');335 },336 "test should not accept missing day": function () {337 var el = createElement("date", "2012-08");338 339 var ret = el.checkValidity();340 341 assertInvalid(ret, el, 'typeMismatch');342 },343 "test should set typeMismatch when day's to high": function () {344 var el = createElement("date", "2012-08-32");345 346 var ret = el.checkValidity();347 348 assertInvalid(ret, el, 'typeMismatch');349 },350 "test should set typeMismatch when day's to low": function () {351 var el = createElement("date", "2012-08-00");352 353 var ret = el.checkValidity();354 355 assertInvalid(ret, el, 'typeMismatch');356 },357 "test should set typeMismatch when month's to high": function () {358 var el = createElement("date", "2012-13-07");359 360 var ret = el.checkValidity();361 362 assertInvalid(ret, el, 'typeMismatch');363 },364 "test should set typeMismatch when month's to low": function () {365 var el = createElement("date", "2012-00-07");366 367 var ret = el.checkValidity();368 369 assertInvalid(ret, el, 'typeMismatch');370 },371 "test should not accept time": function () {372 var el = createElement("date", "2012-08-07T18:45");373 374 var ret = el.checkValidity();375 376 assertInvalid(ret, el, 'typeMismatch');377 }378});379TestCase("formerlyValidationTypeMismatchTime", {380 381 "test should set typeMismatch for invalid time": function () {382 var el = createElement("time", "notime");383 384 var ret = el.checkValidity();385 386 assertInvalid(ret, el, 'typeMismatch');387 },388 "test should not set typeMismatch for valid time": function () {389 var el = createElement("time", "18:45");390 391 var ret = el.checkValidity();392 393 assertValid(ret, el, 'typeMismatch');394 },395 "test should accept empty string": function () {396 var el = createElement("time", "");397 398 var ret = el.checkValidity();399 400 assertValid(ret, el, 'typeMismatch');401 },402 "test should set typeMismatch when hour's too high": function () {403 var el = createElement("time", "24:45");404 405 var ret = el.checkValidity();406 407 assertInvalid(ret, el, 'typeMismatch');408 },409 "test should set typeMismatch when hour's too low": function () {410 var el = createElement("time", "-1:45");411 412 var ret = el.checkValidity();413 414 assertInvalid(ret, el, 'typeMismatch');415 },416 "test should set typeMismatch when minute's too high": function () {417 var el = createElement("time", "18:60");418 419 var ret = el.checkValidity();420 421 assertInvalid(ret, el, 'typeMismatch');422 },423 "test should set typeMismatch when minute's too low": function () {424 var el = createElement("time", "18:-1");425 426 var ret = el.checkValidity();427 428 assertInvalid(ret, el, 'typeMismatch');429 },430 "test should not set typeMismatch for valid time with seconds": function () {431 var el = createElement("time", "18:45:37", { step: "any" });432 433 var ret = el.checkValidity();434 435 assertValid(ret, el, 'typeMismatch');436 },437 "test should set typeMismatch when second's too high": function () {438 var el = createElement("time", "18:45:60");439 440 var ret = el.checkValidity();441 442 assertInvalid(ret, el, 'typeMismatch');443 },444 "test should set typeMismatch when second's too low": function () {445 var el = createElement("time", "18:45:-1");446 447 var ret = el.checkValidity();448 449 assertInvalid(ret, el, 'typeMismatch');450 },451 "test should not set typeMismatch for valid time with fractions of a second": function () {452 var el = createElement("time", "18:45:37.174", { step: "any" });453 454 var ret = el.checkValidity();455 456 assertValid(ret, el, 'typeMismatch');457 }458});459TestCase("formerlyValidationTypeMismatchMonth", {460 461 "test should set typeMismatch for invalid month": function () {462 var el = createElement("month", "nomonth");463 464 var ret = el.checkValidity();465 466 assertInvalid(ret, el, 'typeMismatch');467 },468 "test should not set typeMismatch for valid month": function () {469 var el = createElement("month", "2012-08");470 471 var ret = el.checkValidity();472 473 assertValid(ret, el, 'typeMismatch');474 },475 "test should accept empty string": function () {476 var el = createElement("month", "");477 478 var ret = el.checkValidity();479 480 assertValid(ret, el, 'typeMismatch');481 },482 "test should accept years with more than five digits": function () {483 var el = createElement("month", "12012-08");484 485 var ret = el.checkValidity();486 487 assertValid(ret, el, 'typeMismatch');488 },489 "test should not accept less than four digit year": function () {490 var el = createElement("month", "12-08");491 492 var ret = el.checkValidity();493 494 assertInvalid(ret, el, 'typeMismatch');495 },496 "test should not accept year zero": function () {497 var el = createElement("month", "0000-08");498 499 var ret = el.checkValidity();500 501 assertInvalid(ret, el, 'typeMismatch');502 },503 "test should not accept single digits in month": function () {504 var el = createElement("month", "2012-8");505 506 var ret = el.checkValidity();507 508 assertInvalid(ret, el, 'typeMismatch');509 },510 "test should set typeMismatch when month's to high": function () {511 var el = createElement("month", "2012-13");512 513 var ret = el.checkValidity();514 515 assertInvalid(ret, el, 'typeMismatch');516 },517 "test should set typeMismatch when month's to low": function () {518 var el = createElement("month", "2012-00");519 520 var ret = el.checkValidity();521 522 assertInvalid(ret, el, 'typeMismatch');523 },524 "test should not accept day": function () {525 var el = createElement("month", "2012-08-07");526 527 var ret = el.checkValidity();528 529 assertInvalid(ret, el, 'typeMismatch');530 }531});532TestCase("formerlyValidationTypeMismatchWeek", {533 534 "test should set typeMismatch for invalid week": function () {535 var el = createElement("week", "noweek");536 537 var ret = el.checkValidity();538 539 assertInvalid(ret, el, 'typeMismatch');540 },541 "test should not set typeMismatch for valid week": function () {542 var el = createElement("week", "2012-W32");543 544 var ret = el.checkValidity();545 546 assertValid(ret, el, 'typeMismatch');547 },548 "test should accept empty string": function () {549 var el = createElement("week", "");550 551 var ret = el.checkValidity();552 553 assertValid(ret, el, 'typeMismatch');554 },555 "test should accept years with more than five digits": function () {556 var el = createElement("week", "12012-W32");557 558 var ret = el.checkValidity();559 560 assertValid(ret, el, 'typeMismatch');561 },562 "test should not accept less than four digit year": function () {563 var el = createElement("week", "12-W32");564 565 var ret = el.checkValidity();566 567 assertInvalid(ret, el, 'typeMismatch');568 },569 "test should not accept year zero": function () {570 var el = createElement("week", "0000-W32");571 572 var ret = el.checkValidity();573 574 assertInvalid(ret, el, 'typeMismatch');575 },576 "test should not accept too low week": function () {577 var el = createElement("week", "2012-W00");578 579 var ret = el.checkValidity();580 581 assertInvalid(ret, el, 'typeMismatch');582 },583 "test should not accept too high week": function () {584 var el = createElement("week", "2012-W54");585 586 var ret = el.checkValidity();587 588 assertInvalid(ret, el, 'typeMismatch');589 },590 "test should not accept 53 weeks in year with 52 weeks": function () {591 var el = createElement("week", "2012-W53");592 593 var ret = el.checkValidity();594 595 assertInvalid(ret, el, 'typeMismatch');596 },597 "test should accept 53 weeks in year with 53 weeks": function () {598 var el = createElement("week", "2009-W53");599 600 var ret = el.checkValidity();601 602 assertValid(ret, el, 'typeMismatch');603 },604 "test should accept 53 weeks in year with 53 weeks and first day on Wednesday": function () {605 var el = createElement("week", "1992-W53");606 607 var ret = el.checkValidity();608 609 assertValid(ret, el, 'typeMismatch');610 },611 "test should not accept 53 weeks in year with 52 weeks and first day on Wednesday": function () {612 var el = createElement("week", "1997-W53");613 614 var ret = el.checkValidity();615 616 assertInvalid(ret, el, 'typeMismatch');617 }618});619TestCase("formerlyValidationPatternMismatch", {620 "test should set patternMismatch": function () {621 var el = createElement("text", "letters", { pattern: '\\d*' });622 var ret = el.checkValidity();623 624 assertInvalid(ret, el, 'patternMismatch');625 },626 627 "test should not set patternMismatch on match": function () {628 var el = createElement("text", "123", { pattern: '\\d*' });629 var ret = el.checkValidity();630 631 assertValid(ret, el, 'patternMismatch');632 },633 "test should not set patternMismatch on invalid pattern": function () {634 var el = createElement("text", "123", { pattern: '[z-a]' });635 var ret;636 assertNoException(function () {637 ret = el.checkValidity();638 });639 640 assertValid(ret, el, 'patternMismatch');641 },642 "test should not set patternMismatch empty value": function () {643 var el = createElement("text", "", { pattern: '\\d+' });644 var ret = el.checkValidity();645 646 assertValid(ret, el, 'patternMismatch');647 }648 649 // TODO: Multiple650 651});652TestCase("formerlyValidationTooLong", {653 654 "test should set tooLong": function () {655 var el = createElement("text", "", { maxlength: "20" });656 el.value = "Longer than 20 characters";657 658 var ret = el.checkValidity();659 660 assertInvalid(ret, el, 'tooLong');661 },662 663 "test should not set tooLong when value not dirty": function () {664 var el = createElement("text", "Longer than 20 characters", { maxlength: "20" });665 666 var ret = el.checkValidity();667 668 assertValid(ret, el, 'tooLong');669 },670 "test should not set tooLong for shorter string": function () {671 var el = createElement("text", "", { maxlength: "20" });672 el.value = "Shorter than 20";673 674 var ret = el.checkValidity();675 676 assertValid(ret, el, 'tooLong');677 },678 "test should not set tooLong for empty string": function () {679 var el = createElement("text", "Default", { maxlength: "20" });680 el.value = "";681 682 var ret = el.checkValidity();683 684 assertValid(ret, el, 'tooLong');685 },686 "test should not set tooLong with illegal maxlength": function () {687 var el = createElement("text", "", { maxlength: "illegal" });688 el.value = "Longer than 20 characters";689 690 var ret = el.checkValidity();691 692 assertValid(ret, el, 'tooLong');693 },694 "test should not set tooLong with maxLength -1": function () {695 // Note: This is the default maxLength in Firefox696 var el = createElement("text", "", { maxlength: "-1" });697 el.value = "Longer than 20 characters";698 699 var ret = el.checkValidity();700 701 assertValid(ret, el, 'tooLong');702 }703 704});705TestCase("formerlyValidationRangeUnderflow", {706 707 "test should set rangeUnderflow": function () {708 var el = createElement("number", "8", { min: "10" });709 710 var ret = el.checkValidity();711 712 assertInvalid(ret, el, 'rangeUnderflow');713 },714 "test should not set rangeUnderflow": function () {715 var el = createElement("number", "11", { min: "10" });716 717 var ret = el.checkValidity();718 719 assertValid(ret, el, 'rangeUnderflow');720 },721 "test should not set rangeUnderflow when equal": function () {722 var el = createElement("number", "10", { min: "10" });723 724 var ret = el.checkValidity();725 726 assertValid(ret, el, 'rangeUnderflow');727 },728 "test should not set rangeUnderflow for empty string": function () {729 var el = createElement("number", "", { min: "10" });730 731 var ret = el.checkValidity();732 733 assertValid(ret, el, 'rangeUnderflow');734 },735 "test should not set rangeUnderflow with illegal min": function () {736 var el = createElement("number", "8", { min: "illegal" });737 738 var ret = el.checkValidity();739 740 assertValid(ret, el, 'rangeUnderflow');741 },742 "test should not set rangeUnderflow with illegal value": function () {743 var el = createElement("number", "illegal", { min: "10" });744 745 var ret = el.checkValidity();746 747 assertFalse("validity.rangeUnderflow", el.validity.rangeUnderflow);748 },749 750 "test should have no default min for number field": function () {751 var el = createElement("number", "-1");752 753 var ret = el.checkValidity();754 755 assertValid(ret, el, 'rangeUnderflow');756 },757 "test should have default min = 0 for range field": function () {758 var el = createElement("range", "-1");759 760 var ret = el.checkValidity();761 762 assertInvalid(ret, el, 'rangeUnderflow');763 },764 "test should set rangeUnderflow for datetime field": function () {765 var el = createElement("datetime", "2012-08-07T18:45Z", { min: "2012-08-07T18:46Z" });766 767 var ret = el.checkValidity();768 769 assertInvalid(ret, el, 'rangeUnderflow');770 },771 "test should set rangeUnderflow for date field": function () {772 var el = createElement("date", "2012-08-07", { min: "2012-08-08" });773 774 var ret = el.checkValidity();775 776 assertInvalid(ret, el, 'rangeUnderflow');777 },778 "test should set rangeUnderflow for time field": function () {779 var el = createElement("time", "18:45", { min: "18:46" });780 781 var ret = el.checkValidity();782 783 assertInvalid(ret, el, 'rangeUnderflow');784 },785 "test should set rangeUnderflow for datetime-local field": function () {786 var el = createElement("datetime-local", "2012-08-07T18:45", { min: "2012-08-07T18:46" });787 788 var ret = el.checkValidity();789 790 assertInvalid(ret, el, 'rangeUnderflow');791 },792 "test should set rangeUnderflow for week field": function () {793 var el = createElement("week", "2012-W32", { min: "2012-W33" });794 795 var ret = el.checkValidity();796 797 assertInvalid(ret, el, 'rangeUnderflow');798 },799 "test should set rangeUnderflow for month field": function () {800 var el = createElement("month", "2012-08", { min: "2012-09" });801 802 var ret = el.checkValidity();803 804 assertInvalid(ret, el, 'rangeUnderflow');805 },806 "test should not set rangeUnderflow for text field": function () {807 var el = createElement("text", "8", { min: "10" });808 809 var ret = el.checkValidity();810 811 assertValid(ret, el, 'rangeUnderflow');812 }813});814TestCase("formerlyValidationRangeOverflow", {815 816 "test should set rangeOverflow": function () {817 var el = createElement("number", "12", { max: "10" });818 819 var ret = el.checkValidity();820 821 assertInvalid(ret, el, 'rangeOverflow');822 },823 "test should not set rangeOverflow": function () {824 var el = createElement("number", "9", { max: "10" });825 826 var ret = el.checkValidity();827 828 assertValid(ret, el, 'rangeOverflow');829 },830 "test should not set rangeOverflow when equal": function () {831 var el = createElement("number", "10", { max: "10" });832 833 var ret = el.checkValidity();834 835 assertValid(ret, el, 'rangeOverflow');836 },837 "test should not set rangeOverflow when empty string": function () {838 var el = createElement("number", "", { max: "10" });839 840 var ret = el.checkValidity();841 842 assertValid(ret, el, 'rangeOverflow');843 },844 "test should not set rangeOverflow with illegal max": function () {845 var el = createElement("number", "12", { max: "illegal" });846 847 var ret = el.checkValidity();848 849 assertValid(ret, el, 'rangeOverflow');850 },851 "test should not set rangeOverflow with illegal value": function () {852 var el = createElement("number", "illegal", { max: "10" });853 854 var ret = el.checkValidity();855 856 assertFalse("validity.rangeOverflow", el.validity.rangeOverflow);857 },858 "test should have no default max for number": function () {859 var el = createElement("number", "99999999");860 861 var ret = el.checkValidity();862 863 assertValid(ret, el, 'rangeOverflow');864 },865 "test should have default max = 100 for range": function () {866 var el = createElement("range", "101");867 868 var ret = el.checkValidity();869 870 assertInvalid(ret, el, 'rangeOverflow');871 },872 "test should set rangeOverflow for datetime field": function () {873 var el = createElement("datetime", "2012-08-07T18:45Z", { max: "2012-08-07T18:44Z" });874 875 var ret = el.checkValidity();876 877 assertInvalid(ret, el, 'rangeOverflow');878 },879 "test should set rangeOverflow for date field": function () {880 var el = createElement("date", "2012-08-07", { max: "2012-08-06" });881 882 var ret = el.checkValidity();883 884 assertInvalid(ret, el, 'rangeOverflow');885 },886 "test should set rangeOverflow for time field": function () {887 var el = createElement("time", "18:45", { max: "18:44" });888 889 var ret = el.checkValidity();890 891 assertInvalid(ret, el, 'rangeOverflow');892 },893 "test should set rangeOverflow for datetime-local field": function () {894 var el = createElement("datetime-local", "2012-08-07T18:45", { max: "2012-08-07T18:44" });895 896 var ret = el.checkValidity();897 898 assertInvalid(ret, el, 'rangeOverflow');899 },900 "test should set rangeOverflow for week field": function () {901 var el = createElement("week", "2012-W32", { max: "2012-W31" });902 903 var ret = el.checkValidity();904 905 assertInvalid(ret, el, 'rangeOverflow');906 },907 "test should set rangeOverflow for month field": function () {908 var el = createElement("month", "2012-08", { max: "2012-07" });909 910 var ret = el.checkValidity();911 912 assertInvalid(ret, el, 'rangeOverflow');913 },914 "test should not set rangeOverflow for text field": function () {915 var el = createElement("text", "12", { max: "10" });916 917 var ret = el.checkValidity();918 919 assertValid(ret, el, 'rangeOverflow');920 }921});922TestCase("formerlyValidationStepMismatch", {923 "test should set stepMismatch": function () {924 var el = createElement("number", "1.5", { step: "1" });925 926 var ret = el.checkValidity();927 928 assertInvalid(ret, el, 'stepMismatch');929 },930 "test should not set stepMismatch": function () {931 var el = createElement("number", "2", { step: "1" });932 933 var ret = el.checkValidity();934 935 assertValid(ret, el, 'stepMismatch');936 },937 "test should not set stepMismatch when valid steps from min": function () {938 var el = createElement("number", "3.5", { step: "1", min: "0.5" });939 940 var ret = el.checkValidity();941 942 assertValid(ret, el, 'stepMismatch');943 },944 "test should not set stepMismatch with empty string": function () {945 var el = createElement("number", "", { step: "1" });946 947 var ret = el.checkValidity();948 949 assertValid(ret, el, 'stepMismatch');950 },951 "test should use default step with illegal step value": function () {952 var el = createElement("number", "3.5", { step: "illegal" });953 954 var ret = el.checkValidity();955 956 assertInvalid(ret, el, 'stepMismatch');957 },958 "test should not set stepMismatch with step 'any'": function () {959 var el = createElement("number", "3.5", { step: "any" });960 961 var ret = el.checkValidity();962 963 assertValid(ret, el, 'stepMismatch');964 },965 "test should not set stepMismatch with step = 0": function () {966 var el = createElement("number", "3", { step: "0" });967 968 var ret = el.checkValidity();969 970 assertValid(ret, el, 'stepMismatch');971 },972 "test should not set stepMismatch with illegal value": function () {973 var el = createElement("number", "illegal", { step: "1" });974 975 var ret = el.checkValidity();976 977 assertFalse("validity.stepMismatch", el.validity.stepMismatch);978 },979 "test should not set stepMismatch for text field": function () {980 var el = createElement("text", "1.5", { step: "1" });981 982 var ret = el.checkValidity();983 984 assertValid(ret, el, 'stepMismatch');985 },986 "test should correctly set stepMismatch with value = 0": function () {987 var el = createElement("number", "0", { min: "-0.5", step: "1" });988 989 var ret = el.checkValidity();990 991 assertInvalid(ret, el, 'stepMismatch');992 },993 "test should have default step = 1 for range": function () {994 var el = createElement("range", "0.5");995 996 var ret = el.checkValidity();997 998 assertInvalid(ret, el, 'stepMismatch');999 },1000 "test should set stepMismatch for datetime": function () {1001 var el = createElement("datetime", "2012-08-07T18:45:52Z", { step: "30" });1002 1003 var ret = el.checkValidity();1004 1005 assertInvalid(ret, el, 'stepMismatch');1006 },1007 "test should not set stepMismatch for datetime matching step": function () {1008 var el = createElement("datetime", "2012-08-07T18:45:30Z", { step: "30" });1009 1010 var ret = el.checkValidity();1011 1012 assertValid(ret, el, 'stepMismatch');1013 },1014 "test should have default step = 60 for datetime": function () {1015 var el = createElement("datetime", "2012-08-07T18:45:30Z");1016 1017 var ret = el.checkValidity();1018 1019 assertInvalid(ret, el, 'stepMismatch');1020 },1021 "test should set stepMismatch for date": function () {1022 var el = createElement("date", "2012-08-07", { step: "2" });1023 1024 var ret = el.checkValidity();1025 1026 assertInvalid(ret, el, 'stepMismatch');1027 },1028 "test should not set stepMismatch for date matching step": function () {1029 var el = createElement("date", "2012-08-08", { step: "2" });1030 1031 var ret = el.checkValidity();1032 1033 assertValid(ret, el, 'stepMismatch');1034 },1035 "test should have default step = 1 for date": function () {1036 var el = createElement("date", "2012-08-07");1037 1038 var ret = el.checkValidity();1039 1040 assertValid(ret, el, 'stepMismatch');1041 },1042 "test should set stepMismatch for time": function () {1043 var el = createElement("time", "18:45:45", { step: "30" });1044 1045 var ret = el.checkValidity();1046 1047 assertInvalid(ret, el, 'stepMismatch');1048 },1049 "test should not set stepMismatch for time matching step": function () {1050 var el = createElement("time", "18:45:30", { step: "30" });1051 1052 var ret = el.checkValidity();1053 1054 assertValid(ret, el, 'stepMismatch');1055 },1056 "test should have default step = 60 for time": function () {1057 var el = createElement("time", "18:45:30");1058 1059 var ret = el.checkValidity();1060 1061 assertInvalid(ret, el, 'stepMismatch');1062 },1063 "test should have default step = 60 for datetime-local": function () {1064 var el = createElement("datetime-local", "2012-08-07T18:45:30");1065 1066 var ret = el.checkValidity();1067 1068 assertInvalid(ret, el, 'stepMismatch');1069 },1070 "test should set stepMismatch for week": function () {1071 var el = createElement("week", "2012-W33", { step: "2" });1072 1073 var ret = el.checkValidity();1074 1075 assertInvalid(ret, el, 'stepMismatch');1076 },1077 "test should not set stepMismatch for week matching step": function () {1078 var el = createElement("week", "2012-W32", { step: "2" });1079 1080 var ret = el.checkValidity();1081 1082 assertValid(ret, el, 'stepMismatch');1083 },1084 "test should set stepMismatch for month": function () {1085 var el = createElement("month", "2012-08", { step: "2" });1086 1087 var ret = el.checkValidity();1088 1089 assertInvalid(ret, el, 'stepMismatch');1090 },1091 "test should not set stepMismatch for month matching step": function () {1092 var el = createElement("month", "2012-09", { step: "2" });1093 1094 var ret = el.checkValidity();1095 1096 assertValid(ret, el, 'stepMismatch');1097 }1098});1099TestCase("formerlyValidationInvalidEvent", sinon.testCase({1100 1101 "test should throw invalid event on checkValidity": function () {1102 if (document.createEvent !== undefined) { // Skip this for old IEs for now1103 var el = createElement("text", "", { required: 'required' }, "", true, false);1104 1105 el.checkValidity();1106 1107 assertCalledOnce(el.dispatchEvent);1108 var event = el.dispatchEvent.args[0][0];1109 assertObject(event);1110 assertEquals('invalid', event.type);1111 assertFalse('Bubbles', event.bubbles);1112 assertTrue('Cancelable', event.cancelable);1113 }1114 },1115 1116 "test should not throw invalid event when element valid": function () {1117 var el = createElement("text", "");1118 1119 el.checkValidity();1120 1121 assertNotCalled(el.dispatchEvent);1122 }1123}));1124 1125TestCase("formerlyValidationInvalidEventIE", sinon.testCase({1126 setUp: function () {1127 this.el = createElement("text", "", { required: 'required' }, "", false, true); // Imitate IE1128 this.nativeAttachEvent = this.el.attachEvent;1129 this.nativeDetachEvent = this.el.detachEvent;1130 formerly.initElement(this.el);1131 },1132 "test should override attachEvent when present": function () {1133 //formerly.initElement(this.el); -- Done in setUp1134 1135 assertNotEquals(this.nativeAttachEvent, this.el.attachEvent);1136 },1137 "test attachEvent should return true for native event": function () {1138 var ret = this.el.attachEvent('onclick', function () {});1139 1140 assertTrue(ret);1141 },1142 "test attachEvent should return true for invalid event": function () {1143 var ret = this.el.attachEvent('oninvalid', function () {});1144 1145 assertTrue(ret);1146 },1147 1148 "test should call browser attachEvent when not invalid event": function () {1149 this.el.attachEvent('onclick', function () {});1150 1151 assertCalledWith(this.nativeAttachEvent, 'onclick');1152 },1153 1154 "test should trigger invalid event on checkValidity in IE": function () {1155 var handler = sinon.stub();1156 this.el.attachEvent("oninvalid", handler);1157 1158 this.el.checkValidity();1159 1160 assertCalledOnce(handler);1161 },1162 "test should call back with event object": function () {1163 var handler = sinon.stub();1164 this.el.attachEvent("oninvalid", handler);1165 this.el.checkValidity();1166 1167 var event = handler.args[0][0];1168 1169 assertObject(event);1170 assertEquals("invalid", event.eventType);1171 },1172 "test should call several handlers on checkValidity in IE": function () {1173 var handler1 = sinon.stub();1174 var handler2 = sinon.stub();1175 this.el.attachEvent("oninvalid", handler1);1176 this.el.attachEvent("oninvalid", handler2);1177 1178 this.el.checkValidity();1179 1180 assertCalledOnce(handler1);1181 assertCalledOnce(handler2);1182 },1183 1184 "test should call handler for checked element only": function () {1185 var el2 = createElement("text", "", { required: 'required' }, "", true, true); // Imitate IE1186 var handler1 = sinon.stub();1187 var handler2 = sinon.stub();1188 this.el.attachEvent("oninvalid", handler1);1189 el2.attachEvent("oninvalid", handler2);1190 el2.checkValidity();1191 assertNotCalled(handler1);1192 assertCalledOnce(handler2);1193 },1194 1195 "test should override detachEvent when present": function () {1196 //formerly.initElement(this.el); -- Done in setUp1197 1198 assertNotEquals(this.nativeDetachEvent, this.el.detachEvent);1199 },1200 "test should call browser detachEvent when not invalid event": function () {1201 this.el.detachEvent('onclick', function () {});1202 1203 assertCalledWith(this.nativeDetachEvent, 'onclick');1204 },1205 1206 "test detachEvent should return 0 for invalid": function () {1207 var handler = sinon.stub();1208 this.el.attachEvent("oninvalid", handler);1209 1210 var ret = this.el.detachEvent("oninvalid", handler);1211 1212 assertEquals(0, ret);1213 },1214 "test detachEvent should return 0 for native events": function () {1215 var handler = sinon.stub();1216 this.el.attachEvent("onclick", handler);1217 1218 var ret = this.el.detachEvent("onclick", handler);1219 1220 assertEquals(0, ret);1221 },1222 "test should detach from invalid event": function () {1223 var handler = sinon.stub();1224 this.el.attachEvent("oninvalid", handler);1225 this.el.detachEvent("oninvalid", handler);1226 1227 this.el.checkValidity();1228 1229 assertNotCalled(handler);1230 },1231 "test should detach correct event": function () {1232 var handler1 = sinon.stub();1233 var handler2 = sinon.stub();1234 this.el.attachEvent("oninvalid", handler1);1235 this.el.attachEvent("oninvalid", handler2);1236 this.el.detachEvent("oninvalid", handler2);1237 1238 this.el.checkValidity();1239 1240 assertCalledOnce(handler1);1241 assertNotCalled(handler2);1242 }1243}));1244TestCase("formerlyValidationClassNames", {1245 setUp: function () {1246 this.form1 = { addEventListener: sinon.stub() };1247 },1248 1249 tearDown: function () {1250 formerly.init(this.form1, { validClass: 'valid' }); // Reset to default class name1251 },1252 "test should set valid class": function () {1253 var el = createElement("text", "");1254 var ret = el.checkValidity();1255 1256 assertEquals('valid', el.className);1257 },1258 "test should set valid class and remove invalid class": function () {1259 var el = createElement("text", "invalid");1260 var ret = el.checkValidity();1261 1262 assertEquals('valid', el.className);1263 },1264 "test should set invalid and remove valid class": function () {1265 var el = createElement("text", "", { required: "required" }, "valid");1266 1267 var ret = el.checkValidity();1268 1269 assertEquals("invalid", el.className);1270 },1271 "test should preserve other class names": function () {1272 var el = createElement("text", "", null, "other class names");1273 var ret = el.checkValidity();1274 1275 assertEquals("other class names valid", el.className);1276 },1277 "test should not add valid class if exists": function () {1278 var el = createElement("text", "", null, "already valid");1279 var ret = el.checkValidity();1280 1281 assertEquals("already valid", el.className);1282 },1283 "test should not be fooled by 'valid' in other class names": function () {1284 var el = createElement("text", "", null, "not reallyvalid");1285 var ret = el.checkValidity();1286 1287 assertEquals("not reallyvalid valid", el.className);1288 },1289 1290 "test should remove invalid class": function () {1291 var el = createElement("text", "", null, "invalid");1292 var ret = el.checkValidity();1293 1294 assertEquals("valid", el.className);1295 },1296 "test should remove invalid class among other classes": function () {1297 var el = createElement("text", "", null, "is invalid");1298 var ret = el.checkValidity();1299 1300 assertEquals("is valid", el.className);1301 },1302 "test should not be fooled by 'invalid' in other class names": function () {1303 var el = createElement("text", "", null, "is notinvalid");1304 var ret = el.checkValidity();1305 1306 assertEquals("is notinvalid valid", el.className);1307 },1308 "test should not be fooled by 'invalid' at the beginning of other class names": function () {1309 var el = createElement("text", "", null, "is invalidlike");1310 var ret = el.checkValidity();1311 1312 assertEquals("is invalidlike valid", el.className);1313 },1314 1315 "test should use custom valid class name when set": function () {1316 var el = createElement("text", "", null, "", false);1317 this.form1.elements = [ el ];1318 this.form1.length = this.form1.elements.length;1319 formerly.init(this.form1, { validClass: 'okay' });1320 var ret = el.checkValidity();1321 1322 assertEquals('okay', el.className);1323 },1324 "test should use custom invalid class name when set": function () {1325 var el = createElement("text", "", { required: "required" }, "", false);1326 this.form1.elements = [ el ];1327 this.form1.length = this.form1.elements.length;1328 formerly.init(this.form1, { invalidClass: 'fail' });1329 var ret = el.checkValidity();1330 1331 assertEquals('fail', el.className);1332 }1333});...
report_object.js
Source:report_object.js
1// var defaultProcessor = function($event, key, target, options) {2// console.log($event.target)3// switch(option.elType) {4// case 'text':5// target[key] = $event.target.value;6// break;7// case 'date':8// target[key] = $event.target.value;9// target[key] = '[' + from + '+TO+' + to + ']';10// break11// }12// }13var SEX_VALUES = ['Unknown', 'Male', 'Female'];14var REACTION_OUTCOMES = ['All', 'Recovered/resolved.', 'Recovering/resolving.', 'Not recovered/not resolved.', 'Recovered/resolved with sequelae.', 'Fatal.', 'Unknown.'];15var COUNTRIES = ["ae", "ar", "at", "au", "az", "ba", "bd", "be", "bg", "bo", "br", "ca", "ch", "ci", "cl", "cm", "cn", "co", "cr", "cy", "cz", "de", "dk", "do", "dz", "ec", "ee", "eg", "es", "fi", "fr", "gb", "ge", "gr", "gt", "hk", "hn", "hr", "hu", "id", "ie", "il", "in", "iq", "ir", "is", "it", "jm", "jo", "jp", "ke", "kp", "kr", "kw", "kz", "lb", "lk", "lt", "lu", "lv", "ma", "mt", "mw", "mx", "my", "ng", "nl", "no", "nz", "pa", "pe", "ph", "pk", "pl", "pr", "pt", "qa", "ro", "rs", "ru", "sa", "sd", "se", "sg", "si", "sk", "sv", "th", "tn", "tr", "tw", "ua", "ug", "us", "uy", "uz", "ve", "vn", "za", "zw"]16// var COUNTRIES_FULL = {"AF": "Afghanistan", "AX": "Ã
land Islands", "AL": "Albania", "DZ": "Algeria", "AS": "American Samoa", "AD": "AndorrA", "AO": "Angola", "AI": "Anguilla", "AQ": "Antarctica", "AG": "Antigua and Barbuda", "AR": "Argentina", "AM": "Armenia", "AW": "Aruba", "AU": "Australia", "AT": "Austria", "AZ": "Azerbaijan", "BS": "Bahamas", "BH": "Bahrain", "BD": "Bangladesh", "BB": "Barbados", "BY": "Belarus", "BE": "Belgium", "BZ": "Belize", "BJ": "Benin", "BM": "Bermuda", "BT": "Bhutan", "BO": "Bolivia", "BA": "Bosnia and Herzegovina", "BW": "Botswana", "BV": "Bouvet Island", "BR": "Brazil", "IO": "British Indian Ocean Territory", "BN": "Brunei Darussalam", "BG": "Bulgaria", "BF": "Burkina Faso", "BI": "Burundi", "KH": "Cambodia", "CM": "Cameroon", "CA": "Canada", "CV": "Cape Verde", "KY": "Cayman Islands", "CF": "Central African Republic", "TD": "Chad", "CL": "Chile", "CN": "China", "CX": "Christmas Island", "CC": "Cocos (Keeling) Islands", "CO": "Colombia", "KM": "Comoros", "CG": "Congo", "CD": "Congo, The Democratic Republic of the", "CK": "Cook Islands", "CR": "Costa Rica", "CI": "Cote D\"Ivoire", "HR": "Croatia", "CU": "Cuba", "CY": "Cyprus", "CZ": "Czech Republic", "DK": "Denmark", "DJ": "Djibouti", "DM": "Dominica", "DO": "Dominican Republic", "EC": "Ecuador", "EG": "Egypt", "SV": "El Salvador", "GQ": "Equatorial Guinea", "ER": "Eritrea", "EE": "Estonia", "ET": "Ethiopia", "FK": "Falkland Islands (Malvinas)", "FO": "Faroe Islands", "FJ": "Fiji", "FI": "Finland", "FR": "France", "GF": "French Guiana", "PF": "French Polynesia", "TF": "French Southern Territories", "GA": "Gabon", "GM": "Gambia", "GE": "Georgia", "DE": "Germany", "GH": "Ghana", "GI": "Gibraltar", "GR": "Greece", "GL": "Greenland", "GD": "Grenada", "GP": "Guadeloupe", "GU": "Guam", "GT": "Guatemala", "GG": "Guernsey", "GN": "Guinea", "GW": "Guinea-Bissau", "GY": "Guyana", "HT": "Haiti", "HM": "Heard Island and Mcdonald Islands", "VA": "Holy See (Vatican City State)", "HN": "Honduras", "HK": "Hong Kong", "HU": "Hungary", "IS": "Iceland", "IN": "India", "ID": "Indonesia", "IR": "Iran, Islamic Republic Of", "IQ": "Iraq", "IE": "Ireland", "IM": "Isle of Man", "IL": "Israel", "IT": "Italy", "JM": "Jamaica", "JP": "Japan", "JE": "Jersey", "JO": "Jordan", "KZ": "Kazakhstan", "KE": "Kenya", "KI": "Kiribati", "KP": "Korea, Democratic People\"S Republic of", "KR": "Korea, Republic of", "KW": "Kuwait", "KG": "Kyrgyzstan", "LA": "Lao People\"S Democratic Republic", "LV": "Latvia", "LB": "Lebanon", "LS": "Lesotho", "LR": "Liberia", "LY": "Libyan Arab Jamahiriya", "LI": "Liechtenstein", "LT": "Lithuania", "LU": "Luxembourg", "MO": "Macao", "MK": "Macedonia, The Former Yugoslav Republic of", "MG": "Madagascar", "MW": "Malawi", "MY": "Malaysia", "MV": "Maldives", "ML": "Mali", "MT": "Malta", "MH": "Marshall Islands", "MQ": "Martinique", "MR": "Mauritania", "MU": "Mauritius", "YT": "Mayotte", "MX": "Mexico", "FM": "Micronesia, Federated States of", "MD": "Moldova, Republic of", "MC": "Monaco", "MN": "Mongolia", "MS": "Montserrat", "MA": "Morocco", "MZ": "Mozambique", "MM": "Myanmar", "NA": "Namibia", "NR": "Nauru", "NP": "Nepal", "NL": "Netherlands", "AN": "Netherlands Antilles", "NC": "New Caledonia", "NZ": "New Zealand", "NI": "Nicaragua", "NE": "Niger", "NG": "Nigeria", "NU": "Niue", "NF": "Norfolk Island", "MP": "Northern Mariana Islands", "NO": "Norway", "OM": "Oman", "PK": "Pakistan", "PW": "Palau", "PS": "Palestinian Territory, Occupied", "PA": "Panama", "PG": "Papua New Guinea", "PY": "Paraguay", "PE": "Peru", "PH": "Philippines", "PN": "Pitcairn", "PL": "Poland", "PT": "Portugal", "PR": "Puerto Rico", "QA": "Qatar", "RE": "Reunion", "RO": "Romania", "RU": "Russian Federation", "RW": "RWANDA", "SH": "Saint Helena", "KN": "Saint Kitts and Nevis", "LC": "Saint Lucia", "PM": "Saint Pierre and Miquelon", "VC": "Saint Vincent and the Grenadines", "WS": "Samoa", "SM": "San Marino", "ST": "Sao Tome and Principe", "SA": "Saudi Arabia", "SN": "Senegal", "CS": "Serbia and Montenegro", "SC": "Seychelles", "SL": "Sierra Leone", "SG": "Singapore", "SK": "Slovakia", "SI": "Slovenia", "SB": "Solomon Islands", "SO": "Somalia", "ZA": "South Africa", "GS": "South Georgia and the South Sandwich Islands", "ES": "Spain", "LK": "Sri Lanka", "SD": "Sudan", "SR": "Suriname", "SJ": "Svalbard and Jan Mayen", "SZ": "Swaziland", "SE": "Sweden", "CH": "Switzerland", "SY": "Syrian Arab Republic", "TW": "Taiwan, Province of China", "TJ": "Tajikistan", "TZ": "Tanzania, United Republic of", "TH": "Thailand", "TL": "Timor-Leste", "TG": "Togo", "TK": "Tokelau", "TO": "Tonga", "TT": "Trinidad and Tobago", "TN": "Tunisia", "TR": "Turkey", "TM": "Turkmenistan", "TC": "Turks and Caicos Islands", "TV": "Tuvalu", "UG": "Uganda", "UA": "Ukraine", "AE": "United Arab Emirates", "GB": "United Kingdom", "US": "United States", "UM": "United States Minor Outlying Islands", "UY": "Uruguay", "UZ": "Uzbekistan", "VU": "Vanuatu", "VE": "Venezuela", "VN": "Viet Nam", "VG": "Virgin Islands, British", "VI": "Virgin Islands, U.S.", "WF": "Wallis and Futuna", "EH": "Western Sahara", "YE": "Yemen", "ZM": "Zambia", "ZW": "Zimbabwe"}17var COUNTRIES_FULL = {"AE":"United Arab Emirates","AR":"Argentina","AT":"Austria","AU":"Australia","AZ":"Azerbaijan","BA":"Bosnia and Herzegovina","BD":"Bangladesh","BE":"Belgium","BG":"Bulgaria","BO":"Bolivia","BR":"Brazil","CA":"Canada","CH":"Switzerland","CI":"Cote D\"Ivoire","CL":"Chile","CM":"Cameroon","CN":"China","CO":"Colombia","CR":"Costa Rica","CY":"Cyprus","CZ":"Czech Republic","DE":"Germany","DK":"Denmark","DO":"Dominican Republic","DZ":"Algeria","EC":"Ecuador","EE":"Estonia","EG":"Egypt","ES":"Spain","FI":"Finland","FR":"France","GB":"United Kingdom","GE":"Georgia","GR":"Greece","GT":"Guatemala","HK":"Hong Kong","HN":"Honduras","HR":"Croatia","HU":"Hungary","ID":"Indonesia","IE":"Ireland","IL":"Israel","IN":"India","IQ":"Iraq","IR":"Iran, Islamic Republic Of","IS":"Iceland","IT":"Italy","JM":"Jamaica","JO":"Jordan","JP":"Japan","KE":"Kenya","KP":"Korea, Democratic People\"S Republic of","KR":"Korea, Republic of","KW":"Kuwait","KZ":"Kazakhstan","LB":"Lebanon","LK":"Sri Lanka","LT":"Lithuania","LU":"Luxembourg","LV":"Latvia","MA":"Morocco","MT":"Malta","MW":"Malawi","MX":"Mexico","MY":"Malaysia","NG":"Nigeria","NL":"Netherlands","NO":"Norway","NZ":"New Zealand","PA":"Panama","PE":"Peru","PH":"Philippines","PK":"Pakistan","PL":"Poland","PR":"Puerto Rico","PT":"Portugal","QA":"Qatar","RO":"Romania","RU":"Russian Federation","SA":"Saudi Arabia","SD":"Sudan","SE":"Sweden","SG":"Singapore","SI":"Slovenia","SK":"Slovakia","SV":"El Salvador","TH":"Thailand","TN":"Tunisia","TR":"Turkey","TW":"Taiwan, Province of China","UA":"Ukraine","UG":"Uganda","US":"United States","UY":"Uruguay","UZ":"Uzbekistan","VE":"Venezuela","VN":"Viet Nam","ZA":"South Africa","ZW":"Zimbabwe"}18var QUALIFICATIONS = ['All', 'Physician', 'Pharmacist', 'Other Health Professional', 'Lawyer', 'Consumer or non-health professional']19var DRUG_FREQUENCY = {801: 'Year', 802: 'Month', 803: 'Week', 804: 'Day', 805: 'Hour', 806: 'Minute', 807: 'Trimester', 810: 'Cyclical', 811: 'Trimester', 812: 'As Necessary', 813: 'Total'}20var DRUG_UNIT = {'001': 'kg kilogram(s)', '002': 'G gram(s)', '003': 'Mg milligram(s)', '004': 'μg microgram(s)'}21var fetchTermsPreprocessor = function(property, $scope) {22 return $scope.getCounts(property.full_field + '.exact', 1000)23 .then(function(unProcessData){24 sortedData = $scope.orderByFilter(unProcessData, 'term').map(function(item) {25 return item.term26 });27 property.value.store = property.value.store.concat(sortedData);28 return property.value.store;29 })30}31var defaultProcessor = function(inputValue) {32 // console.log($event.target)33 var key = this.full_field;34 // var target = $scope.searchOptions;35 var processedValue = null;36 switch(this.value.elType) {37 case 'text':38 processedValue = key + ':' + inputValue;39 break;40 case 'date':41 if (inputValue.startDate && inputValue.endDate) {42 processedValue = key + ':' + ('[' + moment(inputValue.startDate).format('YYYYMMDD') + '+TO+' + moment(inputValue.endDate).format('YYYYMMDD') + ']');43 }44 break;45 case 'range':46 if (this.value.max != inputValue.max || this.value.min != inputValue.min) {47 processedValue = key + ':' + ('[' + inputValue.min + '+TO+' + inputValue.max + ']');48 }49 break;50 case 'select':51 processedValue = key + ':' + inputValue;52 break;53 case 'multi_select':54 if (inputValue && inputValue.length > 0) {55 processedValue = '(' + key + ':' + inputValue.join('+') + ')'56 }57 break;58 default:59 throw 'Unknow elType';60 }61 return processedValue;62}63var safetyReportProperties = [];64function safetyPropertiesChild (node, parent) {65 angular.forEach(node, function(value, key){66 if(value.children) {67 safetyPropertiesChild(value.children, (parent ? parent + '.' + key : key));68 } else {69 var newValue = angular.copy(value)70 newValue.children = null;71 safetyReportProperties.push({field: key, full_field: (parent ? parent + '.' + key : key), value: newValue})72 }73 })74}75var safetyReportObject = {76 safetyreportversion: {77 visible: false,78 name: '',79 inTable: false,80 order: 50,81 elType: 'text',82 process: defaultProcessor,83 },84 safetyreportid: {85 visible: false,86 name: 'Report Id',87 inTable: true,88 order: 50,89 elType: 'text',90 process: defaultProcessor,91 },92 primarysourcecountry: {93 visible: false,94 name: '',95 inTable: false,96 order: 50,97 elType: 'text',98 process: defaultProcessor,99 },100 occurcountry: {101 visible: true,102 name: 'Country',103 inTable: true,104 order: 3,105 elType: 'multi_select',106 process: defaultProcessor,107 store: COUNTRIES_FULL,108 // preprocess: fetchTermsPreprocessor,109 trackByIndex: true110 },111 transmissiondateformat: {112 visible: false,113 name: '',114 inTable: false,115 order: 50,116 elType: 'text',117 process: defaultProcessor,118 },119 transmissiondate: {120 visible: false,121 name: '',122 inTable: false,123 order: 50,124 elType: 'date',125 process: defaultProcessor,126 },127 reporttype: {128 visible: false,129 name: '',130 inTable: false,131 order: 50,132 elType: 'text',133 process: defaultProcessor,134 },135 serious: {136 visible: false,137 name: '',138 inTable: false,139 order: 50,140 elType: 'checkbox',141 process: defaultProcessor,142 },143 seriousnesshospitalization: {144 visible: false,145 name: '',146 inTable: false,147 order: 50,148 elType: 'text',149 process: defaultProcessor,150 },151 receivedateformat: {152 visible: false,153 name: '',154 inTable: false,155 order: 50,156 elType: 'text',157 process: defaultProcessor,158 },159 receivedate: {160 visible: true,161 name: 'Report Date',162 inTable: true,163 order: 2,164 elType: 'date',165 process: defaultProcessor,166 },167 receiptdateformat: {168 visible: false,169 name: '',170 inTable: false,171 order: 50,172 elType: 'text',173 process: defaultProcessor,174 },175 receiptdate: {176 visible: false,177 name: '',178 inTable: false,179 order: 50,180 elType: 'date',181 process: defaultProcessor,182 },183 fulfillexpeditecriteria: {184 visible: false,185 name: '',186 inTable: false,187 order: 50,188 elType: 'text',189 process: defaultProcessor,190 },191 companynumb: {192 visible: false,193 name: '',194 inTable: false,195 order: 50,196 elType: 'text',197 process: defaultProcessor,198 },199 duplicate: {200 visible: false,201 name: '',202 inTable: false,203 order: 50,204 elType: 'text',205 process: defaultProcessor,206 },207 reportduplicate: {208 visible: false,209 name: '',210 inTable: false,211 order: 50,212 elType: 'expandable',213 process: defaultProcessor,214 children: {215 duplicatesource: {216 visible: false,217 name: '',218 inTable: false,219 order: 50,220 elType: 'text',221 process: defaultProcessor,222 },223 duplicatenumb: {224 visible: false,225 name: '',226 inTable: false,227 order: 50,228 elType: 'text',229 process: defaultProcessor,230 }231 }232 },233 // primarysource: {234 // reportercountry: "JP",235 // qualification: "1"236 // },237 primarysource: {238 visible: false,239 name: '',240 inTable: false,241 order: 50,242 elType: 'expandable',243 process: defaultProcessor,244 children: {245 reportercountry: {246 visible: false,247 name: 'Reporter Country',248 inTable: true,249 order: 20,250 elType: 'multi_select',251 process: defaultProcessor,252 store: [],253 preprocess: fetchTermsPreprocessor254 },255 qualification: {256 visible: true,257 name: 'Reporter Occupation',258 inTable: true,259 order: 21,260 elType: 'multi_select',261 process: defaultProcessor,262 trackByIndex: true,263 store: QUALIFICATIONS264 }265 }266 },267 // sender: {268 // sendertype: "2",269 // senderorganization: "FDA-Public Use "270 // },271 sender: {272 visible: false,273 name: '',274 inTable: false,275 order: 50,276 elType: 'expandable',277 process: defaultProcessor,278 children: {279 sendertype: {280 visible: false,281 name: '',282 inTable: false,283 order: 50,284 elType: 'text',285 process: defaultProcessor,286 },287 senderorganization: {288 visible: false,289 name: '',290 inTable: false,291 order: 50,292 elType: 'text',293 process: defaultProcessor,294 }295 }296 },297 // receiver: {298 // receivertype: "6",299 // receiverorganization: "FDA"300 // },301 receiver: {302 visible: false,303 name: '',304 inTable: false,305 order: 50,306 elType: 'expandable',307 process: defaultProcessor,308 children: {309 receivertype: {310 visible: false,311 name: '',312 inTable: false,313 order: 50,314 elType: 'text',315 process: defaultProcessor,316 },317 receiverorganization: {318 visible: false,319 name: '',320 inTable: false,321 order: 50,322 elType: 'text',323 process: defaultProcessor,324 }325 }326 },327 // patient: {328 // patientonsetage: "71.619",329 // patientonsetageunit: "801",330 // patientweight: "38",331 // patientsex: "2",332 // reaction: {333 // reactionmeddraversionpt: "18.0",334 // reactionmeddrapt: "Epilepsy",335 // reactionoutcome: "1"336 // },337 patient: {338 visible: false,339 name: '',340 inTable: false,341 order: 50,342 elType: 'expandable',343 process: defaultProcessor,344 children: {345 patientonsetage: {346 visible: true,347 name: 'Age',348 inTable: true,349 order: 12,350 elType: 'range',351 min: 0,352 max: 110,353 // modelMin: 0,354 // modelMax: 200,355 process: defaultProcessor,356 },357 patientonsetageunit: {358 visible: false,359 name: '',360 inTable: false,361 order: 50,362 elType: 'text',363 process: defaultProcessor,364 },365 patientweight: {366 visible: true,367 name: 'Weight(in Kg)',368 inTable: true,369 order: 13,370 elType: 'range',371 min: 5,372 max: 120,373 // modelMin: 5,374 // modelMax: 200,375 process: defaultProcessor,376 },377 patientsex: {378 visible: true,379 name: 'Gender',380 inTable: true,381 order: 14,382 elType: 'select',383 process: defaultProcessor,384 trackByIndex: true,385 store: SEX_VALUES386 },387 drug: {388 visible: false,389 name: '',390 inTable: false,391 order: 50,392 elType: 'expandable',393 process: defaultProcessor,394 children: {395 drugcharacterization: {396 visible: false,397 name: '',398 inTable: false,399 order: 50,400 elType: 'text',401 process: defaultProcessor,402 },403 medicinalproduct: {404 visible: true,405 name: 'Drug Name',406 inTable: false,407 order: 5,408 elType: 'multi_select',409 process: defaultProcessor,410 store: [],411 preprocess: fetchTermsPreprocessor412 },413 drugauthorizationnumb: {414 visible: false,415 name: '',416 inTable: false,417 order: 50,418 elType: 'text',419 process: defaultProcessor,420 },421 drugstructuredosagenumb: {422 visible: false,423 name: '',424 inTable: false,425 order: 50,426 elType: 'text',427 process: defaultProcessor,428 },429 drugstructuredosageunit: {430 visible: false,431 name: '',432 inTable: false,433 order: 50,434 elType: 'text',435 process: defaultProcessor,436 },437 drugseparatedosagenumb: {438 visible: false,439 name: '',440 inTable: false,441 order: 50,442 elType: 'text',443 process: defaultProcessor,444 },445 drugintervaldosageunitnumb: {446 visible: false,447 name: '',448 inTable: false,449 order: 50,450 elType: 'text',451 process: defaultProcessor,452 },453 drugintervaldosagedefinition: {454 visible: false,455 name: '',456 inTable: false,457 order: 50,458 elType: 'text',459 process: defaultProcessor,460 },461 drugadministrationroute: {462 visible: false,463 name: '',464 inTable: false,465 order: 50,466 elType: 'text',467 process: defaultProcessor,468 },469 drugindication: {470 visible: false,471 name: '',472 inTable: false,473 order: 50,474 elType: 'text',475 process: defaultProcessor,476 },477 drugstartdateformat: {478 visible: false,479 name: '',480 inTable: false,481 order: 50,482 elType: 'text',483 process: defaultProcessor,484 },485 drugstartdate: {486 visible: false,487 name: '',488 inTable: false,489 order: 50,490 elType: 'date',491 process: defaultProcessor,492 },493 drugenddateformat: {494 visible: false,495 name: '',496 inTable: false,497 order: 50,498 elType: 'text',499 process: defaultProcessor,500 },501 drugenddate: {502 visible: false,503 name: '',504 inTable: false,505 order: 50,506 elType: 'date',507 process: defaultProcessor,508 },509 drugbatchnumb: {510 visible: false,511 name: 'Lot Number',512 inTable: true,513 order: 50,514 elType: 'text',515 process: defaultProcessor,516 },517 drugcumulativedosagenumb: {518 visible: false,519 name: 'Cum Dose Chr',520 inTable: false,521 order: 30,522 elType: 'range',523 min: 0.5,524 max: 43885716,525 process: defaultProcessor,526 },527 drugcumulativedosageunit: {528 visible: false,529 name: 'Dose Unit',530 inTable: false,531 order: 32,532 elType: 'multi_select',533 store: DRUG_UNIT,534 trackByIndex: true,535 // preprocess: fetchTermsPreprocessor,536 // trackByIndex: false,537 process: defaultProcessor,538 },539 drugdosageform: {540 visible: false,541 name: 'Dose Form',542 inTable: false,543 order: 33,544 elType: 'multi_select',545 store: [],546 preprocess: fetchTermsPreprocessor,547 trackByIndex: false,548 process: defaultProcessor,549 },550 drugintervaldosagedefinition: {551 visible: false ,552 name: 'Dose Frequency',553 inTable: false,554 order: 34,555 elType: 'multi_select',556 store: DRUG_FREQUENCY,557 // preprocess: fetchTermsPreprocessor,558 trackByIndex: true,559 process: defaultProcessor,560 },561 actiondrug: {562 visible: false,563 name: '',564 inTable: false,565 order: 50,566 elType: 'text',567 process: defaultProcessor,568 },569 activesubstance: {570 visible: false,571 name: '',572 inTable: false,573 order: 50,574 elType: 'text',575 process: defaultProcessor,576 children: {577 activesubstancename: {578 visible: false,579 name: '',580 inTable: false,581 order: 50,582 elType: 'text',583 process: defaultProcessor,584 }585 }586 },587 }588 },589 reaction: {590 visible: false,591 name: '',592 inTable: false,593 order: 50,594 elType: 'text',595 process: defaultProcessor,596 children: {597 reactionmeddraversionpt: {598 visible: false,599 name: '',600 inTable: false,601 order: 50,602 elType: 'text',603 process: defaultProcessor,604 },605 reactionmeddrapt: {606 visible: false,607 name: '',608 inTable: false,609 order: 50,610 elType: 'text',611 process: defaultProcessor,612 },613 reactionoutcome: {614 visible: true,615 name: 'Patient Outcome',616 inTable: true,617 order: 6,618 elType: 'select',619 process: defaultProcessor,620 store: REACTION_OUTCOMES,621 trackByIndex: true622 }623 }624 },625 },626 // drug: {627 // drugcharacterization: "1",628 // medicinalproduct: "TOCILIZUMAB",629 // drugauthorizationnumb: "125472",630 // drugstructuredosagenumb: "162",631 // drugstructuredosageunit: "003",632 // drugseparatedosagenumb: "1",633 // drugintervaldosageunitnumb: "2",634 // drugintervaldosagedefinition: "803",635 // drugadministrationroute: "058",636 // drugindication: "RHEUMATOID ARTHRITIS",637 // drugstartdateformat: "102",638 // drugstartdate: "20130730",639 // drugenddateformat: "610",640 // drugenddate: "201312",641 // actiondrug: "1",642 // activesubstance: { activesubstancename: "TOCILIZUMAB" }643 // },644 },645 // summary: {646 // narrativeincludeclinical: "CASE EVENT DATE: 20131216"647 // }648 summary: {649 visible: false,650 name: '',651 inTable: false,652 order: 50,653 elType: 'expandable',654 process: defaultProcessor,655 children: {656 narrativeincludeclinical: {657 visible: false,658 name: '',659 inTable: false,660 order: 50,661 elType: 'text',662 process: defaultProcessor,663 }664 }665 }666}...
horsey.js
Source:horsey.js
1!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.horsey=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){2'use strict';3var crossvent = require('crossvent');4var bullseye = require('bullseye');5var fuzzysearch = require('fuzzysearch');6var KEY_ENTER = 13;7var KEY_ESC = 27;8var KEY_UP = 38;9var KEY_DOWN = 40;10function horsey (input, options) {11 var o = options || {};12 var parent = o.appendTo || document.body;13 var render = o.render || defaultRenderer;14 var getText = o.getText || defaultGetText;15 var getValue = o.getValue || defaultGetValue;16 var set = o.set || defaultSetter;17 var form = o.form;18 var suggestions = o.suggestions;19 var filter = o.filter || defaultFilter;20 var ul = tag('ul', 'sey-list');21 var selection = null;22 var oneload = once(loading);23 var eye;24 var deferredFiltering = defer(filtering);25 if (o.autoHideOnBlur === void 0) { o.autoHideOnBlur = true; }26 if (o.autoHideOnClick === void 0) { o.autoHideOnClick = true; }27 parent.appendChild(ul);28 input.setAttribute('autocomplete', 'off');29 if (Array.isArray(suggestions)) {30 loaded(suggestions);31 } else if (typeof suggestions === 'function') {32 crossvent.add(input, 'focus', oneload);33 }34 inputEvents();35 eye = bullseye(ul, input);36 return {37 add: add,38 clear: clear,39 show: show,40 hide: hide,41 destroy: destroy42 };43 function loading () {44 crossvent.remove(input, 'focus', oneload);45 suggestions(loaded);46 }47 function loaded (suggestions) {48 suggestions.forEach(add);49 }50 function clear () {51 while (ul.lastChild) {52 ul.removeChild(ul.lastChild);53 }54 }55 function add (suggestion) {56 var li = tag('li', 'sey-item');57 render(li, suggestion);58 crossvent.add(li, 'click', select);59 crossvent.add(li, 'filter', filterItem);60 ul.appendChild(li);61 return li;62 function select () {63 set(getValue(suggestion));64 hide();65 input.focus();66 crossvent.fabricate(input, 'horsey-selected');67 }68 function filterItem () {69 var value = input.value;70 if (filter(value, suggestion)) {71 li.className = li.className.replace(/ sey-hide/g, '');72 } else if (!hidden(li)) {73 li.className += ' sey-hide';74 if (selection === li) {75 unselect();76 }77 }78 }79 }80 function visible () {81 return ul.className.indexOf('sey-show') !== -1;82 }83 function hidden (li) {84 return li.className.indexOf('sey-hide') !== -1;85 }86 function show () {87 if (!visible()) {88 ul.className += ' sey-show';89 eye.refresh();90 }91 }92 function select (el) {93 unselect();94 if (el) {95 selection = el;96 selection.className += ' sey-selected';97 }98 }99 function unselect () {100 if (selection) {101 selection.className = selection.className.replace(/ sey-selected/g, '');102 selection = null;103 }104 }105 function move (up, moves) {106 var total = ul.children.length;107 if (total < moves) {108 unselect();109 return;110 }111 if (total === 0) {112 return;113 }114 var first = up ? 'lastChild' : 'firstChild';115 var next = up ? 'previousSibling' : 'nextSibling';116 var el = selection && selection[next] || ul[first];117 select(el);118 if (hidden(el)) {119 move(up, moves ? moves + 1 : 1);120 }121 }122 function hide () {123 ul.className = ul.className.replace(/ sey-show/g, '');124 unselect();125 }126 function keydown (e) {127 var shown = visible();128 var which = e.which || e.keyCode;129 if (which === KEY_DOWN) {130 show();131 if (shown) {132 move();133 }134 stop(e);135 } else if (which === KEY_UP) {136 show();137 move(true);138 stop(e);139 } else if (which === KEY_ENTER && shown) {140 if (selection) {141 crossvent.fabricate(selection, 'click');142 } else {143 hide();144 }145 stop(e);146 } else if (which === KEY_ESC) {147 hide();148 stop(e);149 }150 }151 function stop (e) {152 e.stopPropagation();153 e.preventDefault();154 }155 function filtering () {156 if (!visible()) {157 return;158 }159 var li = ul.firstChild;160 while (li) {161 crossvent.fabricate(li, 'filter');162 li = li.nextSibling;163 }164 if (!selection) {165 move();166 }167 if (!selection) {168 hide();169 }170 }171 function deferredKeydown (e) {172 var which = e.which || e.keyCode;173 if (which === KEY_ENTER) {174 return;175 }176 deferredFiltering();177 }178 function deferredShow (e) {179 var which = e.which || e.keyCode;180 if (which === KEY_ENTER) {181 return;182 }183 setTimeout(show, 0);184 }185 function horseyEventTarget (e) {186 var target = e.target;187 if (target === input) {188 return true;189 }190 while (target) {191 if (target === ul) {192 return true;193 }194 target = target.parentNode;195 }196 }197 function hideOnBlur (e) {198 if (horseyEventTarget(e)) {199 return;200 }201 hide();202 }203 function hideOnClick (e) {204 if (horseyEventTarget(e)) {205 return;206 }207 hide();208 }209 function inputEvents (remove) {210 var op = remove ? 'remove' : 'add';211 crossvent[op](input, 'keypress', deferredShow);212 crossvent[op](input, 'keypress', deferredFiltering);213 crossvent[op](input, 'paste', deferredFiltering);214 crossvent[op](input, 'keydown', deferredKeydown);215 crossvent[op](input, 'keydown', keydown);216 if (o.autoHideOnBlur) { crossvent[op](document.documentElement, 'focus', hideOnBlur, true); }217 if (o.autoHideOnClick) { crossvent[op](document, 'click', hideOnClick); }218 if (form) { crossvent[op](form, 'submit', hide); }219 }220 function destroy () {221 inputEvents(true);222 eye.destroy();223 parent.removeChild(ul);224 crossvent.remove(input, 'focus', oneload);225 }226 function defaultSetter (value) {227 input.value = value;228 }229 function defaultRenderer (li, suggestion) {230 li.innerText = li.textContent = getText(suggestion);231 }232 function defaultFilter (q, suggestion) {233 var text = getText(suggestion) || '';234 var value = getValue(suggestion) || '';235 return fuzzysearch(q, text.toLowerCase()) || fuzzysearch(q, value.toLowerCase());236 }237}238function defaultGetValue (suggestion) {239 return typeof suggestion === 'string' ? suggestion : suggestion.value;240}241function defaultGetText (suggestion) {242 return typeof suggestion === 'string' ? suggestion : suggestion.text;243}244function tag (type, className) {245 var el = document.createElement(type);246 el.className = className;247 return el;248}249function once (fn) {250 var disposed;251 function disposable () {252 if (disposed) { return; }253 disposed = true;254 (fn || noop).apply(null, arguments);255 }256 return disposable;257}258function defer (fn) {259 return function () {260 setTimeout(fn, 0);261 };262}263function noop () {}264module.exports = horsey;265},{"bullseye":2,"crossvent":5,"fuzzysearch":6}],2:[function(require,module,exports){266'use strict';267var crossvent = require('crossvent');268var throttle = require('./throttle');269function bullseye (el, target, options) {270 var o = options || {};271 var destroyed = false;272 var throttledPosition = throttle(position, 30);273 position();274 if (o.tracking !== false) {275 crossvent.add(window, 'resize', throttledPosition);276 }277 return {278 refresh: position,279 destroy: destroy280 };281 function position () {282 if (destroyed) {283 throw new Error('Bullseye can\'t refresh after being destroyed. Create another instance instead.');284 }285 var bounds = target.getBoundingClientRect();286 var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;287 el.style.top = bounds.top + scrollTop + target.offsetHeight + 'px';288 el.style.left = bounds.left + 'px';289 }290 function destroy () {291 crossvent.remove(window, 'resize', throttledPosition);292 destroyed = true;293 }294}295module.exports = bullseye;296},{"./throttle":4,"crossvent":3}],3:[function(require,module,exports){297(function (global){298'use strict';299var addEvent = addEventEasy;300var removeEvent = removeEventEasy;301var hardCache = [];302if (!global.addEventListener) {303 addEvent = addEventHard;304 removeEvent = removeEventHard;305}306function addEventEasy (el, type, fn, capturing) {307 return el.addEventListener(type, fn, capturing);308}309function addEventHard (el, type, fn, capturing) {310 return el.attachEvent('on' + type, wrap(el, type, fn), capturing);311}312function removeEventEasy (el, type, fn) {313 return el.removeEventListener(type, fn);314}315function removeEventHard (el, type, fn) {316 return el.detachEvent('on' + type, unwrap(el, type, fn));317}318function fabricateEvent (el, type) {319 var e = document.createEvent('Event');320 e.initEvent(type, true, true);321 el.dispatchEvent(e);322}323function wrapperFactory (el, type, fn) {324 return function wrapper (originalEvent) {325 var e = originalEvent || global.event;326 e.target = e.target || e.srcElement;327 e.preventDefault = e.preventDefault || function preventDefault () { e.returnValue = false; };328 e.stopPropagation = e.stopPropagation || function stopPropagation () { e.cancelBubble = true; };329 fn.call(el, e);330 };331}332function wrap (el, type, fn) {333 var wrapper = unwrap(el, type, fn) || wrapperFactory(el, type, fn);334 hardCache.push({335 wrapper: wrapper,336 element: el,337 type: type,338 fn: fn339 });340 return wrapper;341}342function unwrap (el, type, fn) {343 var i = find(el, type, fn);344 if (i) {345 var wrapper = hardCache[i].wrapper;346 hardCache.splice(i, 1); // free up a tad of memory347 return wrapper;348 }349}350function find (el, type, fn) {351 var i, item;352 for (i = 0; i < hardCache.length; i++) {353 item = hardCache[i];354 if (item.element === el && item.type === type && item.fn === fn) {355 return i;356 }357 }358}359module.exports = {360 add: addEvent,361 remove: removeEvent,362 fabricate: fabricateEvent363};364}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})365},{}],4:[function(require,module,exports){366'use strict';367function throttle (fn, boundary) {368 var last = -Infinity;369 var timer;370 return function bounced () {371 if (timer) {372 return;373 }374 unbound();375 function unbound () {376 clearTimeout(timer);377 timer = null;378 var next = last + boundary;379 var now = Date.now();380 if (now > next) {381 last = now;382 fn.apply(this, arguments);383 } else {384 timer = setTimeout(unbound, next - now);385 }386 }387 };388}389module.exports = throttle;390},{}],5:[function(require,module,exports){391(function (global){392'use strict';393var addEvent = addEventEasy;394var removeEvent = removeEventEasy;395var hardCache = [];396if (!global.addEventListener) {397 addEvent = addEventHard;398 removeEvent = removeEventHard;399}400function addEventEasy (el, type, fn, capturing) {401 return el.addEventListener(type, fn, capturing);402}403function addEventHard (el, type, fn, capturing) {404 return el.attachEvent('on' + type, wrap(el, type, fn), capturing);405}406function removeEventEasy (el, type, fn) {407 return el.removeEventListener(type, fn);408}409function removeEventHard (el, type, fn) {410 return el.detachEvent('on' + type, unwrap(el, type, fn));411}412function fabricateEvent (el, type) {413 var e = document.createEvent('Event');414 e.initEvent(type, true, true);415 el.dispatchEvent(e);416}417function wrapperFactory (el, type, fn) {418 return function wrapper (originalEvent) {419 var e = originalEvent || global.event;420 e.target = e.target || e.srcElement;421 e.preventDefault = e.preventDefault || function preventDefault () { e.returnValue = false; };422 e.stopPropagation = e.stopPropagation || function stopPropagation () { e.cancelBubble = true; };423 fn.call(el, e);424 };425}426function wrap (el, type, fn) {427 var wrapper = unwrap(el, type, fn) || wrapperFactory(el, type, fn);428 hardCache.push({429 wrapper: wrapper,430 element: el,431 type: type,432 fn: fn433 });434 return wrapper;435}436function unwrap (el, type, fn) {437 var i = find(el, type, fn);438 if (i) {439 var wrapper = hardCache[i].wrapper;440 hardCache.splice(i, 1); // free up a tad of memory441 return wrapper;442 }443}444function find (el, type, fn) {445 var i, item;446 for (i = 0; i < hardCache.length; i++) {447 item = hardCache[i];448 if (item.element === el && item.type === type && item.fn === fn) {449 return i;450 }451 }452}453module.exports = {454 add: addEvent,455 remove: removeEvent,456 fabricate: fabricateEvent457};458}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})459},{}],6:[function(require,module,exports){460'use strict';461function fuzzysearch (query, text) {462 var tlen = text.length;463 var qlen = query.length;464 if (qlen > tlen) {465 return false;466 }467 if (qlen === tlen && query === text) {468 return true;469 }470 outer: for (var i = 0, j = 0; i < qlen; i++) {471 var qch = query.charCodeAt(i);472 while (j < tlen) {473 if (text.charCodeAt(j++) === qch) {474 continue outer;475 }476 }477 return false;478 }479 return true;480}481module.exports = fuzzysearch;482},{}]},{},[1])(1)...
event-v0.5.js
Source:event-v0.5.js
1/**2 * Event v0.53 * Copyright (c) 2011 snandy4 * 5 * 1, 解å³IE fnä¸ä¸¢å¤±this6 * 2, ç»ä¸äºäºä»¶å¯¹è±¡ä½ä¸ºfnç第ä¸ä¸ªåæ°7 * 3, 解å³äºåä¸ä¸ªäºä»¶çhandlersæ§è¡é¡ºåºé®é¢(IEæ åºï¼FF/Safari/Chrome/Operaä¸é¡ºåº)8 * 4, addæ¹æ³æ°å¢onceåæ°ï¼fnåªæ§è¡ä¸æ¬¡9 * 5, removeæ¹æ³æ°å¢å é¤å
ç´ typeç±»åçææçå¬å¨(åæ°ä¼ elï¼type)10 * 6, remvoeæ¹æ³æ°å¢å é¤å
ç´ ææççå¬å¨(åæ°ä¼ el)11 * 7, 解å³äºä»¶å¯¹è±¡çå
¼å®¹æ§é®é¢ï¼å¦é»æ¢é»è®¤è¡ä¸ºï¼åæ¢å泡çï¼æ¯æDOM2/3 eventsï¼12 * 8, éæ13 * 9, 使ç¨guidï¼HTMLElenentä¸ä¸åæeventså±æ§14 * 10, æ¥å£ä¿®æ¹ï¼æ·»å once/delay/scope/stopEvent/preventDefault/stopPropagation15 * 16 * Example17 * 18 * 1, æ·»å ä¸ä¸ªç®åäºä»¶19 * E.on(el, 'click', fn)20 * 21 * 2, æ·»å ä¸ä¸ªå¯é
ç½®çäºä»¶22 * E.on(el, 'click', fn, {23 * once : // trueå该handlerä»
æ§è¡ä¸æ¬¡24 * delay : // handler延è¿æ§è¡çæ¶é´ï¼ä»¥æ¯«ç§ä¸ºåä½25 * scope : // handleræ§è¡ä¸ä¸æï¼é»è®¤ä¸ºel26 * stopEvent : // é»æ¢elé»è®¤è¡ä¸ºï¼åæ¢å泡27 * preventDefault : // é»æ¢é»è®¤è¡ä¸º28 * stopPropagation : // åæ¢å泡29 * });30 *31 */3233E = function(window, document){34 35 var guid = 1,36 37 evtHash = {},38 39 w3c = !!window.addEventListener,40 41 addListener = w3c ?42 function(el, type, fn) { el.addEventListener(type, fn, false); } :43 function(el, type, fn) { el.attachEvent('on' + type, fn); },44 45 removeListener = w3c ?46 function(el, type, fn) { el.removeEventListener(type, fn, false); } :47 function(el, type, fn) { el.detachEvent('on' + type, fn); };48 49 dispatch = w3c ?50 function(el, type){51 try{52 var evt = document.createEvent('Event');53 evt.initEvent(type,true,true);54 el.dispatchEvent(evt);55 }catch(e){alert(e)};56 } :57 function(el, type){58 try{59 el.fireEvent('on'+type);60 }catch(e){alert(e)}61 };62 63 function _isEmptyObj(obj){64 for(var a in obj){65 return false;66 }67 return true;68 }69 function _each(ary, callback){70 for(var i=0; i<ary.length;){ 71 callback(i, ary[i]) ? i=0 : i++;72 }73 }74 function _remove(el, type, guid){75 removeListener(el, type, evtHash[guid][type]['_handler_']);76 delete evtHash[guid][type];77 if(_isEmptyObj(evtHash[guid])){78 delete evtHash[guid];79 }80 }81 function _fixEvent( evt, el ) {82 var props = "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),83 len = props.length;84 function now() {return (new Date).getTime();}85 function returnFalse() {return false;}86 function returnTrue() {return true;}87 function Event( src ) {88 this.originalEvent = src;89 this.type = src.type;90 this.timeStamp = now();91 }92 Event.prototype = {93 preventDefault: function() {94 this.isDefaultPrevented = returnTrue;95 var e = this.originalEvent;96 if( e.preventDefault ) {97 e.preventDefault();98 }99 e.returnValue = false;100 },101 stopPropagation: function() {102 this.isPropagationStopped = returnTrue;103 var e = this.originalEvent;104 if( e.stopPropagation ) {105 e.stopPropagation();106 } 107 e.cancelBubble = true;108 },109 stopImmediatePropagation: function() {110 this.isImmediatePropagationStopped = returnTrue;111 this.stopPropagation();112 },113 isDefaultPrevented: returnFalse,114 isPropagationStopped: returnFalse,115 isImmediatePropagationStopped: returnFalse116 };117118 var originalEvent = evt;119 evt = new Event(originalEvent);120 121 for(var i = len, prop; i;) {122 prop = props[ --i ];123 evt[ prop ] = originalEvent[ prop ];124 }125 if(!evt.target) {126 evt.target = evt.srcElement || document;127 }128 if( evt.target.nodeType === 3 ) {129 evt.target = evt.target.parentNode;130 }131 if( !evt.relatedTarget && evt.fromElement ) {132 evt.relatedTarget = evt.fromElement === evt.target ? evt.toElement : evt.fromElement;133 }134 if( evt.pageX == null && evt.clientX != null ) {135 var doc = document.documentElement, body = document.body;136 evt.pageX = evt.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);137 evt.pageY = evt.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);138 }139 if( !evt.which && ((evt.charCode || evt.charCode === 0) ? evt.charCode : evt.keyCode) ) {140 evt.which = evt.charCode || evt.keyCode;141 }142 if( !evt.metaKey && evt.ctrlKey ) {143 evt.metaKey = evt.ctrlKey;144 }145 if( !evt.which && evt.button !== undefined ) {146 evt.which = (evt.button & 1 ? 1 : ( evt.button & 2 ? 3 : ( evt.button & 4 ? 2 : 0 ) ));147 } 148 if(!evt.currentTarget) evt.currentTarget = el;149 return evt;150 }151 152 function _callback(el, type, evt, handleObj){153 154 var fn = handleObj.fn,155 once = handleObj.once,156 delay = handleObj.delay,157 scope = handleObj.scope || el,158 stopEvent = handleObj.stopEvent,159 preventDefault = handleObj.preventDefault,160 stopPropagation = handleObj.stopPropagation;161 162 if(stopEvent){163 evt.preventDefault();164 evt.stopPropagation();165 }166 if(preventDefault){167 evt.preventDefault();168 }169 if(stopPropagation){170 evt.stopPropagation();171 }172 if(delay){173 (function(fn, scope, evt){174 setTimeout(function(){175 fn.call(scope, evt);176 },delay);177 })(fn, scope, evt);178 }else{179 fn.call(scope, evt);180 }181 182 if(once){183 remove(el, type, fn);184 return true;185 }186 }187 // æ·»å äºä»¶188 function add(el, type, fn, opt){189 var gid, listeners, handleObj = {};190 191 gid = el.guid = el.guid || guid++;192 evtHash[gid] = evtHash[gid] || {};193 listeners = evtHash[gid][type] = evtHash[gid][type] || [];194 195 if(opt){196 handleObj = opt;197 }198 handleObj.fn = fn;199 listeners.push(handleObj);200 201 if(!listeners['_handler_']){202 listeners['_handler_'] = function(evt){203 var evt = _fixEvent(evt||window.event, el);204 for(var i=0,handleObj; handleObj=listeners[i++];){205 if(_callback(el, type, evt, handleObj)){206 i--;207 }208 }209 }210 addListener(el, type, listeners['_handler_']);211 }212 }213 // å é¤äºä»¶214 function remove(el, type, fn){215 var gid = el.guid;216 if(!gid) return;217 218 var events = evtHash[gid],219 listeners = events[type],220 len = arguments.length;221 222 switch(len){223 case 1 :224 for(var type in events){225 _remove(el, type, gid);226 }227 break;228 case 2 :229 _remove(el, type, gid);230 break;231 case 3 :232 _each(listeners, function(i, handleObj){233 if(handleObj.fn == fn){234 return listeners.splice(i, 1);235 }236 });237 if(listeners.length == 0){238 _remove(el, type, gid);239 }240 break;241 }242 }243 244 return {245 on : add,246 un : remove,247 fire : dispatch248 };249
...
jquery.forms.js
Source:jquery.forms.js
1/* Custom form elements */2/* Created by Vladimir Khodakov (web-interface.info team) */3/* Modified by Grigory Zarubin (Shogo.Ru) */45;(function($) {6 $.fn.forms = function(options) {7 var opt = $.extend({}, $.fn.forms.defaults, options);89 return this.each(function() {10 var el = $(this);11 el.type = el.attr('type');12 if(el.is('input') && opt[el.type] && !el.next().hasClass(el.type)) {13 var tname = el.attr('name');14 var tid = el.attr('id');15 el.name = (tname !== undefined && tname != '') ? tname.replace(/[\[\]]/g, '') : ((tid !== undefined && tid != '') ? tid.replace(/[\[\]]/g, '') : (Math.round(Math.random()*10000)+1));16 el.replace = (el.type != 'file') ? '<span class="'+el.type+' el-name-'+el.name+'"></span>' : '<span class="'+el.type+'"><span class="input"></span><span class="button">'+opt.file_bt+'</span></span>';17 el.handle = el.after(el.replace);18 el.hide();19 switch(el.type) {20 case 'checkbox':21 if(el.attr('checked')) {22 el.next().addClass('check_'+el.type);23 }24 el.next().click(function() {25 $(this).toggleClass('check_'+el.type);26 if(!el.prop('checked')) {27 el.prop('checked', true).trigger('change');28 } else {29 el.prop('checked', false).trigger('change');30 }31 });32 el.click(function() {33 el.next().toggleClass('check_'+el.type);34 });35 $('label[for="' + tid + '"]').click(function(e) {36 e.preventDefault();37 var inp = $('#' + $(this).attr('for'));38 inp.next().toggleClass('check_'+el.type);39 if(!inp.prop('checked')) {40 inp.prop('checked', true).trigger('change');41 } else {42 inp.prop('checked', false).trigger('change');43 }44 });45 break;46 case 'radio':47 if(el.attr('checked')) {48 el.next().addClass('check_'+el.type);49 }50 el.show().css({'position':'absolute', 'top':'-10000px', 'left':'-10000px', 'visibility':'hidden'});51 el.next().click(function() {52 if(!el.is(':checked')) {53 $('.el-name-'+el.name).removeClass('check_'+el.type);54 el.attr('checked', true);55 $(this).addClass('check_'+el.type);56 }57 });58 el.click(function() {59 $('.el-name-'+el.name).removeClass('check_'+el.type);60 el.attr('checked', true);61 el.next().addClass('check_'+el.type);62 });63 break;64 case 'file':65 el.id = el.attr('id');66 el.show();67 el.emulate = el.next();68 el.emulate.append(el);69 el.emulate.css({'position':'relative', 'overflow':'hidden'});70 el.emulate.children('input').css({'opacity':'0', 'font-size':'199px', 'top':'0', 'left':'0', 'position':'absolute', 'cursor':'pointer', 'padding':'0', 'margin':'0 0 0 -550px', 'border':'none', 'z-index':'10000', 'background':'#000000', 'direction':'rtl'});71 el.emulate.find('input').change(function() {72 el.emulate.find('.input').html($(this).val());73 });74 break;75 }76 }77 });78 };7980 $.fn.forms.defaults = {81 checkbox : true,82 radio : true,83 file : true,84 file_bt : 'Îáçîð'85 };
...
ewf-param-icon.js
Source:ewf-param-icon.js
1(function($){2 "use strict";3 4 // wpb_el_type_position5 6 $('.wpb-element-edit-modal .wpb_el_type_ewf-icon i').click(function(){7 var value = $(this).attr('class');8 var seletected_field = $(this).closest('.wpb_el_type_ewf-icon');9 10 $(this).closest('ul').find('.selected').removeClass('selected');11 $(this).closest('li').addClass('selected');12 $(this).closest('.wpb_el_type_ewf-icon').find('input.wpb_vc_param_value').val(value);13 14 $('.ewf-icon-ct-selection i', seletected_field).attr('class', value);15 16 });17 18 19 $('.wpb-element-edit-modal .wpb_el_type_ewf-icon .ewf-icon-ct-cancel').click(function(){20 var field = $(this).closest('.wpb_el_type_ewf-icon');21 var cancel = $(this);22 23 24 $(cancel).hide();25 26 $('.ewf-icon-ct-change', field).html('Change Icon');27 $('.ewf-icon-filters', field).hide(); 28 return false;29 30 });31 32 $('.wpb-element-edit-modal .wpb_el_type_ewf-icon .ewf-icon-ct-selection').click(function(){33 var field = $(this).closest('.wpb_el_type_ewf-icon');34 35 $('.ewf-icon-ct-change').click(); 36 });37 38 $('.wpb-element-edit-modal .wpb_el_type_ewf-icon .ewf-icon-ct-change').click(function(){39 var field = $(this).closest('.wpb_el_type_ewf-icon');40 41 42 if ($(this).html() == "Change Icon"){43 $('.ewf-icon-filters', field).slideDown(); 44 $('.ewf-icon-ct-cancel', field).show(); 45 $(this).html('Use Icon');46 return false;47 }48 49 if ($(this).html() == "Use Icon"){50 $('.ewf-icon-filters', field).slideUp(); 51 $('.ewf-icon-ct-cancel', field).hide(); 52 $(this).html('Change Icon');53 return false;54 }55 56 57 58 });59 60 $('.wpb-element-edit-modal .wpb_el_type_ewf-icon ul').each(function(){61 var seletected_field = $(this).closest('.wpb_el_type_ewf-icon');62 var selected_icon = $('input.wpb_vc_param_value', seletected_field).val();63 64 65 if (selected_icon != ''){66 $('li', this).removeClass('selected');67 $('i[class="'+selected_icon+'"]', this).closest('li').addClass('selected');68 }69 });70 71 ...
initbranches.js
Source:initbranches.js
1;(function(){2 /**3 * åå§ååæ¯æ¯ä¸ç§ä¼å模å¼ï¼å½ç¥éæ个æ¡ä»¶å¨æ´ä¸ªçå½å¨æå
é½ä¸ä¼åçååæ¶ï¼ä»
对该æ¡ä»¶æµè¯ä¸æ¬¡ã4 */5 6 // ä¸è¬åæ³7 var util = {8 addEvent: function(el, type, fn) {9 if(window.addEventListener{10 el.addEventListener(type, fn, false)11 }else if(document.attachEvent) {12 el.attachEvent('on' + type, fn);13 }else{14 el['on' + type] = fn;15 }16 },17 removeEvent: function() {18 // 类似addEvent19 }20 }2122 // ä¼ååæ³ãå
å®ä¹æ¥å£ï¼åå®ç°åå£ï¼è¾¾å°äºåªééªè¯ä¸æ¬¡çç®ç23 var util = {24 addEvent: null,25 removeEvent: null26 };27 if(window.addEventListener {28 util.addEvent = function(el, type, fn) {29 el.addEventListener(type, fn, false)30 };31 util.removeEvent = function(el, type, fn) {32 el.removeEventListener(type, fn, false)33 }34 } else if(document.attachEvent) {35 util.addEvent = function(el, type, fn) {36 el.attachEvent('on' + type, fn)37 };38 util.removeEvent = function(el, type, fn) {39 el.detachEvent('on' + type, fn)40 }41 } else {42 util.addEvent = function(el, type, fn) {43 el['on' + type] = fn;44 };45 util.removeEvent = function(el, type, fn) {46 el['on' + type] = null;47 }48 }
...
Using AI Code Generation
1const wdio = require('webdriverio');2const assert = require('assert');3const opts = {4 capabilities: {5 }6};7async function main () {8 const client = await wdio.remote(opts);9 const el = await client.$('~test');10 const type = await el.type();11 console.log(type);12 assert.equal(type, 'XCUIElementTypeTextField');13}14main();15const wdio = require('webdriverio');16const assert = require('assert');17const opts = {18 capabilities: {19 }20};21async function main () {22 const client = await wdio.remote(opts);23 const el = await client.$('~test');24 const type = await el.type();25 console.log(type);26 assert.equal(type, 'XCUIElementTypeTextField');27}28main();
Using AI Code Generation
1console.log(await driver.execute('mobile: el.type', {id: 'id', text: 'text'}));2console.log(await driver.execute('mobile: el.type', {id: 'id', text: 'text', duration: 2}));3console.log(await driver.execute('mobile: el.type', {id: 'id', text: 'text', duration: 2, frequency: 2}));4console.log(await driver.execute('mobile: el.type', {id: 'id', text: 'text', duration: 2, frequency: 2, cancel: true}));5console.log(await driver.execute('mobile: el.type', {id: 'id', text: 'text', duration: 2, frequency: 2, cancel: true, locale: 'en_US'}));6console.log(await driver.execute('mobile: el.type', {id: 'id', text: 'text', duration: 2, frequency: 2, cancel: true, locale: 'en_US', returnKey: 'return'}));7console.log(await driver.execute('mobile: el.type', {id: 'id', text: 'text', duration: 2, frequency: 2, cancel: true, locale: 'en_US', returnKey: 'return', keyName: 'key'}));8console.log(await driver.execute('mobile: el.type', {id: 'id', text: 'text', duration: 2, frequency: 2, cancel: true, locale: 'en_US', returnKey: 'return', keyName: 'key', label: 'label'}));
Using AI Code Generation
1var el = await driver.$('XCUIElementTypeButton');2console.log(await el.getAttribute('type'));3var el = await driver.$('XCUIElementTypeButton');4console.log(await el.getAttribute('type'));5var el = await driver.$('XCUIElementTypeButton');6console.log(await el.getAttribute('type'));7var el = await driver.$('XCUIElementTypeButton');8console.log(await el.getAttribute('type'));9var el = await driver.$('XCUIElementTypeButton');10console.log(await el.getAttribute('type'));11var el = await driver.$('XCUIElementTypeButton');12console.log(await el.getAttribute('type'));13var el = await driver.$('XCUIElementTypeButton');14console.log(await el.getAttribute('type'));15var el = await driver.$('XCUIElementTypeButton');16console.log(await el.getAttribute('type'));17var el = await driver.$('XCUIElementTypeButton');18console.log(await el.getAttribute('type'));19var el = await driver.$('XCUIElementTypeButton');20console.log(await el.getAttribute('type'));21var el = await driver.$('XCUIElementTypeButton');22console.log(await el.getAttribute('type'));
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desired = {4};5 .init(desired)6 .elementByAccessibilityId('Add')7 .then(function (el) {8 el.type('Hello, World!');9 })10 .fin(function () { return driver.quit(); })11 .done();12var wd = require('wd');13var assert = require('assert');14var desired = {15};16 .init(desired)17 .elementByAccessibilityId('Add')18 .then(function (el) {19 el.type('Hello, World!');20 })21 .fin(function () { return driver.quit(); })22 .done();23var wd = require('wd');24var assert = require('assert');25var desired = {26};27 .init(desired)28 .elementByAccessibilityId('Add
Using AI Code Generation
1var el = driver.findElement(By.id("textfield"));2var type = el.type('text');3console.log(type);4var el = driver.findElement(By.id("textfield"));5var clear = el.clear();6console.log(clear);7var el = driver.findElement(By.id("textfield"));8var sendKeys = el.sendKeys('text');9console.log(sendKeys);10var el = driver.findElement(By.id("textfield"));11var getText = el.getText();12console.log(getText);13var el = driver.findElement(By.id("textfield"));14var getAttribute = el.getAttribute('value');15console.log(getAttribute);16var el = driver.findElement(By.id("textfield"));17var getLocation = el.getLocation();18console.log(getLocation);19var el = driver.findElement(By.id("textfield"));20var getSize = el.getSize();21console.log(getSize);22var el = driver.findElement(By.id("textfield"));23var getTagName = el.getTagName();24console.log(getTagName);25var el = driver.findElement(By.id("textfield"));26var isDisplayed = el.isDisplayed();27console.log(isDisplayed);28var el = driver.findElement(By.id("textfield"));29var isEnabled = el.isEnabled();30console.log(isEnabled);31var el = driver.findElement(By.id("textfield"));32var isSelected = el.isSelected();33console.log(isSelected);34var el = driver.findElement(By.id("textfield"));
Using AI Code Generation
1const el = await driver.$("~test-Label");2const type = await el.getAttribute("type");3console.log(type);4const el = await driver.$("~test-Label");5const type = await el.getAttribute("type");6const parent = await el.$(`.${type}`);7const parentType = await parent.getAttribute("type");8console.log(parentType);9const el = await driver.$("~test-Label");10const type = await el.getAttribute("type");11const child = await el.$(`.${type}`);12const childType = await child.getAttribute("type");13console.log(childType);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!