How to use computed method in Playwright Internal

Best JavaScript code snippet using playwright-internal

ember_computed.js

Source:ember_computed.js Github

copy

Full Screen

...72function generateComputedWithKey(macro) {73 return function () {74 var properties = slice.call(arguments, 1);75 var key = arguments[0];76 var computedFunc = computed(function () {77 var values = getValues(this, properties);78 return macro.call(this, key, values);79 });80 return computedFunc.property.apply(computedFunc, properties);81 }82}83function generateComputedWithProperties(macro) {84 return function () {85 var properties = slice.call(arguments);86 var computedFunc = computed(function () {87 return macro.apply(this, [getProperties(this, properties)]);88 });89 var realProperties = properties.slice().invoke('replace', '!', '');90 return computedFunc.property.apply(computedFunc, realProperties);91 };92}93function generateComputedWithValues(macro) {94 return function () {95 var properties = slice.call(arguments);96 var computedFunc = computed(function () {97 return macro.apply(this, [getValues(this, properties)]);98 });99 return computedFunc.property.apply(computedFunc, properties);100 };101}102/**103 *104 * A computed property that returns true if the provided dependent property105 * is equal to the given value.106 * App.*-keys are supported107 * Example*108 * ```javascript109 * var Hamster = Ember.Object.extend({110 * napTime: Ember.computed.equal('state', 'sleepy')111 * });112 * var hamster = Hamster.create();113 * hamster.get('napTime'); // false114 * hamster.set('state', 'sleepy');115 * hamster.get('napTime'); // true116 * hamster.set('state', 'hungry');117 * hamster.get('napTime'); // false118 * ```119 * @method equal120 * @param {String} dependentKey121 * @param {String|Number|Object} value122 * @return {Ember.ComputedProperty} computed property which returns true if123 * the original value for property is equal to the given value.124 * @public125 */126computed.equal = function (dependentKey, value) {127 return computed(dependentKey, function () {128 return smartGet(this, dependentKey) === value;129 }).cacheable();130};131/**132 * A computed property that returns true if the provided dependent property is not equal to the given value133 * App.*-keys are supported134 * <pre>135 * var o = Em.Object.create({136 * p1: 'a',137 * p2: Em.computed.notEqual('p1', 'a')138 * });139 * console.log(o.get('p2')); // false140 * o.set('p1', 'b');141 * console.log(o.get('p2')); // true142 * </pre>143 *144 * @method notEqual145 * @param {string} dependentKey146 * @param {*} value147 * @returns {Ember.ComputedProperty}148 */149computed.notEqual = function (dependentKey, value) {150 return computed(dependentKey, function () {151 return smartGet(this, dependentKey) !== value;152 });153};154/**155 * A computed property that returns true if provided dependent properties are equal to the each other156 * App.*-keys are supported157 * <pre>158 * var o = Em.Object.create({159 * p1: 'a',160 * p2: 'b',161 * p3: Em.computed.equalProperties('p1', 'p2')162 * });163 * console.log(o.get('p3')); // false164 * o.set('p1', 'b');165 * console.log(o.get('p3')); // true166 * </pre>167 *168 * @method equalProperties169 * @param {string} dependentKey1170 * @param {string} dependentKey2171 * @returns {Ember.ComputedProperty}172 */173computed.equalProperties = function (dependentKey1, dependentKey2) {174 return computed(dependentKey1, dependentKey2, function () {175 return smartGet(this, dependentKey1) === smartGet(this, dependentKey2);176 });177};178/**179 * A computed property that returns true if provided dependent properties are not equal to the each other180 * App.*-keys are supported181 * <pre>182 * var o = Em.Object.create({183 * p1: 'a',184 * p2: 'b',185 * p3: Em.computed.notEqualProperties('p1', 'p2')186 * });187 * console.log(o.get('p3')); // true188 * o.set('p1', 'b');189 * console.log(o.get('p3')); // false190 * </pre>191 *192 * @method notEqualProperties193 * @param {string} dependentKey1194 * @param {string} dependentKey2195 * @returns {Ember.ComputedProperty}196 */197computed.notEqualProperties = function (dependentKey1, dependentKey2) {198 return computed(dependentKey1, dependentKey2, function () {199 return smartGet(this, dependentKey1) !== smartGet(this, dependentKey2);200 });201};202/**203 * A computed property that returns grouped collection's items by propertyName-value204 *205 * @method groupBy206 * @param {string} collectionKey207 * @param {string} propertyName208 * @returns {Ember.ComputedProperty}209 */210computed.groupBy = function (collectionKey, propertyName) {211 return computed(collectionKey + '.@each.' + propertyName, function () {212 var collection = get(this, collectionKey);213 return dataUtils.groupPropertyValues(collection, propertyName);214 });215};216/**217 * A computed property that returns filtered collection by propertyName values-list218 * Wrapper to filterProperty-method that allows using list of values to filter219 *220 * @method filterByMany221 * @param {string} collectionKey222 * @param {string} propertyName223 * @param {array} valuesToFilter224 * @returns {Ember.ComputedProperty}225 */226computed.filterByMany = function (collectionKey, propertyName, valuesToFilter) {227 return computed(collectionKey + '.@each.' + propertyName, function () {228 var collection = get(this, collectionKey);229 return dataUtils.filterPropertyValues(collection, propertyName, makeArray(valuesToFilter));230 });231};232/**233 * A computed property that returns collection without elements with value that is in <code>valuesToReject</code>234 * Exclude objects from <code>collection</code> if its <code>key</code> exist in <code>valuesToReject</code>235 *236 * @method rejectMany237 * @param {string} collectionKey238 * @param {string} propertyName239 * @param {array} valuesToReject240 * @returns {Ember.ComputedProperty}241 */242computed.rejectMany = function (collectionKey, propertyName, valuesToReject) {243 return computed(collectionKey + '.@each.' + propertyName, function () {244 var collection = get(this, collectionKey);245 return dataUtils.rejectPropertyValues(collection, propertyName, makeArray(valuesToReject));246 });247};248/**249 * A computed property that returns trueValue if dependent value is true and falseValue otherwise250 * App.*-keys are supported251 * <pre>252 * var o = Em.Object.create({253 * p1: true,254 * p2: Em.computed.ifThenElse('p1', 'abc', 'cba')255 * });256 * console.log(o.get('p2')); // 'abc'257 * o.set('p1', false);258 * console.log(o.get('p2')); // 'cba'259 * </pre>260 *261 * @method ifThenElse262 * @param {string} dependentKey263 * @param {*} trueValue264 * @param {*} falseValue265 * @returns {Ember.ComputedProperty}266 */267computed.ifThenElse = function (dependentKey, trueValue, falseValue) {268 return computed(dependentKey, function () {269 return smartGet(this, dependentKey) ? trueValue : falseValue;270 });271};272/**273 * A computed property that is equal to the logical 'and'274 * Takes any number of arguments275 * Returns true if all of them are truly, false - otherwise276 * App.*-keys are supported277 * <pre>278 * var o = Em.Object.create({279 * p1: true,280 * p2: true,281 * p3: true,282 * p4: Em.computed.and('p1', 'p2', 'p3')283 * });284 * console.log(o.get('p4')); // true285 * o.set('p1', false);286 * console.log(o.get('p4')); // false287 * </pre>288 *289 * @method and290 * @param {...string} dependentKeys291 * @returns {Ember.ComputedProperty}292 */293computed.and = generateComputedWithProperties(function (properties) {294 var value;295 for (var key in properties) {296 value = !!properties[key];297 if (properties.hasOwnProperty(key) && !value) {298 return false;299 }300 }301 return value;302});303/**304 * A computed property that is equal to the logical 'or'305 * Takes any number of arguments306 * Returns true if at least one of them is truly, false - otherwise307 * App.*-keys are supported308 * <pre>309 * var o = Em.Object.create({310 * p1: false,311 * p2: false,312 * p3: false,313 * p4: Em.computed.or('p1', 'p2', 'p3')314 * });315 * console.log(o.get('p4')); // false316 * o.set('p1', true);317 * console.log(o.get('p4')); // true318 * </pre>319 *320 * @method or321 * @param {...string} dependentKeys322 * @returns {Ember.ComputedProperty}323 */324computed.or = generateComputedWithProperties(function (properties) {325 var value;326 for (var key in properties) {327 value = !!properties[key];328 if (properties.hasOwnProperty(key) && value) {329 return value;330 }331 }332 return value;333});334/**335 * A computed property that returns sum on the dependent properties values336 * Takes any number of arguments337 * App.*-keys are supported338 * <pre>339 * var o = Em.Object.create({340 * p1: 1,341 * p2: 2,342 * p3: 3,343 * p4: Em.computed.sumProperties('p1', 'p2', 'p3')344 * });345 * console.log(o.get('p4')); // 6346 * o.set('p1', 2);347 * console.log(o.get('p4')); // 7348 * </pre>349 *350 * @method sumProperties351 * @param {...string} dependentKeys352 * @returns {Ember.ComputedProperty}353 */354computed.sumProperties = generateComputedWithProperties(function (properties) {355 var sum = 0;356 for (var key in properties) {357 if (properties.hasOwnProperty(key)) {358 sum += Number(properties[key]);359 }360 }361 return sum;362});363/**364 * A computed property that returns true if dependent value is greater or equal to the needed value365 * App.*-keys are supported366 * <pre>367 * var o = Em.Object.create({368 * p1: 4,369 * p2: Em.computed.gte('p1', 1)370 * });371 * console.log(o.get('p2')); // true372 * o.set('p1', 4);373 * console.log(o.get('p2')); // true374 * o.set('p1', 5);375 * console.log(o.get('p2')); // false376 * </pre>377 *378 * @method gte379 * @param {string} dependentKey380 * @param {*} value381 * @returns {Ember.ComputedProperty}382 */383computed.gte = function (dependentKey, value) {384 return computed(dependentKey, function () {385 return smartGet(this, dependentKey) >= value;386 });387};388/**389 * A computed property that returns true if first dependent property is greater or equal to the second dependent property390 * App.*-keys are supported391 * <pre>392 * var o = Em.Object.create({393 * p1: 4,394 * p2: 1,395 * p3: Em.computed.gteProperties('p1', 'p2')396 * });397 * console.log(o.get('p3')); // true398 * o.set('p2', 4);399 * console.log(o.get('p3')); // true400 * o.set('p2', 5);401 * console.log(o.get('p3')); // false402 * </pre>403 *404 * @method gteProperties405 * @param {string} dependentKey1406 * @param {string} dependentKey2407 * @returns {Ember.ComputedProperty}408 */409computed.gteProperties = function (dependentKey1, dependentKey2) {410 return computed(dependentKey1, dependentKey2, function () {411 return smartGet(this, dependentKey1) >= smartGet(this, dependentKey2);412 });413};414/**415 * A computed property that returns true if dependent property is less or equal to the needed value416 * App.*-keys are supported417 * <pre>418 * var o = Em.Object.create({419 * p1: 4,420 * p2: Em.computed.lte('p1', 1)421 * });422 * console.log(o.get('p2')); // false423 * o.set('p1', 4);424 * console.log(o.get('p2')); // true425 * o.set('p1', 5);426 * console.log(o.get('p2')); // true427 * </pre>428 *429 * @method lte430 * @param {string} dependentKey431 * @param {*} value432 * @returns {Ember.ComputedProperty}433 */434computed.lte = function (dependentKey, value) {435 return computed(dependentKey, function () {436 return smartGet(this, dependentKey) <= value;437 });438};439/**440 * A computed property that returns true if first dependent property is less or equal to the second dependent property441 * App.*-keys are supported442 * <pre>443 * var o = Em.Object.create({444 * p1: 4,445 * p2: 1,446 * p3: Em.computed.lteProperties('p1', 'p2')447 * });448 * console.log(o.get('p3')); // false449 * o.set('p2', 4);450 * console.log(o.get('p3')); // true451 * o.set('p2', 5);452 * console.log(o.get('p3')); // true453 * </pre>454 *455 * @method lteProperties456 * @param {string} dependentKey1457 * @param {string} dependentKey2458 * @returns {Ember.ComputedProperty}459 */460computed.lteProperties = function (dependentKey1, dependentKey2) {461 return computed(dependentKey1, dependentKey2, function () {462 return smartGet(this, dependentKey1) <= smartGet(this, dependentKey2);463 });464};465/**466 * A computed property that returns true if dependent value is greater than the needed value467 * App.*-keys are supported468 * <pre>469 * var o = Em.Object.create({470 * p1: 4,471 * p2: Em.computed.gt('p1', 1)472 * });473 * console.log(o.get('p2')); // true474 * o.set('p1', 4);475 * console.log(o.get('p2')); // false476 * o.set('p1', 5);477 * console.log(o.get('p2')); // false478 * </pre>479 *480 * @method gt481 * @param {string} dependentKey482 * @param {*} value483 * @returns {Ember.ComputedProperty}484 */485computed.gt = function (dependentKey, value) {486 return computed(dependentKey, function () {487 return smartGet(this, dependentKey) > value;488 });489};490/**491 * A computed property that returns true if first dependent property is greater than the second dependent property492 * App.*-keys are supported493 * <pre>494 * var o = Em.Object.create({495 * p1: 4,496 * p2: 1,497 * p3: Em.computed.gteProperties('p1', 'p2')498 * });499 * console.log(o.get('p3')); // true500 * o.set('p2', 4);501 * console.log(o.get('p3')); // false502 * o.set('p2', 5);503 * console.log(o.get('p3')); // false504 * </pre>505 *506 * @method gtProperties507 * @param {string} dependentKey1508 * @param {string} dependentKey2509 * @returns {Ember.ComputedProperty}510 */511computed.gtProperties = function (dependentKey1, dependentKey2) {512 return computed(dependentKey1, dependentKey2, function () {513 return smartGet(this, dependentKey1) > smartGet(this, dependentKey2);514 });515};516/**517 * A computed property that returns true if dependent value is less than the needed value518 * App.*-keys are supported519 * <pre>520 * var o = Em.Object.create({521 * p1: 4,522 * p2: Em.computed.lt('p1', 1)523 * });524 * console.log(o.get('p2')); // false525 * o.set('p1', 4);526 * console.log(o.get('p2')); // false527 * o.set('p1', 5);528 * console.log(o.get('p2')); // true529 * </pre>530 *531 * @method lt532 * @param {string} dependentKey533 * @param {*} value534 * @returns {Ember.ComputedProperty}535 */536computed.lt = function (dependentKey, value) {537 return computed(dependentKey, function () {538 return smartGet(this, dependentKey) < value;539 });540};541/**542 * A computed property that returns true if first dependent property is less than the second dependent property543 * App.*-keys are supported544 * <pre>545 * var o = Em.Object.create({546 * p1: 4,547 * p2: 1,548 * p3: Em.computed.ltProperties('p1', 'p2')549 * });550 * console.log(o.get('p3')); // false551 * o.set('p2', 4);552 * console.log(o.get('p3')); // false553 * o.set('p2', 5);554 * console.log(o.get('p3')); // true555 * </pre>556 *557 * @method gtProperties558 * @param {string} dependentKey1559 * @param {string} dependentKey2560 * @returns {Ember.ComputedProperty}561 */562computed.ltProperties = function (dependentKey1, dependentKey2) {563 return computed(dependentKey1, dependentKey2, function () {564 return smartGet(this, dependentKey1) < smartGet(this, dependentKey2);565 });566};567/**568 * A computed property that returns true if dependent property is match to the needed regular expression569 * <pre>570 * var o = Em.Object.create({571 * p1: 'abc',572 * p2: Em.computed.match('p1', /^a/)573 * });574 * console.log(o.get('p2')); // true575 * o.set('p1', 'bc');576 * console.log(o.get('p2')); // false577 * </pre>578 *579 * @method match580 * @param {string} dependentKey581 * @param {RegExp} regexp582 * @returns {Ember.ComputedProperty}583 */584computed.match = function (dependentKey, regexp) {585 return computed(dependentKey, function () {586 var value = get(this, dependentKey);587 if (!regexp) {588 return false;589 }590 return regexp.test(value);591 });592};593/**594 * A computed property that returns true of some collection's item has property with needed value595 * <pre>596 * var o = Em.Object.create({597 * p1: [{a: 1}, {a: 2}, {a: 3}],598 * p2: Em.computed.someBy('p1', 'a', 1)599 * });600 * console.log(o.get('p2')); // true601 * o.set('p1.0.a', 2);602 * console.log(o.get('p2')); // false603 * </pre>604 *605 * @method someBy606 * @param {string} collectionKey607 * @param {string} propertyName608 * @param {*} neededValue609 * @returns {Ember.ComputedProperty}610 */611computed.someBy = function (collectionKey, propertyName, neededValue) {612 return computed(collectionKey + '.@each.' + propertyName, function () {613 var collection = smartGet(this, collectionKey);614 if (!collection) {615 return false;616 }617 return collection.someProperty(propertyName, neededValue);618 });619};620/**621 * A computed property that returns true of all collection's items have property with needed value622 * <pre>623 * var o = Em.Object.create({624 * p1: [{a: 1}, {a: 1}, {a: 1}],625 * p2: Em.computed.everyBy('p1', 'a', 1)626 * });627 * console.log(o.get('p2')); // true628 * o.set('p1.0.a', 2);629 * console.log(o.get('p2')); // false630 * </pre>631 *632 * @method everyBy633 * @param {string} collectionKey634 * @param {string} propertyName635 * @param {*} neededValue636 * @returns {Ember.ComputedProperty}637 */638computed.everyBy = function (collectionKey, propertyName, neededValue) {639 return computed(collectionKey + '.@each.' + propertyName, function () {640 var collection = smartGet(this, collectionKey);641 if (!collection) {642 return false;643 }644 return collection.everyProperty(propertyName, neededValue);645 });646};647/**648 * A computed property that returns array with values of named property on all items in the collection649 * <pre>650 * var o = Em.Object.create({651 * p1: [{a: 1}, {a: 2}, {a: 3}],652 * p2: Em.computed.everyBy('p1', 'a')653 * });654 * console.log(o.get('p2')); // [1, 2, 3]655 * o.set('p1.0.a', 2);656 * console.log(o.get('p2')); // [2, 2, 3]657 * </pre>658 *659 * @method mapBy660 * @param {string} collectionKey661 * @param {string} propertyName662 * @returns {Ember.ComputedProperty}663 */664computed.mapBy = function (collectionKey, propertyName) {665 return computed(collectionKey + '.@each.' + propertyName, function () {666 var collection = smartGet(this, collectionKey);667 if (!collection) {668 return [];669 }670 return collection.mapProperty(propertyName);671 });672};673/**674 * A computed property that returns array with collection's items that have needed property value675 * <pre>676 * var o = Em.Object.create({677 * p1: [{a: 1}, {a: 2}, {a: 3}],678 * p2: Em.computed.filterBy('p1', 'a', 2)679 * });680 * console.log(o.get('p2')); // [{a: 2}]681 * o.set('p1.0.a', 2);682 * console.log(o.get('p2')); // [{a: 2}, {a: 2}]683 * </pre>684 *685 * @method filterBy686 * @param {string} collectionKey687 * @param {string} propertyName688 * @param {*} neededValue689 * @returns {Ember.ComputedProperty}690 */691computed.filterBy = function (collectionKey, propertyName, neededValue) {692 return computed(collectionKey + '.@each.' + propertyName, function () {693 var collection = smartGet(this, collectionKey);694 if (!collection) {695 return [];696 }697 return collection.filterProperty(propertyName, neededValue);698 });699};700/**701 * A computed property that returns first collection's item that has needed property value702 * <pre>703 * var o = Em.Object.create({704 * p1: [{a: 1, b: 1}, {a: 2, b: 2}, {a: 3, b: 3}],705 * p2: Em.computed.findBy('p1', 'a', 2)706 * });707 * console.log(o.get('p2')); // [{a: 2, b: 2}]708 * o.set('p1.0.a', 2);709 * console.log(o.get('p2')); // [{a: 2, b: 1}]710 * </pre>711 *712 * @method findBy713 * @param {string} collectionKey714 * @param {string} propertyName715 * @param {*} neededValue716 * @returns {Ember.ComputedProperty}717 */718computed.findBy = function (collectionKey, propertyName, neededValue) {719 return computed(collectionKey + '.@each.' + propertyName, function () {720 var collection = smartGet(this, collectionKey);721 if (!collection) {722 return null;723 }724 return collection.findProperty(propertyName, neededValue);725 });726};727/**728 * A computed property that returns value equal to the dependent729 * Should be used as 'short-name' for deeply-nested values730 * App.*-keys are supported731 * <pre>732 * var o = Em.Object.create({733 * p1: {a: {b: {c: 2}}},734 * p2: Em.computed.alias('p1.a.b.c')735 * });736 * console.log(o.get('p2')); // 2737 * o.set('p1.a.b.c', 4);738 * console.log(o.get('p2')); // 4739 * </pre>740 *741 * @method alias742 * @param {string} dependentKey743 * @returns {Ember.ComputedProperty}744 */745computed.alias = function (dependentKey) {746 return computed(dependentKey, function () {747 return smartGet(this, dependentKey);748 });749};750/**751 * A computed property that returns true if dependent property exists in the needed values752 * <pre>753 * var o = Em.Object.create({754 * p1: 2,755 * p2: Em.computed.existsIn('p1', [1, 2, 3])756 * });757 * console.log(o.get('p2')); // true758 * o.set('p1', 4);759 * console.log(o.get('p2')); // false760 * </pre>761 *762 * @method existsIn763 * @param {string} dependentKey764 * @param {array} neededValues765 * @returns {Ember.ComputedProperty}766 */767computed.existsIn = function (dependentKey, neededValues) {768 return computed(dependentKey, function () {769 var value = smartGet(this, dependentKey);770 return makeArray(neededValues).contains(value);771 });772};773/**774 * A computed property that returns true if dependent property doesn't exist in the needed values775 * <pre>776 * var o = Em.Object.create({777 * p1: 2,778 * p2: Em.computed.notExistsIn('p1', [1, 2, 3])779 * });780 * console.log(o.get('p2')); // false781 * o.set('p1', 4);782 * console.log(o.get('p2')); // true783 * </pre>784 *785 * @method notExistsIn786 * @param {string} dependentKey787 * @param {array} neededValues788 * @returns {Ember.ComputedProperty}789 */790computed.notExistsIn = function (dependentKey, neededValues) {791 return computed(dependentKey, function () {792 var value = smartGet(this, dependentKey);793 return !makeArray(neededValues).contains(value);794 });795};796/**797 * A computed property that returns result of calculation <code>(dependentProperty1/dependentProperty2 * 100)</code>798 * If accuracy is 0 (by default), result is rounded to integer799 * Otherwise - result is float with provided accuracy800 * App.*-keys are supported801 * <pre>802 * var o = Em.Object.create({803 * p1: 2,804 * p2: 4,805 * p3: Em.computed.percents('p1', 'p2')806 * });807 * console.log(o.get('p3')); // 50808 * o.set('p2', 5);809 * console.log(o.get('p3')); // 40810 * </pre>811 *812 * @method percents813 * @param {string} dependentKey1814 * @param {string} dependentKey2815 * @param {number} [accuracy=0]816 * @returns {Ember.ComputedProperty}817 */818computed.percents = function (dependentKey1, dependentKey2, accuracy) {819 if (arguments.length < 3) {820 accuracy = 0;821 }822 return computed(dependentKey1, dependentKey2, function () {823 var v1 = Number(smartGet(this, dependentKey1));824 var v2 = Number(smartGet(this, dependentKey2));825 var result = v1 / v2 * 100;826 if (0 === accuracy) {827 return Math.round(result);828 }829 return parseFloat(result.toFixed(accuracy));830 });831};832/**833 * A computed property that returns result of <code>App.format.role</code> for dependent value834 * <pre>835 * var o = Em.Object.create({836 * p1: 'SECONDARY_NAMENODE',837 * p3: Em.computed.formatRole('p1', false)838 * });839 * console.log(o.get('p2')); // 'SNameNode'840 * o.set('p1', 'FLUME_HANDLER);841 * console.log(o.get('p2')); // 'Flume'842 * </pre>843 *844 * @method formatRole845 * @param {string} dependentKey846 * @param {boolean} isServiceRole847 * @returns {Ember.ComputedProperty}848 */849computed.formatRole = function (dependentKey, isServiceRole) {850 return computed(dependentKey, function () {851 var value = get(this, dependentKey);852 return App.format.role(value, isServiceRole);853 });854};855/**856 * A computed property that returns sum of the named property in the each collection's item857 * <pre>858 * var o = Em.Object.create({859 * p1: [{a: 1}, {a: 2}, {a: 3}],860 * p2: Em.computed.sumBy('p1', 'a')861 * });862 * console.log(o.get('p2')); // 6863 * o.set('p1.0.a', 2);864 * console.log(o.get('p2')); // 7865 * </pre>866 *867 * @method sumBy868 * @param {string} collectionKey869 * @param {string} propertyName870 * @returns {Ember.ComputedProperty}871 */872computed.sumBy = function (collectionKey, propertyName) {873 return computed(collectionKey + '.@each.' + propertyName, function () {874 var collection = smartGet(this, collectionKey);875 if (Em.isEmpty(collection)) {876 return 0;877 }878 var sum = 0;879 collection.forEach(function (item) {880 sum += Number(get(item, propertyName));881 });882 return sum;883 });884};885/**886 * A computed property that returns I18n-string formatted with dependent properties887 * Takes at least one argument888 * App.*-keys are supported889 *890 * @param {string} key key in the I18n-messages891 * @param {...string} dependentKeys892 * @method i18nFormat893 * @returns {Ember.ComputedProperty}894 */895computed.i18nFormat = generateComputedWithKey(function (key, dependentValues) {896 var str = Em.I18n.t(key);897 if (!str) {898 return '';899 }900 return str.format.apply(str, dependentValues);901});902/**903 * A computed property that returns string formatted with dependent properties904 * Takes at least one argument905 * App.*-keys are supported906 * <pre>907 * var o = Em.Object.create({908 * p1: 'abc',909 * p2: 'cba',910 * p3: Em.computed.format('{0} => {1}', 'p1', 'p2')911 * });912 * console.log(o.get('p3')); // 'abc => cba'913 * o.set('p1', 'aaa');914 * console.log(o.get('p3')); // 'aaa => cba'915 * </pre>916 *917 * @param {string} str string to format918 * @param {...string} dependentKeys919 * @method format920 * @returns {Ember.ComputedProperty}921 */922computed.format = generateComputedWithKey(function (str, dependentValues) {923 if (!str) {924 return '';925 }926 return str.format.apply(str, dependentValues);927});928/**929 * A computed property that returns dependent values joined with separator930 * Takes at least one argument931 * App.*-keys are supported932 * <pre>933 * var o = Em.Object.create({934 * p1: 'abc',935 * p2: 'cba',936 * p3: Em.computed.concat('|', 'p1', 'p2')937 * });938 * console.log(o.get('p3')); // 'abc|cba'939 * o.set('p1', 'aaa');940 * console.log(o.get('p3')); // 'aaa|cba'941 * </pre>942 *943 * @param {string} separator944 * @param {...string} dependentKeys945 * @method concat946 * @return {Ember.ComputedProperty}947 */948computed.concat = generateComputedWithKey(function (separator, dependentValues) {949 return dependentValues.join(separator);950});951/**952 * A computed property that returns first not blank value from dependent values953 * Based on <code>Ember.isBlank</code>954 * Takes at least 1 argument955 * Dependent values order affects the result956 * App.*-keys are supported957 * <pre>958 * var o = Em.Object.create({959 * p1: null,960 * p2: '',961 * p3: 'abc'962 * p4: Em.computed.firstNotBlank('p1', 'p2', 'p3')963 * });964 * console.log(o.get('p4')); // 'abc'965 * o.set('p1', 'aaa');966 * console.log(o.get('p4')); // 'aaa'967 * </pre>968 *969 * @param {...string} dependentKeys970 * @method firstNotBlank971 * @return {Ember.ComputedProperty}972 */973computed.firstNotBlank = generateComputedWithValues(function (values) {974 for (var i = 0; i < values.length; i++) {975 if (!Em.isBlank(values[i])) {976 return values[i];977 }978 }979 return null;980});981/**982 * A computed property that returns dependent value if it is truly or ('0'|0)983 * Returns <code>'n/a'</code> otherwise984 * App.*-keys are supported985 * <pre>986 * var o = Em.Object.create({987 * p1: 0,988 * p2: Em.computed.formatUnavailable('p1')989 * });990 * console.log(o.get('p2')); // 0991 * o.set('p1', 12);992 * console.log(o.get('p2')); // 12993 * o.set('p1', 'some string');994 * console.log(o.get('p2')); // 'n/a'995 * </pre>996 *997 * @param {string} dependentKey998 * @method formatUnavailable999 * @returns {Ember.ComputedProperty}1000 */1001computed.formatUnavailable = function(dependentKey) {1002 return computed(dependentKey, function () {1003 var value = smartGet(this, dependentKey);1004 return value || value == 0 ? value : Em.I18n.t('services.service.summary.notAvailable');1005 });1006};1007/**1008 * A computed property that returns one of provided values basing on dependent value1009 * If dependent value is 0, <code>zeroMsg</code> is returned1010 * If dependent value is 1, <code>oneMsg</code> is returned1011 * If dependent value is greater than 1, <code>manyMsg</code> is returned1012 * App.*-keys are supported1013 * <pre>1014 * var o = Em.Object.create({1015 * p1: 0,1016 * p2: Em.computed.formatUnavailable('p1', '0msg', '1msg', '2+msg')1017 * });1018 * console.log(o.get('p2')); // '0msg'1019 * o.set('p1', 1);1020 * console.log(o.get('p2')); // '1msg'1021 * o.set('p1', 100500);1022 * console.log(o.get('p2')); // '2+msg'1023 * </pre>1024 *1025 * @param {string} dependentKey1026 * @param {string} zeroMsg1027 * @param {string} oneMsg1028 * @param {string} manyMsg1029 * @returns {Ember.ComputedProperty}1030 * @method countBasedMessage1031 */1032computed.countBasedMessage = function (dependentKey, zeroMsg, oneMsg, manyMsg) {1033 return computed(dependentKey, function () {1034 var value = Number(smartGet(this, dependentKey));1035 if (value === 0) {1036 return zeroMsg;1037 }1038 if (value > 1) {1039 return manyMsg;1040 }1041 return oneMsg;1042 });1043};1044/**1045 * A computed property that returns property value according to the property key and object key1046 * App.*-keys are supported1047 * <pre>1048 * var o = Em.Object.create({1049 * p1: {a: 1, b: 2, c: 3},1050 * p2: 'a',1051 * p3: Em.computed.getByKey('p1', 'p2')1052 * });1053 * console.log(o.get('p3')); // 11054 * o.set('p2', 'b');1055 * console.log(o.get('p3')); // 21056 * o.set('p2', 'c');1057 * console.log(o.get('p3')); // 31058 * </pre>1059 *1060 * With `defaultValue`1061 * <pre>1062 * var o = Em.Object.create({1063 * p1: {a: 1, b: 2, c: 3},1064 * p2: 'd',1065 * p3: Em.computed.getByKey('p1', 'p2', 100500)1066 * });1067 * console.log(o.get('p3')); // 100500 - default value is returned, because there is no key `d` in the `p1`1068 * </pre>1069 * <b>IMPORTANT!</b> This CP <b>SHOULD NOT</b> be used with for object with values equal to the views (like <code>{a: App.MyViewA, b: App.MyViewB}</code>)1070 * This restriction exists because views may be undefined on the moment when this CP is calculated (files are not `required` yet)1071 *1072 * @param {string} objectKey1073 * @param {string} propertyKey1074 * @param {*} [defaultValue]1075 * @returns {Ember.ComputedProperty}1076 */1077computed.getByKey = function (objectKey, propertyKey, defaultValue) {1078 return computed(objectKey, propertyKey, function () {1079 var object = smartGet(this, objectKey);1080 var property = smartGet(this, propertyKey);1081 if (!object) {1082 return null;1083 }1084 return object.hasOwnProperty(property) ? object[property] : defaultValue;1085 });...

Full Screen

Full Screen

keyframe-utils.js

Source:keyframe-utils.js Github

copy

Full Screen

1"use strict";2// Utility functions and common keyframe test data.3// ------------------------------4// Helper functions5// ------------------------------6/**7 * Test equality between two lists of computed keyframes8 * @param {Array.<ComputedKeyframe>} a - actual computed keyframes9 * @param {Array.<ComputedKeyframe>} b - expected computed keyframes10 */11function assert_frame_lists_equal(a, b) {12 assert_equals(a.length, b.length, "number of frames");13 for (var i = 0; i < Math.min(a.length, b.length); i++) {14 assert_frames_equal(a[i], b[i], "ComputedKeyframe #" + i);15 }16}17/** Helper */18function assert_frames_equal(a, b, name) {19 assert_equals(Object.keys(a).sort().toString(),20 Object.keys(b).sort().toString(),21 "properties on " + name);22 for (var p in a) {23 assert_equals(a[p], b[p], "value for '" + p + "' on " + name);24 }25}26// ------------------------------27// Easing values28// ------------------------------29// [specified easing value, expected easing value]30var gEasingValueTests = [31 ["linear", "linear"],32 ["ease-in-out", "ease-in-out"],33 ["Ease\\2d in-out", "ease-in-out"],34 ["ease /**/", "ease"],35];36var gInvalidEasingInKeyframeSequenceTests = [37 { desc: "a blank easing",38 input: [{ easing: "" }] },39 { desc: "an unrecognized easing",40 input: [{ easing: "unrecognized" }] },41 { desc: "an 'initial' easing",42 input: [{ easing: "initial" }] },43 { desc: "an 'inherit' easing",44 input: [{ easing: "inherit" }] },45 { desc: "a variable easing",46 input: [{ easing: "var(--x)" }] },47 { desc: "a multi-value easing",48 input: [{ easing: "ease-in-out, ease-out" }] }49];50// ------------------------------51// Composite values52// ------------------------------53var gGoodKeyframeCompositeValueTests = [54 "replace", "add", "accumulate", undefined55];56var gGoodOptionsCompositeValueTests = [57 "replace", "add", "accumulate"58];59var gBadCompositeValueTests = [60 "unrecognised", "replace ", "Replace", null61];62// ------------------------------63// Keyframes64// ------------------------------65var gEmptyKeyframeListTests = [66 [],67 null,68 undefined,69];70var gPropertyIndexedKeyframesTests = [71 { desc: "a one property two value property-indexed keyframes specification",72 input: { left: ["10px", "20px"] },73 output: [{ offset: null, computedOffset: 0, easing: "linear",74 left: "10px" },75 { offset: null, computedOffset: 1, easing: "linear",76 left: "20px" }] },77 { desc: "a one shorthand property two value property-indexed keyframes"78 + " specification",79 input: { margin: ["10px", "10px 20px 30px 40px"] },80 output: [{ offset: null, computedOffset: 0, easing: "linear",81 margin: "10px" },82 { offset: null, computedOffset: 1, easing: "linear",83 margin: "10px 20px 30px 40px" }] },84 { desc: "a two property (one shorthand and one of its longhand components)"85 + " two value property-indexed keyframes specification",86 input: { marginTop: ["50px", "60px"],87 margin: ["10px", "10px 20px 30px 40px"] },88 output: [{ offset: null, computedOffset: 0, easing: "linear",89 marginTop: "50px", margin: "10px" },90 { offset: null, computedOffset: 1, easing: "linear",91 marginTop: "60px", margin: "10px 20px 30px 40px" }] },92 { desc: "a two property two value property-indexed keyframes specification",93 input: { left: ["10px", "20px"],94 top: ["30px", "40px"] },95 output: [{ offset: null, computedOffset: 0, easing: "linear",96 left: "10px", top: "30px" },97 { offset: null, computedOffset: 1, easing: "linear",98 left: "20px", top: "40px" }] },99 { desc: "a two property property-indexed keyframes specification with"100 + " different numbers of values",101 input: { left: ["10px", "20px", "30px"],102 top: ["40px", "50px"] },103 output: [{ offset: null, computedOffset: 0.0, easing: "linear",104 left: "10px", top: "40px" },105 { offset: null, computedOffset: 0.5, easing: "linear",106 left: "20px" },107 { offset: null, computedOffset: 1.0, easing: "linear",108 left: "30px", top: "50px" }] },109 { desc: "a property-indexed keyframes specification with an invalid value",110 input: { left: ["10px", "20px", "30px", "40px", "50px"],111 top: ["15px", "25px", "invalid", "45px", "55px"] },112 output: [{ offset: null, computedOffset: 0.00, easing: "linear",113 left: "10px", top: "15px" },114 { offset: null, computedOffset: 0.25, easing: "linear",115 left: "20px", top: "25px" },116 { offset: null, computedOffset: 0.50, easing: "linear",117 left: "30px" },118 { offset: null, computedOffset: 0.75, easing: "linear",119 left: "40px", top: "45px" },120 { offset: null, computedOffset: 1.00, easing: "linear",121 left: "50px", top: "55px" }] },122 { desc: "a one property two value property-indexed keyframes specification"123 + " that needs to stringify its values",124 input: { opacity: [0, 1] },125 output: [{ offset: null, computedOffset: 0, easing: "linear",126 opacity: "0" },127 { offset: null, computedOffset: 1, easing: "linear",128 opacity: "1" }] },129 { desc: "a property-indexed keyframes specification with a CSS variable"130 + " reference",131 input: { left: [ "var(--dist)", "calc(var(--dist) + 100px)" ] },132 output: [{ offset: null, computedOffset: 0.0, easing: "linear",133 left: "var(--dist)" },134 { offset: null, computedOffset: 1.0, easing: "linear",135 left: "calc(var(--dist) + 100px)" }] },136 { desc: "a property-indexed keyframes specification with a CSS variable"137 + " reference in a shorthand property",138 input: { margin: [ "var(--dist)", "calc(var(--dist) + 100px)" ] },139 output: [{ offset: null, computedOffset: 0.0, easing: "linear",140 margin: "var(--dist)" },141 { offset: null, computedOffset: 1.0, easing: "linear",142 margin: "calc(var(--dist) + 100px)" }] },143 { desc: "a one property one value property-indexed keyframes specification",144 input: { left: ["10px"] },145 output: [{ offset: null, computedOffset: 1, easing: "linear",146 left: "10px" }] },147 { desc: "a one property one non-array value property-indexed keyframes"148 + " specification",149 input: { left: "10px" },150 output: [{ offset: null, computedOffset: 1, easing: "linear",151 left: "10px" }] },152 { desc: "a one property two value property-indexed keyframes specification"153 + " where the first value is invalid",154 input: { left: ["invalid", "10px"] },155 output: [{ offset: null, computedOffset: 0, easing: "linear" },156 { offset: null, computedOffset: 1, easing: "linear",157 left: "10px" }] },158 { desc: "a one property two value property-indexed keyframes specification"159 + " where the second value is invalid",160 input: { left: ["10px", "invalid"] },161 output: [{ offset: null, computedOffset: 0, easing: "linear",162 left: "10px" },163 { offset: null, computedOffset: 1, easing: "linear" }] },164];165var gKeyframeSequenceTests = [166 { desc: "a one property one keyframe sequence",167 input: [{ offset: 1, left: "10px" }],168 output: [{ offset: 1, computedOffset: 1, easing: "linear",169 left: "10px" }] },170 { desc: "a one property two keyframe sequence",171 input: [{ offset: 0, left: "10px" },172 { offset: 1, left: "20px" }],173 output: [{ offset: 0, computedOffset: 0, easing: "linear", left: "10px" },174 { offset: 1, computedOffset: 1, easing: "linear", left: "20px" }]175 },176 { desc: "a two property two keyframe sequence",177 input: [{ offset: 0, left: "10px", top: "30px" },178 { offset: 1, left: "20px", top: "40px" }],179 output: [{ offset: 0, computedOffset: 0, easing: "linear",180 left: "10px", top: "30px" },181 { offset: 1, computedOffset: 1, easing: "linear",182 left: "20px", top: "40px" }] },183 { desc: "a one shorthand property two keyframe sequence",184 input: [{ offset: 0, margin: "10px" },185 { offset: 1, margin: "20px 30px 40px 50px" }],186 output: [{ offset: 0, computedOffset: 0, easing: "linear",187 margin: "10px" },188 { offset: 1, computedOffset: 1, easing: "linear",189 margin: "20px 30px 40px 50px" }] },190 { desc: "a two property (a shorthand and one of its component longhands)"191 + " two keyframe sequence",192 input: [{ offset: 0, margin: "10px", marginTop: "20px" },193 { offset: 1, marginTop: "70px", margin: "30px 40px 50px 60px" }],194 output: [{ offset: 0, computedOffset: 0, easing: "linear",195 margin: "10px", marginTop: "20px" },196 { offset: 1, computedOffset: 1, easing: "linear",197 marginTop: "70px", margin: "30px 40px 50px 60px" }] },198 { desc: "a keyframe sequence with duplicate values for a given interior"199 + " offset",200 input: [{ offset: 0.0, left: "10px" },201 { offset: 0.5, left: "20px" },202 { offset: 0.5, left: "30px" },203 { offset: 0.5, left: "40px" },204 { offset: 1.0, left: "50px" }],205 output: [{ offset: 0.0, computedOffset: 0.0, easing: "linear",206 left: "10px" },207 { offset: 0.5, computedOffset: 0.5, easing: "linear",208 left: "20px" },209 { offset: 0.5, computedOffset: 0.5, easing: "linear",210 left: "30px" },211 { offset: 0.5, computedOffset: 0.5, easing: "linear",212 left: "40px" },213 { offset: 1.0, computedOffset: 1.0, easing: "linear",214 left: "50px" }] },215 { desc: "a keyframe sequence with duplicate values for offsets 0 and 1",216 input: [{ offset: 0, left: "10px" },217 { offset: 0, left: "20px" },218 { offset: 0, left: "30px" },219 { offset: 1, left: "40px" },220 { offset: 1, left: "50px" },221 { offset: 1, left: "60px" }],222 output: [{ offset: 0, computedOffset: 0, easing: "linear", left: "10px" },223 { offset: 0, computedOffset: 0, easing: "linear", left: "20px" },224 { offset: 0, computedOffset: 0, easing: "linear", left: "30px" },225 { offset: 1, computedOffset: 1, easing: "linear", left: "40px" },226 { offset: 1, computedOffset: 1, easing: "linear", left: "50px" },227 { offset: 1, computedOffset: 1, easing: "linear", left: "60px" }]228 },229 { desc: "a two property four keyframe sequence",230 input: [{ offset: 0, left: "10px" },231 { offset: 0, top: "20px" },232 { offset: 1, top: "30px" },233 { offset: 1, left: "40px" }],234 output: [{ offset: 0, computedOffset: 0, easing: "linear", left: "10px" },235 { offset: 0, computedOffset: 0, easing: "linear", top: "20px" },236 { offset: 1, computedOffset: 1, easing: "linear", top: "30px" },237 { offset: 1, computedOffset: 1, easing: "linear", left: "40px" }]238 },239 { desc: "a single keyframe sequence with omitted offset",240 input: [{ left: "10px" }],241 output: [{ offset: null, computedOffset: 1, easing: "linear",242 left: "10px" }] },243 { desc: "a single keyframe sequence with null offset",244 input: [{ offset: null, left: "10px" }],245 output: [{ offset: null, computedOffset: 1, easing: "linear",246 left: "10px" }] },247 { desc: "a single keyframe sequence with string offset",248 input: [{ offset: '0.5', left: "10px" }],249 output: [{ offset: 0.5, computedOffset: 0.5, easing: "linear",250 left: "10px" }] },251 { desc: "a one property keyframe sequence with some omitted offsets",252 input: [{ offset: 0.00, left: "10px" },253 { offset: 0.25, left: "20px" },254 { left: "30px" },255 { left: "40px" },256 { offset: 1.00, left: "50px" }],257 output: [{ offset: 0.00, computedOffset: 0.00, easing: "linear",258 left: "10px" },259 { offset: 0.25, computedOffset: 0.25, easing: "linear",260 left: "20px" },261 { offset: null, computedOffset: 0.50, easing: "linear",262 left: "30px" },263 { offset: null, computedOffset: 0.75, easing: "linear",264 left: "40px" },265 { offset: 1.00, computedOffset: 1.00, easing: "linear",266 left: "50px" }] },267 { desc: "a one property keyframe sequence with some null offsets",268 input: [{ offset: 0.00, left: "10px" },269 { offset: 0.25, left: "20px" },270 { offset: null, left: "30px" },271 { offset: null, left: "40px" },272 { offset: 1.00, left: "50px" }],273 output: [{ offset: 0.00, computedOffset: 0.00, easing: "linear",274 left: "10px" },275 { offset: 0.25, computedOffset: 0.25, easing: "linear",276 left: "20px" },277 { offset: null, computedOffset: 0.50, easing: "linear",278 left: "30px" },279 { offset: null, computedOffset: 0.75, easing: "linear",280 left: "40px" },281 { offset: 1.00, computedOffset: 1.00, easing: "linear",282 left: "50px" }] },283 { desc: "a two property keyframe sequence with some omitted offsets",284 input: [{ offset: 0.00, left: "10px", top: "20px" },285 { offset: 0.25, left: "30px" },286 { left: "40px" },287 { left: "50px", top: "60px" },288 { offset: 1.00, left: "70px", top: "80px" }],289 output: [{ offset: 0.00, computedOffset: 0.00, easing: "linear",290 left: "10px", top: "20px" },291 { offset: 0.25, computedOffset: 0.25, easing: "linear",292 left: "30px" },293 { offset: null, computedOffset: 0.50, easing: "linear",294 left: "40px" },295 { offset: null, computedOffset: 0.75, easing: "linear",296 left: "50px", top: "60px" },297 { offset: 1.00, computedOffset: 1.00, easing: "linear",298 left: "70px", top: "80px" }] },299 { desc: "a one property keyframe sequence with all omitted offsets",300 input: [{ left: "10px" },301 { left: "20px" },302 { left: "30px" },303 { left: "40px" },304 { left: "50px" }],305 output: [{ offset: null, computedOffset: 0.00, easing: "linear",306 left: "10px" },307 { offset: null, computedOffset: 0.25, easing: "linear",308 left: "20px" },309 { offset: null, computedOffset: 0.50, easing: "linear",310 left: "30px" },311 { offset: null, computedOffset: 0.75, easing: "linear",312 left: "40px" },313 { offset: null, computedOffset: 1.00, easing: "linear",314 left: "50px" }] },315 { desc: "a keyframe sequence with different easing values, but the same"316 + " easing value for a given offset",317 input: [{ offset: 0.0, easing: "ease", left: "10px"},318 { offset: 0.0, easing: "ease", top: "20px"},319 { offset: 0.5, easing: "linear", left: "30px" },320 { offset: 0.5, easing: "linear", top: "40px" },321 { offset: 1.0, easing: "step-end", left: "50px" },322 { offset: 1.0, easing: "step-end", top: "60px" }],323 output: [{ offset: 0.0, computedOffset: 0.0, easing: "ease",324 left: "10px" },325 { offset: 0.0, computedOffset: 0.0, easing: "ease",326 top: "20px" },327 { offset: 0.5, computedOffset: 0.5, easing: "linear",328 left: "30px" },329 { offset: 0.5, computedOffset: 0.5, easing: "linear",330 top: "40px" },331 { offset: 1.0, computedOffset: 1.0, easing: "steps(1)",332 left: "50px" },333 { offset: 1.0, computedOffset: 1.0, easing: "steps(1)",334 top: "60px" }] },335 { desc: "a keyframe sequence with different composite values, but the"336 + " same composite value for a given offset",337 input: [{ offset: 0.0, composite: "replace", left: "10px" },338 { offset: 0.0, composite: "replace", top: "20px" },339 { offset: 0.5, composite: "add", left: "30px" },340 { offset: 0.5, composite: "add", top: "40px" },341 { offset: 1.0, composite: "replace", left: "50px" },342 { offset: 1.0, composite: "replace", top: "60px" }],343 output: [{ offset: 0.0, computedOffset: 0.0, easing: "linear",344 composite: "replace", left: "10px" },345 { offset: 0.0, computedOffset: 0.0, easing: "linear",346 composite: "replace", top: "20px" },347 { offset: 0.5, computedOffset: 0.5, easing: "linear",348 composite: "add", left: "30px" },349 { offset: 0.5, computedOffset: 0.5, easing: "linear",350 composite: "add", top: "40px" },351 { offset: 1.0, computedOffset: 1.0, easing: "linear",352 composite: "replace", left: "50px" },353 { offset: 1.0, computedOffset: 1.0, easing: "linear",354 composite: "replace", top: "60px" }] },355 { desc: "a one property two keyframe sequence that needs to stringify"356 + " its values",357 input: [{ offset: 0, opacity: 0 },358 { offset: 1, opacity: 1 }],359 output: [{ offset: 0, computedOffset: 0, easing: "linear", opacity: "0" },360 { offset: 1, computedOffset: 1, easing: "linear", opacity: "1" }]361 },362 { desc: "a keyframe sequence with a CSS variable reference",363 input: [{ left: "var(--dist)" },364 { left: "calc(var(--dist) + 100px)" }],365 output: [{ offset: null, computedOffset: 0.0, easing: "linear",366 left: "var(--dist)" },367 { offset: null, computedOffset: 1.0, easing: "linear",368 left: "calc(var(--dist) + 100px)" }] },369 { desc: "a keyframe sequence with a CSS variable reference in a shorthand"370 + " property",371 input: [{ margin: "var(--dist)" },372 { margin: "calc(var(--dist) + 100px)" }],373 output: [{ offset: null, computedOffset: 0.0, easing: "linear",374 margin: "var(--dist)" },375 { offset: null, computedOffset: 1.0, easing: "linear",376 margin: "calc(var(--dist) + 100px)" }] },377 { desc: "a keyframe sequence where shorthand precedes longhand",378 input: [{ offset: 0, margin: "10px", marginRight: "20px" },379 { offset: 1, margin: "30px" }],380 output: [{ offset: 0, computedOffset: 0, easing: "linear",381 margin: "10px", marginRight: "20px" },382 { offset: 1, computedOffset: 1, easing: "linear",383 margin: "30px" }] },384 { desc: "a keyframe sequence where longhand precedes shorthand",385 input: [{ offset: 0, marginRight: "20px", margin: "10px" },386 { offset: 1, margin: "30px" }],387 output: [{ offset: 0, computedOffset: 0, easing: "linear",388 marginRight: "20px", margin: "10px" },389 { offset: 1, computedOffset: 1, easing: "linear",390 margin: "30px" }] },391 { desc: "a keyframe sequence where lesser shorthand precedes greater"392 + " shorthand",393 input: [{ offset: 0,394 borderLeft: "1px solid rgb(1, 2, 3)",395 border: "2px dotted rgb(4, 5, 6)" },396 { offset: 1, border: "3px dashed rgb(7, 8, 9)" }],397 output: [{ offset: 0, computedOffset: 0, easing: "linear",398 borderLeft: "1px solid rgb(1, 2, 3)",399 border: "2px dotted rgb(4, 5, 6)" },400 { offset: 1, computedOffset: 1, easing: "linear",401 border: "3px dashed rgb(7, 8, 9)" }] },402 { desc: "a keyframe sequence where greater shorthand precedes lesser"403 + " shorthand",404 input: [{ offset: 0, border: "2px dotted rgb(4, 5, 6)",405 borderLeft: "1px solid rgb(1, 2, 3)" },406 { offset: 1, border: "3px dashed rgb(7, 8, 9)" }],407 output: [{ offset: 0, computedOffset: 0, easing: "linear",408 border: "2px dotted rgb(4, 5, 6)",409 borderLeft: "1px solid rgb(1, 2, 3)" },410 { offset: 1, computedOffset: 1, easing: "linear",411 border: "3px dashed rgb(7, 8, 9)" }] },412 { desc: "a two property keyframe sequence where one property is missing"413 + " from the first keyframe",414 input: [{ offset: 0, left: "10px" },415 { offset: 1, left: "20px", top: "30px" }],416 output: [{ offset: 0, computedOffset: 0, easing: "linear", left: "10px" },417 { offset: 1, computedOffset: 1, easing: "linear",418 left: "20px", top: "30px" }] },419 { desc: "a two property keyframe sequence where one property is missing"420 + " from the last keyframe",421 input: [{ offset: 0, left: "10px", top: "20px" },422 { offset: 1, left: "30px" }],423 output: [{ offset: 0, computedOffset: 0, easing: "linear",424 left: "10px" , top: "20px" },425 { offset: 1, computedOffset: 1, easing: "linear",426 left: "30px" }] },427 { desc: "a keyframe sequence with repeated values at offset 1 with"428 + " different easings",429 input: [{ offset: 0.0, left: "100px", easing: "ease" },430 { offset: 0.0, left: "200px", easing: "ease" },431 { offset: 0.5, left: "300px", easing: "linear" },432 { offset: 1.0, left: "400px", easing: "ease-out" },433 { offset: 1.0, left: "500px", easing: "step-end" }],434 output: [{ offset: 0.0, computedOffset: 0.0, easing: "ease",435 left: "100px" },436 { offset: 0.0, computedOffset: 0.0, easing: "ease",437 left: "200px" },438 { offset: 0.5, computedOffset: 0.5, easing: "linear",439 left: "300px" },440 { offset: 1.0, computedOffset: 1.0, easing: "ease-out",441 left: "400px" },442 { offset: 1.0, computedOffset: 1.0, easing: "steps(1)",443 left: "500px" }] },444];445var gInvalidKeyframesTests = [446 { desc: "keyframes with an out-of-bounded positive offset",447 input: [ { opacity: 0 },448 { opacity: 0.5, offset: 2 },449 { opacity: 1 } ],450 expected: { name: "TypeError" } },451 { desc: "keyframes with an out-of-bounded negative offset",452 input: [ { opacity: 0 },453 { opacity: 0.5, offset: -1 },454 { opacity: 1 } ],455 expected: { name: "TypeError" } },456 { desc: "keyframes not loosely sorted by offset",457 input: [ { opacity: 0, offset: 1 },458 { opacity: 1, offset: 0 } ],459 expected: { name: "TypeError" } },460 { desc: "property-indexed keyframes with an invalid easing value",461 input: { opacity: [ 0, 0.5, 1 ],462 easing: "inherit" },463 expected: { name: "TypeError" } },464 { desc: "a keyframe sequence with an invalid easing value",465 input: [ { opacity: 0, easing: "jumpy" },466 { opacity: 1 } ],467 expected: { name: "TypeError" } },468 { desc: "keyframes with an invalid composite value",469 input: [ { opacity: 0, composite: "alternate" },470 { opacity: 1 } ],471 expected: { name: "TypeError" } }472];473// ------------------------------474// KeyframeEffectOptions475// ------------------------------476var gKeyframeEffectOptionTests = [477 { desc: "an empty KeyframeEffectOptions object",478 input: { },479 expected: { } },480 { desc: "a normal KeyframeEffectOptions object",481 input: { delay: 1000,482 fill: "auto",483 iterations: 5.5,484 duration: "auto",485 direction: "alternate" },486 expected: { delay: 1000,487 fill: "auto",488 iterations: 5.5,489 duration: "auto",490 direction: "alternate" } },491 { desc: "a double value",492 input: 3000,493 expected: { duration: 3000 } },494 { desc: "+Infinity",495 input: Infinity,496 expected: { duration: Infinity } },497 { desc: "an Infinity duration",498 input: { duration: Infinity },499 expected: { duration: Infinity } },500 { desc: "an auto duration",501 input: { duration: "auto" },502 expected: { duration: "auto" } },503 { desc: "an Infinity iterations",504 input: { iterations: Infinity },505 expected: { iterations: Infinity } },506 { desc: "an auto fill",507 input: { fill: "auto" },508 expected: { fill: "auto" } },509 { desc: "a forwards fill",510 input: { fill: "forwards" },511 expected: { fill: "forwards" } }512];513var gInvalidKeyframeEffectOptionTests = [514 { desc: "-Infinity",515 input: -Infinity,516 expected: { name: "TypeError" } },517 { desc: "NaN",518 input: NaN,519 expected: { name: "TypeError" } },520 { desc: "a negative value",521 input: -1,522 expected: { name: "TypeError" } },523 { desc: "a negative Infinity duration",524 input: { duration: -Infinity },525 expected: { name: "TypeError" } },526 { desc: "a NaN duration",527 input: { duration: NaN },528 expected: { name: "TypeError" } },529 { desc: "a negative duration",530 input: { duration: -1 },531 expected: { name: "TypeError" } },532 { desc: "a string duration",533 input: { duration: "merrychristmas" },534 expected: { name: "TypeError" } },535 { desc: "a negative Infinity iterations",536 input: { iterations: -Infinity},537 expected: { name: "TypeError" } },538 { desc: "a NaN iterations",539 input: { iterations: NaN },540 expected: { name: "TypeError" } },541 { desc: "a negative iterations",542 input: { iterations: -1 },543 expected: { name: "TypeError" } },544 { desc: "a blank easing",545 input: { easing: "" },546 expected: { name: "TypeError" } },547 { desc: "an unrecognized easing",548 input: { easing: "unrecognised" },549 expected: { name: "TypeError" } },550 { desc: "an 'initial' easing",551 input: { easing: "initial" },552 expected: { name: "TypeError" } },553 { desc: "an 'inherit' easing",554 input: { easing: "inherit" },555 expected: { name: "TypeError" } },556 { desc: "a variable easing",557 input: { easing: "var(--x)" },558 expected: { name: "TypeError" } },559 { desc: "a multi-value easing",560 input: { easing: "ease-in-out, ease-out" },561 expected: { name: "TypeError" } }...

Full Screen

Full Screen

border-changes.js

Source:border-changes.js Github

copy

Full Screen

1description(2"This test checks the behavior of table styles when changing certain table attributes."3);4var yellow = "rgb(255, 255, 0)";5var orange = "rgb(255, 165, 0)";6var red = "rgb(255, 0, 0)";7var table = document.createElement("table");8table.setAttribute("style", "border-color: yellow");9var row = table.insertRow(-1);10row.setAttribute("style", "border-color: orange");11var cell = row.insertCell(-1);12cell.setAttribute("style", "border-color: red");13document.body.appendChild(table);14shouldBe("getComputedStyle(table, '').borderLeftWidth", "'0px'");15shouldBe("getComputedStyle(table, '').borderRightWidth", "'0px'");16shouldBe("getComputedStyle(table, '').borderTopWidth", "'0px'");17shouldBe("getComputedStyle(table, '').borderBottomWidth", "'0px'");18shouldBe("getComputedStyle(table, '').borderLeftStyle", "'none'");19shouldBe("getComputedStyle(table, '').borderRightStyle", "'none'");20shouldBe("getComputedStyle(table, '').borderTopStyle", "'none'");21shouldBe("getComputedStyle(table, '').borderBottomStyle", "'none'");22shouldBe("getComputedStyle(table, '').borderLeftColor", "yellow");23shouldBe("getComputedStyle(table, '').borderRightColor", "yellow");24shouldBe("getComputedStyle(table, '').borderTopColor", "yellow");25shouldBe("getComputedStyle(table, '').borderBottomColor", "yellow");26shouldBe("getComputedStyle(cell, '').borderLeftWidth", "'0px'");27shouldBe("getComputedStyle(cell, '').borderRightWidth", "'0px'");28shouldBe("getComputedStyle(cell, '').borderTopWidth", "'0px'");29shouldBe("getComputedStyle(cell, '').borderBottomWidth", "'0px'");30shouldBe("getComputedStyle(cell, '').borderLeftStyle", "'none'");31shouldBe("getComputedStyle(cell, '').borderRightStyle", "'none'");32shouldBe("getComputedStyle(cell, '').borderTopStyle", "'none'");33shouldBe("getComputedStyle(cell, '').borderBottomStyle", "'none'");34shouldBe("getComputedStyle(cell, '').borderLeftColor", "red");35shouldBe("getComputedStyle(cell, '').borderRightColor", "red");36shouldBe("getComputedStyle(cell, '').borderTopColor", "red");37shouldBe("getComputedStyle(cell, '').borderBottomColor", "red");38table.border = '';39shouldBe("getComputedStyle(table, '').borderLeftWidth", "'1px'");40shouldBe("getComputedStyle(table, '').borderRightWidth", "'1px'");41shouldBe("getComputedStyle(table, '').borderTopWidth", "'1px'");42shouldBe("getComputedStyle(table, '').borderBottomWidth", "'1px'");43shouldBe("getComputedStyle(table, '').borderLeftStyle", "'outset'");44shouldBe("getComputedStyle(table, '').borderRightStyle", "'outset'");45shouldBe("getComputedStyle(table, '').borderTopStyle", "'outset'");46shouldBe("getComputedStyle(table, '').borderBottomStyle", "'outset'");47shouldBe("getComputedStyle(table, '').borderLeftColor", "yellow");48shouldBe("getComputedStyle(table, '').borderRightColor", "yellow");49shouldBe("getComputedStyle(table, '').borderTopColor", "yellow");50shouldBe("getComputedStyle(table, '').borderBottomColor", "yellow");51shouldBe("getComputedStyle(cell, '').borderLeftWidth", "'1px'");52shouldBe("getComputedStyle(cell, '').borderRightWidth", "'1px'");53shouldBe("getComputedStyle(cell, '').borderTopWidth", "'1px'");54shouldBe("getComputedStyle(cell, '').borderBottomWidth", "'1px'");55shouldBe("getComputedStyle(cell, '').borderLeftStyle", "'inset'");56shouldBe("getComputedStyle(cell, '').borderRightStyle", "'inset'");57shouldBe("getComputedStyle(cell, '').borderTopStyle", "'inset'");58shouldBe("getComputedStyle(cell, '').borderBottomStyle", "'inset'");59shouldBe("getComputedStyle(cell, '').borderLeftColor", "red");60shouldBe("getComputedStyle(cell, '').borderRightColor", "red");61shouldBe("getComputedStyle(cell, '').borderTopColor", "red");62shouldBe("getComputedStyle(cell, '').borderBottomColor", "red");63table.setAttribute("bordercolor", "green");64shouldBe("getComputedStyle(table, '').borderLeftWidth", "'1px'");65shouldBe("getComputedStyle(table, '').borderRightWidth", "'1px'");66shouldBe("getComputedStyle(table, '').borderTopWidth", "'1px'");67shouldBe("getComputedStyle(table, '').borderBottomWidth", "'1px'");68shouldBe("getComputedStyle(table, '').borderLeftStyle", "'solid'");69shouldBe("getComputedStyle(table, '').borderRightStyle", "'solid'");70shouldBe("getComputedStyle(table, '').borderTopStyle", "'solid'");71shouldBe("getComputedStyle(table, '').borderBottomStyle", "'solid'");72shouldBe("getComputedStyle(table, '').borderLeftColor", "yellow");73shouldBe("getComputedStyle(table, '').borderRightColor", "yellow");74shouldBe("getComputedStyle(table, '').borderTopColor", "yellow");75shouldBe("getComputedStyle(table, '').borderBottomColor", "yellow");76shouldBe("getComputedStyle(cell, '').borderLeftWidth", "'1px'");77shouldBe("getComputedStyle(cell, '').borderRightWidth", "'1px'");78shouldBe("getComputedStyle(cell, '').borderTopWidth", "'1px'");79shouldBe("getComputedStyle(cell, '').borderBottomWidth", "'1px'");80shouldBe("getComputedStyle(cell, '').borderLeftStyle", "'solid'");81shouldBe("getComputedStyle(cell, '').borderRightStyle", "'solid'");82shouldBe("getComputedStyle(cell, '').borderTopStyle", "'solid'");83shouldBe("getComputedStyle(cell, '').borderBottomStyle", "'solid'");84shouldBe("getComputedStyle(cell, '').borderLeftColor", "red");85shouldBe("getComputedStyle(cell, '').borderRightColor", "red");86shouldBe("getComputedStyle(cell, '').borderTopColor", "red");87shouldBe("getComputedStyle(cell, '').borderBottomColor", "red");88table.rules = "cols";89shouldBe("getComputedStyle(table, '').borderLeftWidth", "'1px'");90shouldBe("getComputedStyle(table, '').borderRightWidth", "'1px'");91shouldBe("getComputedStyle(table, '').borderTopWidth", "'1px'");92shouldBe("getComputedStyle(table, '').borderBottomWidth", "'1px'");93shouldBe("getComputedStyle(table, '').borderLeftStyle", "'solid'");94shouldBe("getComputedStyle(table, '').borderRightStyle", "'solid'");95shouldBe("getComputedStyle(table, '').borderTopStyle", "'solid'");96shouldBe("getComputedStyle(table, '').borderBottomStyle", "'solid'");97shouldBe("getComputedStyle(table, '').borderLeftColor", "yellow");98shouldBe("getComputedStyle(table, '').borderRightColor", "yellow");99shouldBe("getComputedStyle(table, '').borderTopColor", "yellow");100shouldBe("getComputedStyle(table, '').borderBottomColor", "yellow");101shouldBe("getComputedStyle(cell, '').borderLeftWidth", "'1px'");102shouldBe("getComputedStyle(cell, '').borderRightWidth", "'1px'");103shouldBe("getComputedStyle(cell, '').borderTopWidth", "'0px'");104shouldBe("getComputedStyle(cell, '').borderBottomWidth", "'0px'");105shouldBe("getComputedStyle(cell, '').borderLeftStyle", "'solid'");106shouldBe("getComputedStyle(cell, '').borderRightStyle", "'solid'");107shouldBe("getComputedStyle(cell, '').borderTopStyle", "'none'");108shouldBe("getComputedStyle(cell, '').borderBottomStyle", "'none'");109shouldBe("getComputedStyle(cell, '').borderLeftColor", "red");110shouldBe("getComputedStyle(cell, '').borderRightColor", "red");111shouldBe("getComputedStyle(cell, '').borderTopColor", "red");112shouldBe("getComputedStyle(cell, '').borderBottomColor", "red");113table.rules = "rows";114shouldBe("getComputedStyle(table, '').borderLeftWidth", "'1px'");115shouldBe("getComputedStyle(table, '').borderRightWidth", "'1px'");116shouldBe("getComputedStyle(table, '').borderTopWidth", "'1px'");117shouldBe("getComputedStyle(table, '').borderBottomWidth", "'1px'");118shouldBe("getComputedStyle(table, '').borderLeftStyle", "'solid'");119shouldBe("getComputedStyle(table, '').borderRightStyle", "'solid'");120shouldBe("getComputedStyle(table, '').borderTopStyle", "'solid'");121shouldBe("getComputedStyle(table, '').borderBottomStyle", "'solid'");122shouldBe("getComputedStyle(table, '').borderLeftColor", "yellow");123shouldBe("getComputedStyle(table, '').borderRightColor", "yellow");124shouldBe("getComputedStyle(table, '').borderTopColor", "yellow");125shouldBe("getComputedStyle(table, '').borderBottomColor", "yellow");126shouldBe("getComputedStyle(cell, '').borderLeftWidth", "'0px'");127shouldBe("getComputedStyle(cell, '').borderRightWidth", "'0px'");128shouldBe("getComputedStyle(cell, '').borderTopWidth", "'1px'");129shouldBe("getComputedStyle(cell, '').borderBottomWidth", "'1px'");130shouldBe("getComputedStyle(cell, '').borderLeftStyle", "'none'");131shouldBe("getComputedStyle(cell, '').borderRightStyle", "'none'");132shouldBe("getComputedStyle(cell, '').borderTopStyle", "'solid'");133shouldBe("getComputedStyle(cell, '').borderBottomStyle", "'solid'");134shouldBe("getComputedStyle(cell, '').borderLeftColor", "red");135shouldBe("getComputedStyle(cell, '').borderRightColor", "red");136shouldBe("getComputedStyle(cell, '').borderTopColor", "red");137shouldBe("getComputedStyle(cell, '').borderBottomColor", "red");138document.body.removeChild(table);...

Full Screen

Full Screen

scrollbarState.js

Source:scrollbarState.js Github

copy

Full Screen

1/*---------------------------------------------------------------------------------------------2 * Copyright (c) Microsoft Corporation. All rights reserved.3 * Licensed under the MIT License. See License.txt in the project root for license information.4 *--------------------------------------------------------------------------------------------*/5'use strict';6/**7 * The minimal size of the slider (such that it can still be clickable) -- it is artificially enlarged.8 */9var MINIMUM_SLIDER_SIZE = 20;10var ScrollbarState = /** @class */ (function () {11 function ScrollbarState(arrowSize, scrollbarSize, oppositeScrollbarSize) {12 this._scrollbarSize = Math.round(scrollbarSize);13 this._oppositeScrollbarSize = Math.round(oppositeScrollbarSize);14 this._arrowSize = Math.round(arrowSize);15 this._visibleSize = 0;16 this._scrollSize = 0;17 this._scrollPosition = 0;18 this._computedAvailableSize = 0;19 this._computedIsNeeded = false;20 this._computedSliderSize = 0;21 this._computedSliderRatio = 0;22 this._computedSliderPosition = 0;23 this._refreshComputedValues();24 }25 ScrollbarState.prototype.clone = function () {26 var r = new ScrollbarState(this._arrowSize, this._scrollbarSize, this._oppositeScrollbarSize);27 r.setVisibleSize(this._visibleSize);28 r.setScrollSize(this._scrollSize);29 r.setScrollPosition(this._scrollPosition);30 return r;31 };32 ScrollbarState.prototype.setVisibleSize = function (visibleSize) {33 var iVisibleSize = Math.round(visibleSize);34 if (this._visibleSize !== iVisibleSize) {35 this._visibleSize = iVisibleSize;36 this._refreshComputedValues();37 return true;38 }39 return false;40 };41 ScrollbarState.prototype.setScrollSize = function (scrollSize) {42 var iScrollSize = Math.round(scrollSize);43 if (this._scrollSize !== iScrollSize) {44 this._scrollSize = iScrollSize;45 this._refreshComputedValues();46 return true;47 }48 return false;49 };50 ScrollbarState.prototype.setScrollPosition = function (scrollPosition) {51 var iScrollPosition = Math.round(scrollPosition);52 if (this._scrollPosition !== iScrollPosition) {53 this._scrollPosition = iScrollPosition;54 this._refreshComputedValues();55 return true;56 }57 return false;58 };59 ScrollbarState._computeValues = function (oppositeScrollbarSize, arrowSize, visibleSize, scrollSize, scrollPosition) {60 var computedAvailableSize = Math.max(0, visibleSize - oppositeScrollbarSize);61 var computedRepresentableSize = Math.max(0, computedAvailableSize - 2 * arrowSize);62 var computedIsNeeded = (scrollSize > 0 && scrollSize > visibleSize);63 if (!computedIsNeeded) {64 // There is no need for a slider65 return {66 computedAvailableSize: Math.round(computedAvailableSize),67 computedIsNeeded: computedIsNeeded,68 computedSliderSize: Math.round(computedRepresentableSize),69 computedSliderRatio: 0,70 computedSliderPosition: 0,71 };72 }73 // We must artificially increase the size of the slider if needed, since the slider would be too small to grab with the mouse otherwise74 var computedSliderSize = Math.round(Math.max(MINIMUM_SLIDER_SIZE, Math.floor(visibleSize * computedRepresentableSize / scrollSize)));75 // The slider can move from 0 to `computedRepresentableSize` - `computedSliderSize`76 // in the same way `scrollPosition` can move from 0 to `scrollSize` - `visibleSize`.77 var computedSliderRatio = (computedRepresentableSize - computedSliderSize) / (scrollSize - visibleSize);78 var computedSliderPosition = (scrollPosition * computedSliderRatio);79 return {80 computedAvailableSize: Math.round(computedAvailableSize),81 computedIsNeeded: computedIsNeeded,82 computedSliderSize: Math.round(computedSliderSize),83 computedSliderRatio: computedSliderRatio,84 computedSliderPosition: Math.round(computedSliderPosition),85 };86 };87 ScrollbarState.prototype._refreshComputedValues = function () {88 var r = ScrollbarState._computeValues(this._oppositeScrollbarSize, this._arrowSize, this._visibleSize, this._scrollSize, this._scrollPosition);89 this._computedAvailableSize = r.computedAvailableSize;90 this._computedIsNeeded = r.computedIsNeeded;91 this._computedSliderSize = r.computedSliderSize;92 this._computedSliderRatio = r.computedSliderRatio;93 this._computedSliderPosition = r.computedSliderPosition;94 };95 ScrollbarState.prototype.getArrowSize = function () {96 return this._arrowSize;97 };98 ScrollbarState.prototype.getScrollPosition = function () {99 return this._scrollPosition;100 };101 ScrollbarState.prototype.getRectangleLargeSize = function () {102 return this._computedAvailableSize;103 };104 ScrollbarState.prototype.getRectangleSmallSize = function () {105 return this._scrollbarSize;106 };107 ScrollbarState.prototype.isNeeded = function () {108 return this._computedIsNeeded;109 };110 ScrollbarState.prototype.getSliderSize = function () {111 return this._computedSliderSize;112 };113 ScrollbarState.prototype.getSliderPosition = function () {114 return this._computedSliderPosition;115 };116 /**117 * Compute a desired `scrollPosition` such that `offset` ends up in the center of the slider.118 * `offset` is based on the same coordinate system as the `sliderPosition`.119 */120 ScrollbarState.prototype.getDesiredScrollPositionFromOffset = function (offset) {121 if (!this._computedIsNeeded) {122 // no need for a slider123 return 0;124 }125 var desiredSliderPosition = offset - this._arrowSize - this._computedSliderSize / 2;126 return Math.round(desiredSliderPosition / this._computedSliderRatio);127 };128 /**129 * Compute a desired `scrollPosition` such that the slider moves by `delta`.130 */131 ScrollbarState.prototype.getDesiredScrollPositionFromDelta = function (delta) {132 if (!this._computedIsNeeded) {133 // no need for a slider134 return 0;135 }136 var desiredSliderPosition = this._computedSliderPosition + delta;137 return Math.round(desiredSliderPosition / this._computedSliderRatio);138 };139 return ScrollbarState;140}());...

Full Screen

Full Screen

webform.element.computed.js

Source:webform.element.computed.js Github

copy

Full Screen

1/**2 * @file3 * JavaScript behaviors for computed elements.4 */5(function ($, Drupal) {6 'use strict';7 Drupal.webform = Drupal.webform || {};8 Drupal.webform.computed = Drupal.webform.computed || {};9 Drupal.webform.computed.delay = Drupal.webform.computed.delay || 500;10 var computedElements = [];11 /**12 * Initialize computed elements.13 *14 * @type {Drupal~behavior}15 */16 Drupal.behaviors.webformComputed = {17 attach: function (context) {18 // Find computed elements and build trigger selectors.19 $(context).find('.js-webform-computed').once('webform-computed').each(function () {20 // Get computed element and form.21 var $element = $(this);22 var $form = $element.closest('form');23 // Get unique id for computed element based on the element name24 // and form id.25 var id = $form.attr('id') + '-' + $element.find('input[type="hidden"]').attr('name');26 // Get elements that are used by the computed element.27 var elementKeys = $(this).data('webform-element-keys').split(',');28 if (!elementKeys) {29 return;30 }31 // Get computed element trigger selectors.32 var inputs = [];33 $.each(elementKeys, function (i, key) {34 // Exact input match.35 inputs.push(':input[name="' + key + '"]');36 // Sub inputs. (aka #tree)37 inputs.push(':input[name^="' + key + '["]');38 });39 var triggers = inputs.join(',');40 // Track computed elements.41 computedElements.push({42 id: id,43 element: $element,44 form: $form,45 triggers: triggers46 });47 // Clear computed last values to ensure that a computed element is48 // always re-computed on page load.49 $element.attr('data-webform-computed-last', '');50 });51 // Initialize triggers for each computed element.52 $.each(computedElements, function (index, computedElement) {53 // Get trigger from the current context.54 var $triggers = $(context).find(computedElement.triggers);55 // Make sure current context has triggers.56 if (!$triggers.length) {57 return;58 }59 // Make sure triggers are within the computed element's form60 // and only initialized once.61 $triggers = computedElement.form.find($triggers)62 .once('webform-computed-triggers-' + computedElement.id);63 // Double check that there are triggers which need to be initialized.64 if (!$triggers.length) {65 return;66 }67 initializeTriggers(computedElement.element, $triggers);68 });69 /**70 * Initialize computed element triggers.71 *72 * @param {jQuery} $element73 * An jQuery object containing the computed element.74 * @param {jQuery} $triggers75 * An jQuery object containing the computed element triggers.76 */77 function initializeTriggers($element, $triggers) {78 // Add event handler to computed element triggers.79 $triggers.on('keyup change', queueUpdate);80 // Add event handler to computed element tabledrag.81 var $draggable = $triggers.closest('tr.draggable');82 if ($draggable.length) {83 $draggable.find('.tabledrag-handle').on('mouseup pointerup touchend',84 queueUpdate);85 }86 // Queue an update to make sure trigger values are computed.87 queueUpdate();88 // Queue computed element updates using a timer.89 var timer = null;90 function queueUpdate() {91 if (timer) {92 window.clearTimeout(timer);93 timer = null;94 }95 timer = window.setTimeout(triggerUpdate, Drupal.webform.computed.delay);96 }97 function triggerUpdate() {98 // Get computed element wrapper.99 var $wrapper = $element.find('.js-webform-computed-wrapper');100 // If computed element is loading, requeue the update and wait for101 // the computed element to be updated.102 if ($wrapper.hasClass('webform-computed-loading')) {103 queueUpdate();104 return;105 }106 // Prevent duplicate computations.107 // @see Drupal.behaviors.formSingleSubmit108 var formValues = $triggers.serialize();109 var previousValues = $element.attr('data-webform-computed-last');110 if (previousValues === formValues) {111 return;112 }113 $element.attr('data-webform-computed-last', formValues);114 // Add loading class to computed wrapper.115 $wrapper.addClass('webform-computed-loading');116 // Trigger computation.117 $element.find('.js-form-submit').mousedown();118 }119 }120 }121 };...

Full Screen

Full Screen

LogScaler.js

Source:LogScaler.js Github

copy

Full Screen

1//>>built2define("dojox/dgauges/LogScaler",["dojo/_base/lang","dojo/_base/declare","dojo/Stateful"],function(_1,_2,_3){3return _2("dojox.dgauges.LogScaler",_3,{minimum:0,maximum:1000,multiplier:10,majorTicks:null,_computedMultiplier:NaN,constructor:function(){4this.watchedProperties=["minimum","maximum","multiplier"];5},_buildMajorTickItems:function(){6var _4=[];7this._computedMinimum=this.getComputedMinimum();8this._computedMaximum=this.getComputedMaximum();9this._computedMultiplier=this.getComputedMultiplier();10if(this._computedMaximum>this._computedMinimum){11var _5=Math.max(0,Math.floor(Math.log(this._computedMinimum+1e-9)/Math.LN10));12var _6=Math.max(0,Math.floor(Math.log(this._computedMaximum+1e-9)/Math.LN10));13var _7;14for(var i=_5;i<=_6;i+=this._computedMultiplier){15_7={};16_7.value=Math.pow(10,i);17_7.position=(i-_5)/(_6-_5);18_4.push(_7);19}20}21return _4;22},getComputedMinimum:function(){23return Math.pow(10,Math.max(0,Math.floor(Math.log(this.minimum+1e-9)/Math.LN10)));24},getComputedMaximum:function(){25return Math.pow(10,Math.max(0,Math.floor(Math.log(this.maximum+1e-9)/Math.LN10)));26},getComputedMultiplier:function(){27return Math.max(1,Math.floor(Math.log(this.multiplier+1e-9)/Math.LN10));28},computeTicks:function(){29this.majorTicks=this._buildMajorTickItems();30return this.majorTicks.concat();31},positionForValue:function(_8){32if(this._computedMaximum<this._computedMinimum||_8<=this._computedMinimum||_8<1||isNaN(_8)){33_8=this._computedMinimum;34}35if(_8>=this._computedMaximum){36_8=this._computedMaximum;37}38_8=Math.log(_8)/Math.LN10;39var sv=Math.log(this._computedMinimum)/Math.LN10;40var ev=Math.log(this._computedMaximum)/Math.LN10;41return (_8-sv)/(ev-sv);42},valueForPosition:function(_9){43var sv=Math.log(this._computedMinimum)/Math.LN10;44var ev=Math.log(this._computedMaximum)/Math.LN10;45return Math.pow(10,sv+_9*(ev-sv));46}});...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const [response] = await Promise.all([7 page.click('text=Get Started')8 ]);9 await browser.close();10})();11const { chromium } = require('playwright');12(async () => {13 const browser = await chromium.launch();14 const context = await browser.newContext();15 const page = await context.newPage();16 const [response] = await Promise.all([17 page.click('text=Get Started')18 ]);19 await browser.close();20})();21const { chromium } = require('playwright');22(async () => {23 const browser = await chromium.launch();24 const context = await browser.newContext();25 const page = await context.newPage();26 const [response] = await Promise.all([27 page.click('text=Get Started')28 ]);29 await browser.close();30})();31const { chromium } = require('playwright');32(async () => {33 const browser = await chromium.launch();34 const context = await browser.newContext();35 const page = await context.newPage();36 const [response] = await Promise.all([37 page.click('text=Get Started')38 ]);39 await browser.close();40})();41const { chromium } = require('playwright');42(async () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright-internal');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.screenshot({ path: 'example.png' });6 await browser.close();7})();8const { chromium } = require('playwright');9(async () => {10 const browser = await chromium.launch();11 const page = await browser.newPage();12 await page.screenshot({ path: 'example.png' });13 await browser.close();14})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium, webkit, firefox} = require('playwright');2(async () => {3 const browser = await chromium.launch({headless: false});4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: `example.png` });7 await browser.close();8})();9const {chromium, webkit, firefox} = require('playwright');10(async () => {11 const browser = await chromium.launch({headless: false});12 const context = await browser.newContext();13 const page = await context.newPage();14 await page.screenshot({ path: `example.png` });15 await browser.close();16})();17const {chromium, webkit, firefox} = require('playwright');18(async () => {19 const browser = await chromium.launch({headless: false});20 const context = await browser.newContext();21 const page = await context.newPage();22 await page.screenshot({ path: `example.png` });23 await browser.close();24})();25const {chromium, webkit, firefox} = require('playwright');26(async () => {27 const browser = await chromium.launch({headless: false});28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.screenshot({ path: `example.png` });31 await browser.close();32})();33const {chromium, webkit, firefox} = require('playwright');34(async () => {35 const browser = await chromium.launch({headless: false});36 const context = await browser.newContext();37 const page = await context.newPage();38 await page.screenshot({ path: `example.png` });39 await browser.close();40})();41const {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.screenshot({ path: 'example.png' });6 await browser.close();7})();8const { chromium } = require('playwright');9(async () => {10 const browser = await chromium.launch();11 const page = await browser.newPage();12 await page.screenshot({ path: 'example.png' });13 await browser.close();14})();15const { chromium } = require('playwright');16(async () => {17 const browser = await chromium.launch();18 const page = await browser.newPage();19 await page.screenshot({ path: 'example.png' });20 await browser.close();21})();22const { chromium } = require('playwright');23(async () => {24 const browser = await chromium.launch();25 const page = await browser.newPage();26 await page.screenshot({ path: 'example.png' });27 await browser.close();28})();29const { chromium } = require('playwright');30(async () => {31 const browser = await chromium.launch();32 const page = await browser.newPage();33 await page.screenshot({ path: 'example.png' });34 await browser.close();35})();36const { chromium } = require('playwright');37(async () => {38 const browser = await chromium.launch();39 const page = await browser.newPage();40 await page.screenshot({ path: 'example.png' });41 await browser.close();42})();43const { chromium } = require('playwright');44(async () => {45 const browser = await chromium.launch();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Playwright } = require('playwright');2const playwright = new Playwright();3const browser = await playwright.chromium.launch();4const page = await browser.newPage();5const selector = await page.$('text=Get started');6const box = await selector.boundingBox();7console.log(box);8await browser.close();9const { Playwright } = require('playwright');10const playwright = new Playwright();11const browser = await playwright.chromium.launch();12const page = await browser.newPage();13const selector = await page.$('text=Get started');14const box = await selector.boundingBox();15console.log(box);16await browser.close();17const { Playwright } = require('playwright');18const playwright = new Playwright();19const browser = await playwright.chromium.launch();20const page = await browser.newPage();21const selector = await page.$('text=Get started');22const box = await selector.boundingBox();23console.log(box);24await browser.close();25const { Playwright } = require('playwright');26const playwright = new Playwright();27const browser = await playwright.chromium.launch();28const page = await browser.newPage();29const selector = await page.$('text=Get started');30const box = await selector.boundingBox();31console.log(box);32await browser.close();33const { Playwright } = require('playwright');34const playwright = new Playwright();35const browser = await playwright.chromium.launch();36const page = await browser.newPage();37const selector = await page.$('text=Get started');38const box = await selector.boundingBox();39console.log(box);40await browser.close();41const { Playwright } = require('playwright');42const playwright = new Playwright();43const browser = await playwright.chromium.launch();44const page = await browser.newPage();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { computeSelector } = require('playwright/lib/server/dom.js');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 const selector = computeSelector(page, '[aria-label="Search"]');5 console.log(selector);6});7}8const { computeSelector } = require('playwright/lib/server/dom.js');9const { test } = require('@playwright/test');10test('test', async ({ page }) => {11 const selector = computeSelector(page, '[aria-label="Google Search"]');12 console.log(selector);13});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { WebKit } = require('playwright');2const webkit = new WebKit();3const page = await webkit.launch().newPage();4const { computedStyle } = page.mainFrame();5const style = await computedStyle('h1');6console.log(style);7const puppeteer = require('puppeteer');8const browser = await puppeteer.launch();9const page = await browser.newPage();10const style = await page.evaluate(() => {11 const element = document.querySelector('h1');12 return window.getComputedStyle(element);13});14console.log(style);15const { webkit } = require('playwright');16const browser = await webkit.launch();17const page = await browser.newPage();18const style = await page.$eval('h1', el => {19 return window.getComputedStyle(el);20});21console.log(style);22const puppeteer = require('puppeteer');23const browser = await puppeteer.launch();24const page = await browser.newPage();25const style = await page.$eval('h1', el => {26 return window.getComputedStyle(el);27});28console.log(style);29const { WebKit } = require('playwright');30const webkit = new WebKit();31const page = await webkit.launch().newPage();32const { computedStyle } = page.mainFrame();33const style = await computedStyle('h1');34console.log(style);35const puppeteer = require('puppeteer');36const browser = await puppeteer.launch();37const page = await browser.newPage();38const style = await page.evaluate(() => {39 const element = document.querySelector('h1');40 return window.getComputedStyle(element);41});42console.log(style);43const { webkit } = require('playwright');44const browser = await webkit.launch();45const page = await browser.newPage();46const style = await page.$eval('h1', el => {47 return window.getComputedStyle(el);48});49console.log(style);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Playwright } from '@playwright/test';2const playwright = new Playwright();3playwright._computeSelector('css=button');4import { chromium } from 'playwright';5const browser = await chromium.launch();6const context = await browser.newContext();7const page = await context.newPage();8const selector = page._computeSelector('css=button');9console.log(selector);10await page.close();11await context.close();12await browser.close();13{14}15{16}17{18}19{

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful