CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-zepto

Zepto is a minimalist JavaScript library for modern browsers with a largely jQuery-compatible API

Overview
Eval results
Files

stack-operations.mddocs/

Stack Operations

Method chaining history management for complex query operations. The stack module maintains a history of element collections during chaining operations, allowing developers to navigate back to previous selections.

Capabilities

Chain Navigation

Methods for navigating through the chain history during complex DOM operations.

/**
 * End the most recent filtering operation and return to the previous set of elements
 * @returns Previous collection in the chain
 */
$.fn.end();

/**
 * Add the previous set of elements to the current collection
 * @returns Combined collection including both current and previous elements
 */
$.fn.andSelf();

Usage Examples:

// Using end() to navigate back in the chain
$('#container')
  .find('.item')
  .addClass('highlighted')
  .end()  // Back to #container
  .addClass('processed');

// Complex chaining with multiple end() calls
$('.list')
  .find('li')
  .filter('.active')
  .addClass('current')
  .end()  // Back to all li elements
  .end()  // Back to .list elements
  .fadeIn();

// Using andSelf() to combine sets
$('.parent')
  .children('.child')
  .andSelf()  // Include both .parent and .child elements
  .addClass('combined');

Chain History

The stack operations modify the following methods to support chaining history:

  • filter() - Maintains reference to unfiltered collection
  • add() - Maintains reference to original collection
  • not() - Maintains reference to original collection
  • eq() - Maintains reference to full collection
  • first() - Maintains reference to full collection
  • last() - Maintains reference to full collection
  • find() - Maintains reference to search context
  • closest() - Maintains reference to original collection
  • parents() - Maintains reference to original collection
  • parent() - Maintains reference to original collection
  • children() - Maintains reference to parent collection
  • siblings() - Maintains reference to original collection

Advanced Chain Navigation

Complex operations combining multiple chain navigation techniques.

// Multi-level navigation example
$('#form')
  .find('input')
  .filter('[required]')
  .addClass('required-field')
  .end()          // Back to all inputs
  .filter('[type="email"]')
  .addClass('email-field')
  .end()          // Back to all inputs
  .end()          // Back to #form
  .find('button')
  .addClass('form-button');

// Combining andSelf() with filtering
$('.menu')
  .find('.menu-item')
  .filter('.active')
  .andSelf()      // Include both active items and their parent menu
  .addClass('highlight-group');

// Working with siblings and navigation
$('.selected')
  .siblings()
  .addClass('sibling')
  .end()          // Back to .selected elements
  .addClass('original-selection');

Chain Stack Internal Structure

The stack maintains internal references to previous collections:

// Internal structure (for reference only)
{
  length: 3,
  0: element1,
  1: element2, 
  2: element3,
  prevObject: previousZeptoCollection,  // Used by end()
  context: originalContext              // Original search context
}

This internal structure allows end() to return to the prevObject and andSelf() to combine the current collection with prevObject.

Install with Tessl CLI

npx tessl i tessl/npm-zepto

docs

advanced-features.md

ajax.md

animation.md

browser-detection.md

callback-management.md

core-dom.md

css-styling.md

data-management.md

enhanced-selectors.md

events.md

forms.md

index.md

mobile-touch.md

stack-operations.md

tile.json