To execute the example, create an HTML page and perform the following operations:
1. Add links to following CSS files: PP.css, PP.Metabase.css.
Also add links to the following JS files: PP.js, PP.Metabase.js and resources.ru.js.
The root folder of the project must contain images folder named img and resources folder named resources.
2. Next in the <head> tag add a script that creates the DiscussMenu component:
<script type="text/javascript"> var onReady = function () { // Specify path to the root folder that contains resources files PP.resourceManager.setRootResourcesFolder("../resources/"); // Set regional settings for Russian language PP.setCurrentCulture(PP.setCurrentCulture(PP.Cultures.ru)); // Create the Share menu var shareMenu = new PP.Ui.DiscussMenu({ ImagePath: "../img/", // Path to the icons folder BeforeDiscuss: function (sender, args) // Event fired on menu item selection { alert("Before going to " + args.ShareType) }, Discuss: function (sender, args) // Event fired after menu item selection { alert("After going to " + args.ShareType) } } ); // Add a button for opening the Share menu var btn = new PP.Ui.Button({ ParentNode: document.getElementById("btn1"), Content: "Share", Menu: shareMenu, }) // Add a button that will change parameters of the Share menu items var btn = new PP.Ui.Button( { ParentNode: document.getElementById("btn2"), Content: "Change menu items", Click: function () { shareMenu.getLinkedInItem().setIsHovered(true); // The LinkedIn item is selected as on mouse over shareMenu.getFacebookItem().setEnabled(false); // The Facebook item is inactive shareMenu.getTwitterItem().setIsVisible(false); // The Twitter item is hidden shareMenu.getLiveJournalItem().setIsVisible(false); // The LiveJournal item is hidden } }) } </script>
3. In the <body> tag as a value of the onLoad attribute specify name of the function for component creation, and add two <div> elements with the IDs btn1 and btn2:
<body onload="onReady()"> <div id="btn1"></div> <div id="btn2"></div> </body>
After executing the example the Share and Change Menu Items buttons are placed in the page. Clicking the first button opens a menu:
On clicking a menu item the Before jumping to <social network name> message is displayed. Next the user is directed to the site of selected social network, and the screen displays the following message: After jumping to <social network name>.
Clicking the Change Menu Items button selects the LinkedIn item on mouseover, the Facebook item will be disabled, the Twitter and LiveJournal items will be hidden (The Meta Platforms Inc. company, which owns the social network Facebook, is recognized as an extremist organization, and its activity on the territory of Russia is prohibited).
See also: