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

From MozillaWiki
< Labs‎ | Jetpack‎ | Reboot‎ | JEP
Jump to navigation Jump to search
Line 77: Line 77:
</pre>
</pre>


 
<pre>  
 
myMods.add('styles', {
<b>Removing includes</b>
     'body':{
<pre>
         'background': '#ffffff',
myMods.remove({  
         'font-family':'Trebuchet MS'
     'includes':{
    },
         'script': ['http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools.js'],
    'span.details':{
         'styles': ['http://yui.yahooapis.com/3.0.0/build/cssbase/base-min.css']
        'font-size':'7px'
     }
     }
});
});
</pre>
</pre>


<b>Removing all includes</b>
<pre>
<pre>
// This method also takes the options: 'styles', 'script', 'matches', 'all'
myMods.add('styles', 'a.special { color: green; font-size: 18px; }');
moddingTwoPages.empty('includes');
</pre>
</pre>


==== Style Methods ====
<pre>
 
myMods.add('script', function(){
<b>Adding styles via object</b>
    var pageLog = function(){
<pre>  
         console.log('I just initialized a pageMod!');
moddingTwoPages.add({
    'styles': {
        'body':{
            'background': '#ffffff',
            'font-family':'Trebuchet MS'
        },
         'span.details':{
            'font-size':'7px'
        }
     }
     }
});
});
</pre>
</pre>


<b>Adding styles via string</b>
<pre>
<pre>
moddingTwoPages.add({
myMods.add('matches', ['*.digg.com']);
    'styles': 'a.special { color: green; font-size: 18px; }'
});
</pre>
</pre>


<b>Removing specific styles</b>
==== Page Mods Method: <i>remove</i> ====
<pre>
 
moddingTwoPages.remove({
<b>Arguments:</b>
    'styles':{
 
        'body':['background', 'font-family'],
#type - (<i>string</i>) The type of modifier being added. Can be 'matches', 'includes', 'styles', or 'script'. NOTE: If the only argument is an object, Page Mods assumes multiple modifiers will be passed in.
        'span.details':['font-size']
#data -
    }
#* matches: expects an array of URL strings
});
#* includes: expects an array of asset URL strings
</pre>
#* styles: expects a single string, or an object whose keys are CSS selectors and values are objects composed of keys which are CSS properties and their values.
#* script: expects a function, the function is bound with the target document's window object
 


<b>Removing all styles</b>
<b>Returns:</b>
<pre>
// This method (also noted above) takes the options: 'includes', 'script', 'matches', 'all'
moddingTwoPages.empty('styles');
</pre>


The attached Page Mods instance


==== Script Methods  ====
<b>Examples:</b>


<b>Adding script</b>
<pre>
<pre>
moddingTwoPages.add({
myMods.remove('includes', {
     'script': function(){
     'script': ['http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools.js'],
        var pageLog = function(){
     'styles': ['http://yui.yahooapis.com/3.0.0/build/cssbase/base-min.css']
            console.log('I just initialized a pageMod!');
        }
     }
});
});
</pre>
</pre>


<b>Removing all script</b>
<pre>
<pre>
// This method also takes the options: 'includes', 'styles', 'matches', 'all'
myMods.remove('styles', {
moddingTwoPages.empty('script');
    'body':['background', 'font-family'],
    'span.details':['font-size']
});
</pre>
</pre>




==== Match Methods ====
==== Page Mods Method: <i>empty</i> ====


<b>Adding matches</b>
<b>Arguments:</b>


#type - (<i>string</i>) The type of modifier being added. Can be 'matches', 'includes', 'styles', or 'script'. NOTE: If the only argument is an object, Page Mods assumes multiple modifiers will be passed in.
#data -
#* matches: expects an array of URL strings
#* includes: expects an array of asset URL strings
#* styles: expects a single string, or an object whose keys are CSS selectors and values are objects composed of keys which are CSS properties and their values.
#* script: expects a function, the function is bound with the target document's window object


<b>Removing matches</b>
<pre>
var moddingOnePage = moddingThreePages.remove({
    'matches': ['*.google.com', 'jetpack.mozillalabs.com']
});
</pre>


<b>Removing all matches</b>
<b>Returns:</b>
 
The attached Page Mods instance
 
<b>Examples:</b>
 
<pre>
<pre>
// This method (also noted above) takes the options: 'includes', 'styles', 'script', 'all'
moddingTwoPages.empty('includes');
moddingTwoPages.empty('matches');
</pre>
</pre>

Revision as of 15:58, 4 February 2010

JEP 107 - Page Mods

  • Champion: Daniel Buchner - daniel@mozilla.com
  • Status: Accepted/In-Queue
  • Bug Ticket:
  • Type: API
  • Difficulty: 4


Proposal

Page Mods is chiefly aimed at modifying and manipulating content documents within Firefox. Pages Mods should perform this functionality in a seamless fashion where the end result is the only change visible to the user.

Key Issues

When documents load that are represented in the "matches" white-list, we must ensure that script and styles injected into the page are evaluated by the parser in the normal load cycle. Perhaps we achieve this by dynamically creating resource (or custom protocol) URIs that contain the style and script blocks entered similar to the Background Page mechanisms. These URIs would be dynamically created CSS/JS files that would then be injected in the appropriate places withing the matched documents (CSS files in the doc head, JS files just after the close of the body tag).

Dependencies & Requirements

  • Are there any Firefox platform bugs blocking it?
  • Does other Jetpack platform code need to be modified or added?
  • Does its implementation affect any other projects or code?


Internal Methods

API Methods

Page Mods Initialization

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; }' +
              'span.details { font-size: 7px; }'
    },
    'script': function(){
        $('container').addEvents({
            'mouseenter:relay(ul li)':function(){ this.tween('background','#000'); },
            'mouseleave:relay(ul li)':function(){ this.tween('background','#fff'); }
        })
    }
});


Page Mods Method: add

Arguments:

  1. type - (string) The type of modifier being added. Can be 'matches', 'includes', 'styles', or 'script'. NOTE: If the only argument is an object, Page Mods assumes multiple modifiers will be passed in.
  2. data -
    • matches: expects an array of URL strings
    • includes: expects an array of asset URL strings
    • styles: expects a single string, or an object whose keys are CSS selectors and values are objects composed of keys which are CSS properties and their values.
    • script: expects a function, the function is bound with the target document's window object


Returns:

The attached Page Mods instance


Examples:

myMods.add('matches', ['*.digg.com']);
myMods.add('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']
});
 
myMods.add('styles', {
    'body':{
        'background': '#ffffff',
        'font-family':'Trebuchet MS'
    },
    'span.details':{
        'font-size':'7px'
    }
});
myMods.add('styles', 'a.special { color: green; font-size: 18px; }');
myMods.add('script', function(){
    var pageLog = function(){
        console.log('I just initialized a pageMod!');
    }
});
myMods.add('matches', ['*.digg.com']);

Page Mods Method: remove

Arguments:

  1. type - (string) The type of modifier being added. Can be 'matches', 'includes', 'styles', or 'script'. NOTE: If the only argument is an object, Page Mods assumes multiple modifiers will be passed in.
  2. data -
    • matches: expects an array of URL strings
    • includes: expects an array of asset URL strings
    • styles: expects a single string, or an object whose keys are CSS selectors and values are objects composed of keys which are CSS properties and their values.
    • script: expects a function, the function is bound with the target document's window object


Returns:

The attached Page Mods instance

Examples:

myMods.remove('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']
});
myMods.remove('styles', {
    'body':['background', 'font-family'],
    'span.details':['font-size']
});


Page Mods Method: empty

Arguments:

  1. type - (string) The type of modifier being added. Can be 'matches', 'includes', 'styles', or 'script'. NOTE: If the only argument is an object, Page Mods assumes multiple modifiers will be passed in.
  2. data -
    • matches: expects an array of URL strings
    • includes: expects an array of asset URL strings
    • styles: expects a single string, or an object whose keys are CSS selectors and values are objects composed of keys which are CSS properties and their values.
    • script: expects a function, the function is bound with the target document's window object


Returns:

The attached Page Mods instance

Examples:

moddingTwoPages.empty('includes');