Labs/Jetpack/Reboot/JEP/108: Difference between revisions

Line 32: Line 32:
* Functional context for the function passed to the background page can be passed as an option
* Functional context for the function passed to the background page can be passed as an option


==== Page Mods <i>Initialization</i> ====
==== Background Page Global: <i>$dom</i> ====




<pre class="brush:js;">
==== Background Page Method: <i>run</i> ====
var myMods = new pageMod({
  'matches': ['*.google.com', 'jetpack.mozillalabs.com'],
  'includes': {
      'script': ['http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools.js'],
      'styles': ['http://yui.yahooapis.com/3.0.0/build/cssbase/base-min.css']
  },
  'styles': {
      'body': {
          'background': '#ffffff',
          'font-family': 'Trebuchet MS'
      }
  },
  'script': function(){
      $('container').addEvents({
          'click:relay(ul li)': function(){ this.setStyles('background','#000') },
          'mousenter:relay(ul li)': function(){ this.tween('background','#000') },
          'mouseleave:relay(ul li)': function(){ this.tween('background','#fff') }
      });
  }
});
</pre>
 
==== Page Mods Method: <i>add</i> ====


<b>Arguments:</b>
<b>Arguments:</b>


#<b>type</b> - (<i>string</i>) The type of modifier being added. Can be 'matches', 'includes', 'styles', or 'script'. If the only argument passed in is an object, Page Mods assumes multiple modifiers will be passed in.
#<b>options</b> - (<i>object</i>)
#<b>data</b> -
#* matches: (<i>array</i>) an array of web site resource strings
#* matches: (<i>array</i>) an array of web site resource strings
#* includes: (<i>object</i>) 'script' or 'style' keyed nodes whose values are arrays of asset resource strings
#* includes: (<i>object</i>) 'script' or 'style' keyed nodes whose values are arrays of asset resource strings
#* styles: (<i>object</i>) an object whose keys are CSS selectors and whose values are objects composed of CSS property keys and values
#* styles: (<i>object</i>) an object whose keys are CSS selectors and whose values are objects composed of CSS property keys and values
#* script: (<i>function</i>) a function that will be injected into the page and called. By default, the function is bound with the target document's window object
#* script: (<i>function</i>) a function that will be injected into the page and called. By default, the function is bound with the target document's window object
#<b>executable</b> - (<i>array</i>) an array of web site resource strings


<b>Returns:</b>
<b>Returns:</b>
1,273

edits