{"id":27616,"date":"2022-02-01T00:46:52","date_gmt":"2022-01-31T23:46:52","guid":{"rendered":"https:\/\/www.adsafe.org\/?p=27616"},"modified":"2022-02-01T00:46:52","modified_gmt":"2022-01-31T23:46:52","slug":"adsafe-widget-structure","status":"publish","type":"post","link":"https:\/\/www.projectliberty.org\/de\/widget.html","title":{"rendered":"ADsafe Widget Structure"},"content":{"rendered":"<div style=\"margin-left: 50px; padding: 1em; background-color: lemonchiffon; border: 2px solid black;\">\n<p>AD<b>safe<\/b> defines a safe subset of the JavaScript Programming Language,<br \/>\nand an interface that allows programs written in that language to usefully<br \/>\ninteract with a specific subtree of of the HTML document. A programmed<br \/>\nHTML fragment is called a <i>widget<\/i>.<\/p>\n<p>A widget is a fragment of HTML with some script. That script is able<br \/>\nto manipulate the HTML fragment, but is unable to manipulate any other<br \/>\npart of the document. All <code>&lt;input&gt;<\/code> tags must contain<br \/>\nan <code>autocomplete=\"off\"<\/code> attribute.<\/p>\n<p>This is the simplest widget pattern allowed by AD<b>safe<\/b>:<\/p>\n<div style=\"position: relative; left: -4em; background-color: papayawhip; padding: 1em; border: 2px solid black;\">\n<pre>&lt;div id=\"<var>WIDGETNAME_<\/var>\"&gt;\n   <i>html markup required by the widget<\/i>\n&lt;script&gt;\nADSAFE.go(\"<var>WIDGETNAME_<\/var>\", function (dom) {\n    \"use strict\";\n\n\/\/ This is where the code for the widget is placed. It can access\n\/\/ the document through the dom parameter, allowing it indirect\n\/\/ access to html elements, allowing it to change content, styling,\n\/\/ and behavior.\n\n});\n&lt;\/script&gt;\n&lt;\/div&gt;<\/pre>\n<\/div>\n<p>It uses the <a href=\"\">JSLint<\/a> option <code>{adsafe: true, fragment: true}<\/code>.<br \/>\nThe widget must be wrapped in a <code>&lt;div&gt;<\/code> element. The<br \/>\n<code>&lt;div&gt;<\/code> element must have an <code>id<\/code>. The <code>id<\/code><br \/>\nmust contain only upper case ASCII letters with a trailing <code>_<\/code><br \/>\ncharacter. It is the page builder\u2019s responsibility to assure that the<br \/>\n<code>id<\/code> of the <code>&lt;div&gt;<\/code> is unique to the page.<\/p>\n<p>The other elements may have <code>id<\/code>s Those <code>id<\/code>s<br \/>\nmust be in all uppercase and have a prefix that matches the widget <code>id<\/code><br \/>\n. For example,<\/p>\n<div style=\"position: relative; left: -4em; background-color: papayawhip; padding: 1em; border: 2px solid black;\">\n<pre>&lt;div id=\"KODA_\"&gt;\n&lt;p id=\"KODA_BOSANDA\"&gt;<\/pre>\n<\/div>\n<p>The <code>ADSAFE.go<\/code> method gives the script access to a<br \/>\n<var>dom<\/var> object that provides a limited interface to the widget\u2019s<br \/>\nDOM tree.<\/p>\n<p>Another AD<b>safe<\/b> pattern allows the widget to load approved<br \/>\nJavaScript libraries. All of the script tags in a <code>&lt;div&gt;<\/code><br \/>\nmust be at the top level of the <code>&lt;div&gt;<\/code>.<\/p>\n<div style=\"position: relative; left: -4em; background-color: papayawhip; padding: 1em; border: 2px solid black;\">\n<pre>&lt;div id=\"<var>WIDGETNAME_<\/var>\"&gt;\n    <i>html markup required by the widget<\/i>\n&lt;script&gt;\nADSAFE.id(\"<var>WIDGETNAME_<\/var>\");\n&lt;\/script&gt;\n&lt;script src=\"<var>AD<b>safe<\/b> approved url<\/var>\"&gt;&lt;\/script&gt;\n&lt;script&gt;\nADSAFE.go(\"<var>WIDGETNAME_<\/var>\", function (dom, lib) {\n    \"use strict\";\n\n\/\/ This is where the code for the widget is placed. It can access\n\/\/ the document through the dom parameter, allowing it indirect\n\/\/ access to html elements, allowing it to change content, styling,\n\/\/ and behavior.\n\n\/\/ Each library file can give itself a <var>name<\/var>. This script can access\n\/\/ the library file as lib.<var>name<\/var>.\n\n});\n&lt;\/script&gt;\n&lt;\/div&gt;<\/pre>\n<\/div>\n<p>It uses the <a href=\"\">JSLint<\/a> option <code>{adsafe: true, fragment: true}<\/code>.<\/p>\n<p>The services provided through <code>ADSAFE<\/code> methods can include<br \/>\ncommunication with the network and manipulation of the DOM. The <code>ADSAFE<\/code><br \/>\nmethods are provided by the page to give the widgets restricted access<br \/>\nto essential services. It is not safe to give a widget direct access<br \/>\nto any DOM node because access to any DOM node gives access to the <code>document<\/code><br \/>\nobject, which gives unrestricted access to the entire tree and to the<br \/>\nnetwork. It is safe to give a widget indirect access to the DOM through<br \/>\nmethods that assure that no capability leakage occurs.<\/p>\n<p>In order for a widget to be approved by AD<b>safe<\/b>, it may not<br \/>\nmake use of any global variables except the <code>ADSAFE<\/code><br \/>\nobject (or other global variables that a site may designate). It<br \/>\nmay not define any global variables, and it may not contain any<br \/>\ncode that could give the guest code access to the <code>window<\/code><br \/>\nobject or <code>document<\/code> object.<\/p>\n<p>All AD<b>safe<\/b> approved library files must conform to this pattern:<\/p>\n<div style=\"position: relative; left: -4em; background-color: papayawhip; padding: 1em; border: 2px solid black;\">\n<pre>ADSAFE.lib(\"<var>name<\/var>\", function (lib) {\n    \"use strict\";\n\n\/\/ This is where the code for the library module is placed. It cannot\n\/\/ access the document unless the guest code passes the dom parameter\n\/\/ to its methods. The optional lib parameter gives it access to the\n\/\/ currently loaded libraries.\n\n    return {\n\n\/\/ Return an object containing the library module's privileged methods.\n\/\/ The script can get access to this object at lib.<var>name<\/var>.\n\n    };\n});\n<\/pre>\n<\/div>\n<p>It uses the <a href=\"\">JSLint<\/a> option <code>{adsafe: true, fragment: false}<\/code>.<br \/>\nA library file contains a call to <code>ADSAFE.lib<\/code>, which allows<br \/>\nthe file to identify itself and to pass an object to the guest code.<\/p>\n<p><code>ADSAFE.lib<\/code> can only be called at the top of a script<br \/>\nfile. It cannot be called from any other location. Calls to <code>ADSAFE.lib<\/code><br \/>\nmust occur after the call to <code>ADSAFE.id<\/code>, but before<br \/>\nthe call to <code>ADSAFE.go<\/code>.<\/p>\n<p><code>ADSAFE.id<\/code> can only be called at the top of the widget\u2019s<br \/>\nfirst script. It cannot be called from any other location.<\/p>\n<p><code>ADSAFE.go<\/code> can only be called from an inline script.<br \/>\nIt cannot be called from a file. It can only be called once. It<br \/>\nmust be called from the last script block in the fragment.<\/p>\n<p>The <code>id<\/code> of the widget\u2019s containing <code>&lt;div&gt;<\/code><br \/>\nmust exactly match the <var>id<\/var> passed to the <code>ADSAFE.id<\/code><br \/>\nand <code>ADSAFE.go<\/code> methods.<\/p>\n<p>The AD<b>safe<\/b> verifier is able to statically enforce all of these<br \/>\nrestrictions.<\/p>\n<p>If the page wants to modify the <var>dom<\/var> and <var>lib<\/var> objects<br \/>\nand the bunch <var>prototype<\/var> object that are given to the widget,<br \/>\nit pass a function to the <code>ADSAFE._intercept<\/code> method. The function will be<br \/>\ncalled before the function that is supplied with <code>ADSAFE.go<\/code>.<br \/>\nThis can be used to add or remove or modify the methods that are provided<br \/>\nto the widget.<\/p>\n<div style=\"position: relative; left: -4em; background-color: papayawhip; padding: 1em; border: 2px solid black;\">\n<pre>ADSAFE._intercept(function (id, dom, lib, bunch) {\n    \"use strict\";\n\n\/\/ Do not allow widgets to set position to absolute.\n\/\/ This is to prevent phishing and other annoyances.\n\n    var style = bunch.prototype.style;\n\n    bunch.prototype.style = function (name, value) {\n        if (name.toLowerCase() === 'position' &amp;&amp;\n                value.toLowerCase() === 'absolute') {\n            throw {\n                name: 'error',\n                message: 'position:absolute is not allowed'\n            }\n        }\n        return style.apply(this, arguments);\n    };\n});<\/pre>\n<\/div>\n<p>A page could allow inter-widget communication by providing communication<br \/>\nmethods to the <var>lib<\/var> object. A page could allow a method<br \/>\nto change the <code>src<\/code> of a node.<\/p>\n<p>The file <a href=\"\"><code>adsafe.js<\/code><\/a> contains the<br \/>\nruntime component that provides the <code>ADSAFE<\/code> object, and should be loaded before all interceptors and widgets. The<br \/>\nfile <a href=\"\">template.html<\/a> contains the template<br \/>\nfor a widget. The file <a href=\"\">template.js<\/a> contains<br \/>\nthe template for a JavaScript library file.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>ADsafe defines a safe subset of the JavaScript Programming Language, and an interface that allows programs written in that language to usefully interact with a specific subtree of of the HTML document. A programmed HTML fragment is called a widget. A widget is a fragment of HTML with some script. That script is able to [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[],"class_list":{"0":"post-27616","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-allgemein"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.3.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>ADsafe Widget Structure - The Website of Informations<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.projectliberty.org\/de\/widget.html\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ADsafe Widget Structure - The Website of Informations\" \/>\n<meta property=\"og:description\" content=\"ADsafe defines a safe subset of the JavaScript Programming Language, and an interface that allows programs written in that language to usefully interact with a specific subtree of of the HTML document. A programmed HTML fragment is called a widget. A widget is a fragment of HTML with some script. That script is able to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.projectliberty.org\/de\/widget.html\" \/>\n<meta property=\"og:site_name\" content=\"The Website of Informations\" \/>\n<meta property=\"article:published_time\" content=\"2022-01-31T23:46:52+00:00\" \/>\n<meta name=\"author\" content=\"Anthony William\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Anthony William\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"5\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.projectliberty.org\/de\/widget.html\",\"url\":\"https:\/\/www.projectliberty.org\/de\/widget.html\",\"name\":\"ADsafe Widget Structure - The Website of Informations\",\"isPartOf\":{\"@id\":\"https:\/\/www.projectliberty.org\/#website\"},\"datePublished\":\"2022-01-31T23:46:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.projectliberty.org\/#\/schema\/person\/26d70862eb5cf88d95e0524f4813b365\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.projectliberty.org\/de\/widget.html#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.projectliberty.org\/de\/widget.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.projectliberty.org\/de\/widget.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.projectliberty.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ADsafe Widget Structure\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.projectliberty.org\/#website\",\"url\":\"https:\/\/www.projectliberty.org\/\",\"name\":\"The Website of Informations\",\"description\":\"Just another WordPress site\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.projectliberty.org\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"de\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.projectliberty.org\/#\/schema\/person\/26d70862eb5cf88d95e0524f4813b365\",\"name\":\"Anthony William\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/www.projectliberty.org\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e66b6bd62abc29635862a92fb64ae1fd3bf3ba48f22ad069b9e9d4af94faf44e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e66b6bd62abc29635862a92fb64ae1fd3bf3ba48f22ad069b9e9d4af94faf44e?s=96&d=mm&r=g\",\"caption\":\"Anthony William\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ADsafe Widget Structure - The Website of Informations","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.projectliberty.org\/de\/widget.html","og_locale":"de_DE","og_type":"article","og_title":"ADsafe Widget Structure - The Website of Informations","og_description":"ADsafe defines a safe subset of the JavaScript Programming Language, and an interface that allows programs written in that language to usefully interact with a specific subtree of of the HTML document. A programmed HTML fragment is called a widget. A widget is a fragment of HTML with some script. That script is able to [&hellip;]","og_url":"https:\/\/www.projectliberty.org\/de\/widget.html","og_site_name":"The Website of Informations","article_published_time":"2022-01-31T23:46:52+00:00","author":"Anthony William","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Anthony William","Gesch\u00e4tzte Lesezeit":"5\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.projectliberty.org\/de\/widget.html","url":"https:\/\/www.projectliberty.org\/de\/widget.html","name":"ADsafe Widget Structure - The Website of Informations","isPartOf":{"@id":"https:\/\/www.projectliberty.org\/#website"},"datePublished":"2022-01-31T23:46:52+00:00","author":{"@id":"https:\/\/www.projectliberty.org\/#\/schema\/person\/26d70862eb5cf88d95e0524f4813b365"},"breadcrumb":{"@id":"https:\/\/www.projectliberty.org\/de\/widget.html#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.projectliberty.org\/de\/widget.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.projectliberty.org\/de\/widget.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.projectliberty.org\/"},{"@type":"ListItem","position":2,"name":"ADsafe Widget Structure"}]},{"@type":"WebSite","@id":"https:\/\/www.projectliberty.org\/#website","url":"https:\/\/www.projectliberty.org\/","name":"The Website of Informations","description":"Just another WordPress site","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.projectliberty.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"de"},{"@type":"Person","@id":"https:\/\/www.projectliberty.org\/#\/schema\/person\/26d70862eb5cf88d95e0524f4813b365","name":"Anthony William","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/www.projectliberty.org\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e66b6bd62abc29635862a92fb64ae1fd3bf3ba48f22ad069b9e9d4af94faf44e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e66b6bd62abc29635862a92fb64ae1fd3bf3ba48f22ad069b9e9d4af94faf44e?s=96&d=mm&r=g","caption":"Anthony William"}}]}},"_links":{"self":[{"href":"https:\/\/www.projectliberty.org\/de\/wp-json\/wp\/v2\/posts\/27616","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.projectliberty.org\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.projectliberty.org\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.projectliberty.org\/de\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.projectliberty.org\/de\/wp-json\/wp\/v2\/comments?post=27616"}],"version-history":[{"count":0,"href":"https:\/\/www.projectliberty.org\/de\/wp-json\/wp\/v2\/posts\/27616\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.projectliberty.org\/de\/wp-json\/wp\/v2\/media?parent=27616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.projectliberty.org\/de\/wp-json\/wp\/v2\/categories?post=27616"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.projectliberty.org\/de\/wp-json\/wp\/v2\/tags?post=27616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}