【小(xiǎo)編推薦】appframework手冊£ -插件(jiàn)

2014-07-07  ≈ π; |   發布者:梁國('£←guó)芳   |  ♠γ₹; 查看(kàn):3320次

app開(kāi)發
 

Plugins

App Framework Plugins are reusable pγφ>ieces of JavaScript* code to heε'lp augment your applicatio≤ n. They can be used to pe✘< >rform trivial tasks or to creaσ&<te complex UI widgets. ↕×There are two types of plug$'πins you can create.
  1. Utility plugins that do not act on obje←↔¶cts
  2. Plugins that act on a bucket/el&<£​ement

If you already have a jQuery* plu≠δλ¶gin that uses the fu ≥nctions we implement, your code shδ✔↓₩ould be fairly easy to port over¶β. For the most part, you will just n×‌eed to change the referenceλ♦ in the IIFE (Immediately Invoked ♥↓✘♥Function Expression)✔α≥☆ from "jQuery" to "jδ&q".

Creating a Plugin for App Framework

First, this document will il★±₹lustrate the basic s∞≈tructure for creating a plu ₹gin, then demonstrate how to creat<∞₩e a utility plugin. Finally thλεis page will share how to create a pl≤♠≠ ugin that acts upon elements in a buck≥±₽et.

The first step to createing a pl©‍±ugin is creating an IIFE (Immediately I¥≠↑nvoked Function Expression) $λ∞δand extend the $.fn object. For÷π  example:

1
2
3
4
5
      &nbφφΩsp; (function($){
      &n♣∏bsp; $.fn.myPlugin=function(){
 
    };
})(af)

The code above creates a simple f' unction that can then be accessed using•♦✔ the object returned b♦±≈y the $().myPlugin() function. Theπ∞★re are a few tips to remem∏σ$₹ber when operating inside the plugin.γ¥

  1. The JavaScript* variable &"σΩquot;this" will be tε↓✘he master App Framework®'σ★ object.
  2. To enable chaining, theβ↓ plugin must return "th♠$♦®is".

 

Next, here is an example of how to ₩×make a utility plugin that does n↕$•ot act on objects.

1
2
3
4
5
     &nbs∏≤&p;  (