[Xplugins] JQuery ContextMenu Right-click menu

Source: Internet
Author: User

[2012-04-12] Contextmenu Right-click menu v0.1 Release

[Function] Popup Right-click menu in a specific area

[function] can be in the popup right-click menu area, and then block a small area.

[function] There are two ways to add a right-click menu item, parameter configuration to add and specify ID entry.

[Function] Support event callback, there are two, a parameter is configured to correspond to callbacks, specify the ID of the unified callback, can be based on the setting of the link label difference.

[2012-04-29] Contextmenu Right-click menu v0.2 version update

[fix] Fixed a bug where the specified ID was added when the content does not exist.

[new] Added the function that the menu becomes gray and the event callback is invalid.

[Adjust] adjusted part of the CSS, the source code is divided into models, and debugging parts.

Plugin description

Contextmenu is a multi-function, JQuery-based dialog box plugin.

Operating Environment

Compatible with ie6+, Firefox, Chrome, Opera and other mainstream browsers.

Use authorization

Contextmenu permanent free use, if there are good suggestions, please email: [Email protected], Contextmenu perfect need everyone's good advice.

Since the configuration of the overall project development to use the right-click menu, such as tables, Web desktop and so on. Describes the functions of the right-click menu design, which can be learned according to the configuration file annotations.

    1. var defaults={
    2. offsetx:2,//Mouse on X-axis offset
    3. offsety:2,//Mouse on y-axis offset
    4. speed:300,//effect Speed
    5. flash:!1,//effect is turned on, default does not open
    6. Flashmode: ",//special effects mode, with Flash for true use
    7. cancel:!1,//exclusion does not appear in the right-click menu area
    8. items:[],//menu Items
    9. Action:$.noop ()//Free menu item back to Event
    10. };

There are two ways to add a right-click menu : One is to add items and have an event callback directly;

  1. <script type="Text/javascript">
  2. $ (function () {
  3. $ (' #WincontextMenu-test '). Wincontextmenu ({
  4. Cancel: '. Cancel ',
  5. items:[{
  6. ID: ' Item1 ',
  7. Text: ' Item1 item ',
  8. Icon: '. /skins/default/contextmenu/icons/sync.png ',
  9. disable:!0,//new additions to True/false
  10. Action:function () {alert (' first-item1 ')}//added by item
  11. },
  12. {
  13. ID: ' ITEM2 ',
  14. Text: ' ITEM2 item ',
  15. Icon: '. /skins/default/contextmenu/icons/calendar.png ',
  16. Action:function () {alert (' second-item2 ')}//added by item
  17. }],
  18. Action:function (e) {alert (e.id);} Free Design Item Event callback
  19. });
  20. });
  21. </Script>

The second is to add an Li tag to the Web page by the specified ID of Wincontextmenu

  1. <div id="Wincontextmenu" class="Wincontextmenu" style= "top:100px; left:230px; Display:none; " >
  2.   <li><< Span class= "Tag-name" >a id= "copy"  href=" # ">< img src= ". /skins/default/contextmenu/icons/copy.png ">< Span> copy </span> </a></ li>   
  3.   <li> <a id= " Create " href=" # "> <img src= >< Span> new </span> </a></ li>   
  4.   <div class= "m-split" ></div >   
  5. <li><a id="Save" href="#"><img src=". /skins/default/contextmenu/icons/save.png "><span> Save </span> </a></li>
  6. <Li><a id= "table"  href= "#"  class= "cmdisable" ><< Span class= "Tag-name" >img src= ". /skins/default/contextmenu/icons/table.png ">< Span> form </span> </a></ li>   
  7.   <li> <a id= " Setup " href=" # "> <img src= >< span> set </span ></a> </li>   
  8. </div>

The above two additions are listed in the previous row, appended by the specified ID, in the items item.

Seeing is believing, or directly to the source code to go ... This page is available for download.

Code Snippets (4)

File Admininterface-contextmenu (source v0.2). rar ~ 268KB Download (34)

[code] jquery UI ContextMenu Right-click menu
  1. /*
  2. * Author:antianlu
  3. * DATE:2012-04-21
  4. * Plugin Name:jQuery.Contextmenu
  5. * address:http://www.oschina.net/code/snippet_153403_9880
  6. * version:0.2
  7. * Email:[email protected]
  8. */
  9. (function (cm) {
  10. jquery.fn.wincontextmenu=Function (options) {
  11. var defaults={
  12. offsetx:2,//Mouse on X-axis offset
  13. offsety:2,//Mouse on y-axis offset
  14. speed:300,//effect Speed
  15. flash:!1,//effect is turned on, default does not open
  16. Flashmode: ",//special effects mode, with Flash for true use
  17. cancel:!1,//exclusion does not appear in the right-click menu area
  18. items:[],//menu Items
  19. Action:$.noop ()//Free menu item back to Event
  20. };
  21. var opt=cm.extend (true,defaults,options);
  22. function Create (e) {
  23. var m=cm ('<ul class=' wincontextmenu></ul> '). AppendTo (  Document.body);
  24. Cm.each (Opt.items,function (I,ITM) {
  25. if (ITM) {
  26. Varrow=cm (' ref=" Sitem "  href= "javascript:void (0)" > <span></ span></a ></li> '). AppendTo (m);  
  27. ITM.ICON?CM ('<img src= '' +itm.icon+ '> '). InsertBefore (Row.find (' span ')): ';
  28. Itm.text?row.find (' span '). Text (Itm.text): ";
  29. if (itm.action) {
  30. Row.find (' a '). Click (function () {this.classname!= ' cmdisable '? Itm.action (e): null;});
  31. }
  32. });
  33. if (cm (' #WincontextMenu '). html ()!=null) {
  34. CM (cm (' #WincontextMenu '). html (). Replace (/#/g, ' javascript:void (0) '). AppendTo (m);}
  35. return m;
  36. }
  37. if (opt.cancel) {//exclude do not appear right-click menu area
  38. CM (Opt.cancel). Live (' ContextMenu ', function (e) {return false});
  39. This.live (' ContextMenu ', function (e) {
  40. var m=Create (E). Show ();
  41. var l = E.pagex + opt.offsetx,
  42. t = e.pagey+opt.offsety,
  43. p={
  44. WH:CM (window). Height (),
  45. WW:CM (window). Width (),
  46. Mh:m.height (),
  47. Mw:m.width ()
  48. }
  49. t= (T+P.MH)>=p.wh? ( t-=p.mh): t;//When the menu is outside the bounds of the window
  50. l= (L+P.MW)>=p.ww? (  l-=P.MW): l;
  51. M.css ({zindex:1000001, left:l, Top:t}). Live (' ContextMenu ', function () {return false;});
  52. M.find (' a '). Click (function (e) {///Call the new menu item added from the page
  53. var b=$ (this). attr (' ref ');
  54. if (b!= ' Sitem ') {this.classname!= ' cmdisable '? Opt.action (this): null;}
  55. E.preventdefault ();
  56. });
  57. CM (Document.body). Live (' ContextMenu click ', function () {//Prevent dynamically loaded label invalidation issues
  58. M.remove ();
  59. });
  60. return false;
  61. });
  62. return this;
  63. }
  64. }) (JQuery);

Original address: http://www.oschina.net/code/snippet_153403_9880

[Xplugins] JQuery ContextMenu Right-click menu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.