All Projects → PhpGt → Dom

PhpGt / Dom

Licence: MIT License
Modern DOM API.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to Dom

Html Dom
This project is developed by Nguyen Huu Phuoc. I love building products and sharing knowledge.
Stars: ✭ 4,269 (+4751.14%)
Mutual labels:  dom, document-object-model, dom-manipulation
Webappsec Trusted Types
A browser API to prevent DOM-Based Cross Site Scripting in modern web applications.
Stars: ✭ 424 (+381.82%)
Mutual labels:  dom, w3c
Wpt
Test suites for Web platform specs — including WHATWG, W3C, and others
Stars: ✭ 3,573 (+3960.23%)
Mutual labels:  dom, w3c
Jsoup
jsoup: the Java HTML parser, built for HTML editing, cleaning, scraping, and XSS safety.
Stars: ✭ 9,184 (+10336.36%)
Mutual labels:  dom, css-selectors
domonic
Create HTML with python 3 using a standard DOM API. Includes a python port of JavaScript for interoperability and tons of other cool features. A fast prototyping library.
Stars: ✭ 86 (-2.27%)
Mutual labels:  dom, dom-manipulation
Css Select
a CSS selector compiler & engine
Stars: ✭ 279 (+217.05%)
Mutual labels:  dom, css-selector
Browser Monkey
Reliable DOM testing
Stars: ✭ 53 (-39.77%)
Mutual labels:  dom, css-selector
visdom
A library use jQuery like API for html parsing & node selecting & node mutation, suitable for web scraping and html confusion.
Stars: ✭ 80 (-9.09%)
Mutual labels:  css-selector, dom-manipulation
m4q
Small library for DOM manipulation and animation. This library similar to jQuery, but written more simply.
Stars: ✭ 30 (-65.91%)
Mutual labels:  dom, dom-manipulation
grasp
Essential NLP & ML, short & fast pure Python code
Stars: ✭ 58 (-34.09%)
Mutual labels:  document-object-model, css-selectors
ElementFinder
Fetch data from HTML and XML via xpath/css and prepare it with regexp
Stars: ✭ 29 (-67.05%)
Mutual labels:  dom, css-selector
CDom
Simple HTML/XML/BBCode DOM component for PHP.
Stars: ✭ 26 (-70.45%)
Mutual labels:  dom, css-selector
Floki
Floki is a simple HTML parser that enables search for nodes using CSS selectors.
Stars: ✭ 1,642 (+1765.91%)
Mutual labels:  css-selector, css-selectors
Javascript Steppitguide
JavaScript-StepPitGuide《JavaScript踩坑指南》- 说前端简单的什么的最变态了!
Stars: ✭ 30 (-65.91%)
Mutual labels:  dom, w3c
necktie
Necktie – a simple DOM binding tool
Stars: ✭ 43 (-51.14%)
Mutual labels:  dom, dom-manipulation
lego
🚀 Web-components made lightweight & Future-Proof.
Stars: ✭ 69 (-21.59%)
Mutual labels:  dom, w3c
rottenjs
An all-in-one (2.6kb) Javascript library for web development
Stars: ✭ 15 (-82.95%)
Mutual labels:  dom, dom-manipulation
XrayDOM
🔥 X-ray your DOM using just the cursor and never open the console again!
Stars: ✭ 13 (-85.23%)
Mutual labels:  dom
shaven
DOM building utility & Template engine based on JsonML + syntax sugar
Stars: ✭ 66 (-25%)
Mutual labels:  dom
texthighlighter
a no dependency typescript npm package for highlighting user selected text
Stars: ✭ 17 (-80.68%)
Mutual labels:  dom

The modern DOM API for PHP 7 projects

Modern DOM API.

Built on top of PHP's native DOMDocument, this project provides access to modern DOM APIs, as you would expect working with client-side code in the browser.

Performing DOM manipulation in your server-side code enhances the way dynamic pages can be built. Utilising a standardised object-oriented interface means the page can be ready-processed, benefitting browsers, webservers and content delivery networks.


Build status Code quality Code coverage Current version PHP.Gt/Dom documentation

Example usage: Hello, you!

Important note: the example shown here is for illustrative purposes, but using the DOM to directly set data to elements' values tightly couples the logic to the view, which is considered bad practice. Please see the DomTemplate library for a more robust solution to binding data to the DOM.

Consider a page with a form, with an input element to enter your name. When the form is submitted, the page should greet you by your name.

This is a simple example of how source HTML files can be treated as templates. This can easily be applied to more advanced template pages to provide dynamic content, without requiring non-standard techniques such as {{curly braces}} for placeholders, or echo '<div class='easy-mistake'>' . $content['opa'] . '</div>' error-prone HTML construction from within PHP.

Source HTML (name.html)

<!doctype html>
<h1>
	Hello, <span class="name-output">you</span> !
</h1>

<form>
	<input name="name" placeholder="Your name, please" required />
	<button>Submit</button>
</form>

PHP used to inject your name (index.php)

<?php
use Gt\Dom\HTMLDocument;
use Gt\Dom\HTMLElement\HTMLSpanElement;
require "vendor/autoload.php";

$html = file_get_contents("name.html");
$document = new HTMLDocument($html);

if(isset($_GET["name"])) {
	/** @var HTMLSpanElement $span */
	$span = $document->querySelector(".name-output");
	$span->innerText = $_GET["name"];
}

echo $document;

Features at a glance

Known limitations / W3C spec compliance

This repository aims to be as accurate as possible to the DOM specification at https://dom.spec.whatwg.org/ - as of v3.0.0 there are no known inconsistencies.

The DOM specification does however define functionality that is only possible to implement on the client-side. For example, HTMLInputElement::files returns a FileList that enumerates all files that are selected by the user through the browser's interface. This kind of functionality is impossible to implement server-side, but has been stubbed out for consistency with the specification. Attempting to use client-side functionality within this library throws a ClientSideOnlyFunctionalityException.

The following classes extend the ClientSideOnly base class:

  • AudioTrackList
  • CSSStyleDeclaration
  • FileList
  • MediaController
  • MediaError
  • MediaStream
  • StyleSheet
  • TextTrack
  • TextTrackList
  • TimeRanges
  • ValidityState
  • VideoTrackList
  • WindowProxy

Data binding and page template features

This repository is intended to be as accurate to the DOM specification as possible. An extension to the repository is available at https://php.gt/domtemplate which adds page templating and data binding through custom elements and template attributes, introducing serverside functionality similar to that of WebComponents.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].