ContextJS ;is ;a ;lightweight ;solution ;for ;contextual ;menus. ;Currently, ;there ;are ;two ;versions.
The ;first ;is ;to ;be ;used with Twitters ;Bootstrap ; ;(bootstrap.css ;specifically). ;If ;you ;do ;not ;use ;or ;want ;to ;use ;bootstrap.css, ;there ;is ;a ;standalone ;stylesheet ;to ;give ;the ;menu ;it's ;base ;styles.
Features
;- Linted: ;Valid ;JS
- Can ;be ;used ;with ;or ;without ;Twitters ;Bootstrap.css
- Event ;Based ;Links
- Anchor ;Links
- Headers
- Dividers
- Recursive ;Menus ;(infinite ;depth)
- Vertical ;Space ;Detection ;(turns ;into ;a ;"dropup")
- Horizontal ;Space ;Detection ;(Drops ;to ;the ;left ;instead ;of ;right)
- Add/Delete ;menus ;Dynamically
在线实例
; ;实例演示使用方法
- context.init({
- fadeSpeed: 100,
- filter: function ($obj){},
- above: 'auto',
- preventDoubleContext: true,
- compress: false
- });
<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>
Headers
;- {
- header: 'My Header Title'
- }
<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>
Anchor ;Links
;- {
- text: 'My Link Title',
- href: 'http://contextjs.com/',
- target: '_blank'
- }
<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>
Dividers
;- {
- divider: true
- }
<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>
Event ;Based ;Actions
;- {
- text: 'Event Based Link',
- action: function(e){
- e.preventDefault();
- alert('Do Something');
- }
- }
<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>
Sub-Menus
;- {
- text: 'My Sub-menu',
- subMenu: [menuObjects]
- }
<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>
Tracking ;Links ;with ;Google ;Analytics
;- {
- text: 'context.js',
- href: 'http://contextjs.com/context.js',
- target:'_blank',
- action: function(e){
- _gaq.push(['_trackEvent', 'ContextJS Download', this.pathname, this.innerHTML]);
- }
- }
<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>
参数详解
; ;<table ;class="table ;table-striped ;table-bordered ;table-condensed" ;cellpadding="6"> ; ;<thead> ; ;<tr ;class="firstRow"><th>Paramater</th><th>Type</th><th>Default</th><th>Description</th></tr> ; ; ; ;</thead> ; ;<tbody> ; ;<tr> ; ;<td>fadeSpeed</td> ; ;<td>int</td> ; ;<td>100</td> ; ;<td>The ;speed ;in ;which ;the ;context ;menu ;fades ;in ;(in ;milliseconds)</td> ; ; ; ;</tr> ; ;<tr> ; ;<td>filter</td> ; ;<td>function</td> ; ;<td>null</td> ; ;<td>Function ;that ;each ;finished ;list ;element ;will ;pass ;through ;for ;extra ;modification.</td> ; ; ; ;</tr> ; ;<tr> ; ;<td>above</td> ; ;<td>string ;|| ;boolean</td> ; ;<td>'auto'</td> ; ;<td>If ;set ;to ;'auto', ;menu ;will ;appear ;as ;a ;"dropup" ;if ;there ;is ;not ;enough ;room ;below ;it. ;Settings ;to ;true ;will ;make ;the ;menu ;a ;"popup" ;by ;default.</td> ; ; ; ;</tr> ; ;<tr> ; ;<td>preventDoubleContext</td> ; ;<td>boolean</td> ; ;<td>true</td> ; ;<td>If ;set ;to ;true, ;browser-based ;context ;menus ;will ;not ;work ;on ;contextjs ;menus.</td> ; ; ; ;</tr> ; ;<tr> ; ;<td>compress</td> ; ;<td>boolean</td> ; ;<td>false</td> ; ;<td>If ;set ;to ;true, ;context ;menus ;will ;have ;less ;padding, ;making ;them ;(hopefully) ;more ;unobtrusive</td> ; ; ; ;</tr> ; ; ; ;</tbody> ; ; ; ;</table> ;Updating ;Settings
;- context.settings({initSettings});
<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>
; ; ; ;<table ;class="table ;table-striped ;table-bordered ;table-condensed" ;cellpadding="6"> ; ;<thead> ; ;<tr ;class="firstRow"><th>Paramater</th><th>Type</th><th>Default</th><th>Description</th></tr> ; ; ; ;</thead> ; ;<tbody> ; ;<tr> ; ;<td>settings</td> ; ;<td>object</td> ; ;<td>null</td> ; ;<td>The ;init ;settings ;can ;be ;placed ;in ;here ;to ;update ;context ;menus ;written ;to ;the ;DOM. ;Changing ;settings ;between ;attaching ;menus ;will ;give ;the ;menus ;their ;own ;options.</td> ; ; ; ;</tr> ; ; ; ;</tbody> ; ; ; ;</table> ;
Attaching
;- context.attach('#download', [menuObjects]);
<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>
; ; ; ;<table ;class="table ;table-striped ;table-bordered ;table-condensed" ;cellpadding="6"> ; ;<thead> ; ;<tr ;class="firstRow"><th>Paramater</th><th>Type</th><th>Default</th><th>Description</th></tr> ; ; ; ;</thead> ; ;<tbody> ; ;<tr> ; ;<td>selector</td> ; ;<td>string</td> ; ;<td>null</td> ; ;<td>The ;jQuery ;(or ;css) ;selector ;of ;the ;element ;you ;want ;to ;apply ;the ;context ;menu ;to</td> ; ; ; ;</tr> ; ;<tr> ; ;<td>menuObjects</td> ; ;<td>array</td> ; ;<td>null</td> ; ;<td>An ;array ;of ;objects ;that ;define ;the ;menus ;structure</td> ; ; ; ;</tr> ; ; ; ;</tbody> ; ; ; ;</table> ;
Destroying
;- context.destroy('#download');
<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>
; ; ; ;<table ;class="table ;table-striped ;table-bordered ;table-condensed" ;cellpadding="6"> ; ;<thead> ; ;<tr ;class="firstRow"><th>Paramater</th><th>Type</th><th>Default</th><th>Description</th></tr> ; ; ; ;</thead> ; ;<tbody> ; ;<tr> ; ;<td>selector</td> ; ;<td>string</td> ; ;<td>null</td> ; ;<td>The ;jQuery ;(or ;css) ;selector ;of ;the ;element ;you ;want ;to ;remove ;the ;context ;menu ;from</td> ; ; ; ;</tr> ; ; ; ;</tbody> ; ; ; ;</table> ; ;
下载