[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.
- var defaults={
- offsetx:2,//Mouse on X-axis offset
- offsety:2,//Mouse on y-axis offset
- speed:300,//effect Speed
- flash:!1,//effect is turned on, default does not open
- Flashmode: ",//special effects mode, with Flash for true use
- cancel:!1,//exclusion does not appear in the right-click menu area
- items:[],//menu Items
- Action:$.noop ()//Free menu item back to Event
- };
There are two ways to add a right-click menu : One is to add items and have an event callback directly;
- <script type="Text/javascript">
- $ (function () {
- $ (' #WincontextMenu-test '). Wincontextmenu ({
- Cancel: '. Cancel ',
- items:[{
- ID: ' Item1 ',
- Text: ' Item1 item ',
- Icon: '. /skins/default/contextmenu/icons/sync.png ',
- disable:!0,//new additions to True/false
- Action:function () {alert (' first-item1 ')}//added by item
- },
- {
- ID: ' ITEM2 ',
- Text: ' ITEM2 item ',
- Icon: '. /skins/default/contextmenu/icons/calendar.png ',
- Action:function () {alert (' second-item2 ')}//added by item
- }],
- Action:function (e) {alert (e.id);} Free Design Item Event callback
- });
- });
- </Script>
The second is to add an Li tag to the Web page by the specified ID of Wincontextmenu
- <div id="Wincontextmenu" class="Wincontextmenu" style= "top:100px; left:230px; Display:none; " >
- <li><< Span class= "Tag-name" >a id= "copy" href=" # ">< img src= ". /skins/default/contextmenu/icons/copy.png ">< Span> copy </span> </a></ li>
- <li> <a id= " Create " href=" # "> <img src= >< Span> new </span> </a></ li>
- <div class= "m-split" ></div >
- <li><a id="Save" href="#"><img src=". /skins/default/contextmenu/icons/save.png "><span> Save </span> </a></li>
- <Li><a id= "table" href= "#" class= "cmdisable" ><< Span class= "Tag-name" >img src= ". /skins/default/contextmenu/icons/table.png ">< Span> form </span> </a></ li>
- <li> <a id= " Setup " href=" # "> <img src= >< span> set </span ></a> </li>
- </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
- /*
- * Author:antianlu
- * DATE:2012-04-21
- * Plugin Name:jQuery.Contextmenu
- * address:http://www.oschina.net/code/snippet_153403_9880
- * version:0.2
- * Email:[email protected]
- */
- (function (cm) {
- jquery.fn.wincontextmenu=Function (options) {
- var defaults={
- offsetx:2,//Mouse on X-axis offset
- offsety:2,//Mouse on y-axis offset
- speed:300,//effect Speed
- flash:!1,//effect is turned on, default does not open
- Flashmode: ",//special effects mode, with Flash for true use
- cancel:!1,//exclusion does not appear in the right-click menu area
- items:[],//menu Items
- Action:$.noop ()//Free menu item back to Event
- };
- var opt=cm.extend (true,defaults,options);
- function Create (e) {
- var m=cm ('<ul class=' wincontextmenu></ul> '). AppendTo ( Document.body);
- Cm.each (Opt.items,function (I,ITM) {
- if (ITM) {
- Varrow=cm (' ref=" Sitem " href= "javascript:void (0)" > <span></ span></a ></li> '). AppendTo (m);
- ITM.ICON?CM ('<img src= '' +itm.icon+ '> '). InsertBefore (Row.find (' span ')): ';
- Itm.text?row.find (' span '). Text (Itm.text): ";
- if (itm.action) {
- Row.find (' a '). Click (function () {this.classname!= ' cmdisable '? Itm.action (e): null;});
- }
- });
- if (cm (' #WincontextMenu '). html ()!=null) {
- CM (cm (' #WincontextMenu '). html (). Replace (/#/g, ' javascript:void (0) '). AppendTo (m);}
- return m;
- }
- if (opt.cancel) {//exclude do not appear right-click menu area
- CM (Opt.cancel). Live (' ContextMenu ', function (e) {return false});
- This.live (' ContextMenu ', function (e) {
- var m=Create (E). Show ();
- var l = E.pagex + opt.offsetx,
- t = e.pagey+opt.offsety,
- p={
- WH:CM (window). Height (),
- WW:CM (window). Width (),
- Mh:m.height (),
- Mw:m.width ()
- }
- t= (T+P.MH)>=p.wh? ( t-=p.mh): t;//When the menu is outside the bounds of the window
- l= (L+P.MW)>=p.ww? ( l-=P.MW): l;
- M.css ({zindex:1000001, left:l, Top:t}). Live (' ContextMenu ', function () {return false;});
- M.find (' a '). Click (function (e) {///Call the new menu item added from the page
- var b=$ (this). attr (' ref ');
- if (b!= ' Sitem ') {this.classname!= ' cmdisable '? Opt.action (this): null;}
- E.preventdefault ();
- });
- CM (Document.body). Live (' ContextMenu click ', function () {//Prevent dynamically loaded label invalidation issues
- M.remove ();
- });
- return false;
- });
- return this;
- }
- }) (JQuery);
Original address: http://www.oschina.net/code/snippet_153403_9880
[Xplugins] JQuery ContextMenu Right-click menu