### Configure SyntaxHighlighter for WireIt Guide Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/guide.html This JavaScript snippet configures the path to the clipboard SWF file for SyntaxHighlighter, which is used to display code examples within the WireIt guide. After setting the configuration, it initializes the highlighter for all code blocks on the page. ```JavaScript SyntaxHighlighter.config.clipboardSwf = 'res/SyntaxHighlighter/clipboard.swf';SyntaxHighlighter.all(); ``` -------------------------------- ### Example WireIt Wiring JSON Structure Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/guide.html Illustrates a fragment of the WireIt Wiring JSON format, specifically showing a wire definition with source and target terminals, and the 'properties' object containing metadata like name, description, and category for a wiring instance. ```JSON "src":{"moduleId":2,"terminal":"_OUTPUT"}, "tgt":{"moduleId":1,"terminal":"_INPUT2"} } ], "properties":{ "name":"demo", "description":"", "isTest":true, "category":"Demo" } }; ``` -------------------------------- ### JavaScript WireIt Layer and Form Container Setup Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/plugins/inputex/examples/index.html Demonstrates how to initialize a WireIt layer and configure two 'WireIt.FormContainer' instances. It defines various inputEx fields for user data and sets up a bezier wire connection between the 'email' terminal of the first container and a custom output terminal of the second, all within a YAHOO.util.Event.addListener onload function. ```JavaScript YAHOO.util.Event.addListener(window, 'load', function() { // Required for the tooltips YAHOO.inputEx.spacerUrl = "../lib/inputex/images/space.gif"; // Example 1 demoLayer = new WireIt.Layer({layerMap: false}); demoLayer.setWiring({ containers: [ { position:[380,240], xtype: "WireIt.FormContainer", collapsible: true, fields: [ {type: 'select', label: 'Title', name: 'title', selectValues: ['Mr','Mrs','Mme'] }, {label: 'Firstname', name: 'firstname', required: true }, {label: 'Lastname', name: 'lastname', value:'Dupont'}, {type:'email', label: 'Email', name: 'email', required: true, wirable: true }, {type:'boolean', label: 'Happy to be there ?', name: 'happy'}, {type:'url', label: 'Website', name:'website', size: 25} ], legend: 'Tell us about yourself...' }, { position:[145,80], xtype: "WireIt.FormContainer", collapsible: true, fields: [ {label: 'Firstname', name: 'firstname' }, {label: 'Lastname', name: 'lastname' }, {label: 'Title', name: 'title' } ], legend: 'Hello there', terminals: [ {direction: [0,1], offsetPosition: { bottom: -14, left: 160}, ddConfig: { type: "output", allowedTypes: ["input"] }, name: "_OUT1" } ] } ], wires: [ { src: { moduleId: 0, terminal: "email" }, tgt: { moduleId: 1, terminal: "_OUT1" }, xtype: "WireIt.BezierWire" } ] }); }); ``` -------------------------------- ### Comprehensive Wire Mouse Event Handling Example in JavaScript Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/guide.html A complete JavaScript example demonstrating how to define custom functions for wire mouse events (mouse in, mouse out, click), create a random layer with containers and wires, and then subscribe these functions to the mouse events for each wire. This example changes wire color on hover and shows an alert on click. ```JavaScript // Functions executed with the scope of a wire var wireRed = function() { this.options.color = 'rgb(255, 0, 0)'; this.redraw(); }, wireBlue = function() { this.options.color = 'rgb(173, 216, 230)'; this.redraw(); }, wireClick = function() { alert("Hoho ! you clicked !"); }; // Generate a random layer var layer = new WireIt.Layer({}); for(var i = 0 ; i < 5 ; i++) { layer.addContainer({ terminals: [ {direction: [0,1], offsetPosition: {bottom: -13, left: 25} }], title: "Block #"+i, position: [ Math.floor(Math.random()*800)+30, Math.floor(Math.random()*300)+30 ] }); } for(var i = 0 ; i < 7 ; i++) { var w = layer.addWire({ src: {moduleId: Math.floor(Math.random()*5), terminalId: 0}, tgt: {moduleId: Math.floor(Math.random()*5), terminalId: 0} }); // Subscribe methods to mouse events for all wires w.eventMouseIn.subscribe(wireRed, w, true); w.eventMouseOut.subscribe(wireBlue, w, true); w.eventMouseClick.subscribe(wireClick, w, true); } ``` -------------------------------- ### Configure WireIt Ajax Adapter Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/guide.html Configures the WireIt.WiringEditor.adapters.Ajax to connect to a custom backend using GET requests for saving, deleting, and listing wirings. Demonstrates both hard-coded URLs and dynamic URL functions. ```JavaScript WireIt.WiringEditor.adapters.Ajax.config = { saveWiring: { method: 'GET', // The url can be hard-coded url: 'fakeSaveDelete.json' }, deleteWiring: { method: 'GET', /** * 'url' can also be a function that returns the URL as a string. * For exemple, to connect to a REST store, you might want to send a DELETE /resource/wirings/moduleName * (moduleName is present in the "value" parameter) */ url: function(value) { return "fakeSaveDelete.json"; } }, listWirings: { method: 'GET', url: 'listWirings.json' } }; ``` -------------------------------- ### Example of Asynchronous Callback Invocation with YUI Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/guide.html Illustrates how to handle asynchronous operations, specifically an Ajax request using YUI, and then invoke the appropriate WireIt adapter callback (success or failure) based on the response. ```JavaScript function(val, callbacks) { YAHOO.util.Connect.asyncRequest('POST', 'myUrl', { success: function(r) { //... callbacks.success.call(callbacks.scope, results); }, failure: function(r) { callbacks.failure.call(callbacks.scope, error); } }); } ``` -------------------------------- ### Example of Synchronous Callback Invocation Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/guide.html Demonstrates how to synchronously invoke success or failure callbacks within a WireIt adapter method, passing results or errors to the specified scope. ```JavaScript function(val, callbacks) { if(everythingGoesFine) { callbacks.success.call(callbacks.scope, results); } else { callbacks.failure.call(callbacks.scope, results); } } ``` -------------------------------- ### Initialize WireIt Dynamic Graph with Spring Layout Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/plugins/layout/examples/spring_layout.html This JavaScript code initializes a WireIt layer, defines a set of nodes and their connections (wires), and then programmatically adds them to the layer. It positions containers randomly and then applies a dynamic layout algorithm to arrange them, simulating a spring model. The commented-out section shows an example of animating container positions. ```JavaScript var layer = null; window.onload = function() { var nodes = [ "WireIt", // 0 "librairies", "inputEx", "YUI", "excanvas", // 1, 2, 3, 4 "classes", "Wire", "Terminal", "Container", "Layer", "WiringEditor", // 5, 6, 7, 8, 9, 10 "modules", "editor", "inputex", "labels", "layout", "composable", "grouping" // 11, 12, 13, 14, 15,16,17 ]; var wires = [ [0,1], [1,2], [1,3], [2,3], [1,4], // librairies [0,5], [5,6], [5,7], [5,8], [5,9], [5,10], // classes [0, 11], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17] ]; layer = new WireIt.Layer({}); for(var i = 0 ; i < nodes.length ; i++) { layer.addContainer({ terminals: [ { offsetPosition: {top: 5, left: 25}, editable: false }], title: nodes[i], position: [ Math.floor(Math.random()*800)+30, Math.floor(Math.random()*300)+30 ], close: false }); } for(var i = 0 ; i < wires.length ; i++) { var wc = wires[i]; layer.addWire({ src: {moduleId: wc[0], terminalId: 0}, tgt: {moduleId: wc[1], terminalId: 0}, xtype: "WireIt.Wire" }); } layer.startDynamicLayout(); // For example with animation /*setInterval(function() { var c = layer.containers[0]; var anim = new WireIt.util.Anim( c.terminals, c.el, { left: {to: 500 }, top: {to: 200 } }, 1, YAHOO.util.Easing.easeOut); anim.animate(); layer.dynamicLayout.init(); }, 5000);*/ }; ``` -------------------------------- ### JavaScript WireIt Event Handling Example Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/examples/wire_events.html This JavaScript snippet initializes a WireIt layer upon window load, populating it with several containers and wires. It then attaches custom event handlers to each wire's mouse-in, mouse-out, and click events, demonstrating how to change wire appearance and trigger actions based on user interaction. ```JavaScript window.onload = function() { // Functions executed with the scope of a wire var wireRed = function() { this.color = 'rgb(255, 0, 0)'; this.redraw(); }, wireBlue = function() { this.color = 'rgb(173, 216, 230)'; this.redraw(); }, wireClick = function() { alert("Hoho ! you clicked !"); }; // Generate a random layer var layer = new WireIt.Layer({}); for(var i = 0 ; i < 5 ; i++) { layer.addContainer({ terminals: [ {direction: [0,1], offsetPosition: {bottom: -13, left: 25} } ], title: "Block #"+i, position: [ Math.floor(Math.random()*800)+30, Math.floor(Math.random()*300)+30 ] }); } for(var i = 0 ; i < 7 ; i++) { var w = layer.addWire({ src: {moduleId: Math.floor(Math.random()*5), terminalId: 0}, tgt: {moduleId: Math.floor(Math.random()*5), terminalId: 0} }); // Subscribe methods to mouse events for all wires w.eventMouseIn.subscribe(wireRed, w, true); w.eventMouseOut.subscribe(wireBlue, w, true); w.eventMouseClick.subscribe(wireClick, w, true); } }; ``` -------------------------------- ### Create Basic inputEx SelectField Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/plugins/inputex/lib/inputex/examples/select_field.html Demonstrates how to initialize a simple inputEx SelectField with a list of choices. This example uses a shorthand syntax for defining choices, where the value is directly provided. ```JavaScript new inputEx.SelectField({ name: 'country', choices: [ { value: 'United States of America' }, { value: 'France' } ], parentEl: 'container1' }); ``` -------------------------------- ### Configure WiringEditor Autoload with URL Parameter Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/guide.html Demonstrates how to use the 'autoload' URL parameter to specify which wiring should be opened automatically when the WiringEditor is displayed. This allows for direct links to specific wiring configurations. ```URL http://myhost.com/editor/?autoload=myWiring ``` -------------------------------- ### Initialize inputEx Dialogs and Load Dependencies with YUI Loader Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/plugins/inputex/lib/inputex/examples/dialog_widget.html This comprehensive JavaScript function demonstrates the full initialization process for inputEx dialogs within a YUI environment. It sets up both the basic and modal dialog examples, configures the inputEx spacer URL, and utilizes `YAHOO.util.YUILoader` to asynchronously load required inputEx and YUI modules. It also shows how to declare inputEx modules to YUI for proper dependency management. ```JavaScript /** * The function to call when all script/css resources have been loaded */ function init() { // Required for the UrlField inputEx.spacerUrl = "../images/space.gif"; // Example 1 Example1 = {}; var formConfig = { type: 'form', fields: [ {type: 'select', label: 'Title', name: 'title', choices: ['Mr', 'Mrs', 'Ms'] }, {label: 'Firstname', name: 'firstname', required: true, value:'Jacques' }, {label: 'Lastname', name: 'lastname', value:'Dupont' }, {type:'email', label: 'Email', name: 'email'}, {type:'url', label: 'Website',name:'website'} ], buttons: [ {type: 'submit', value: 'Send', onClick: function() { alert(YAHOO.lang.JSON.stringify(Example1.myPanel.getForm().getValue())); return false; // prevent form submit }}, {type: 'link', value: 'Cancel', onClick: function() { Example1.myPanel.hide(); } } ] }; Example1.myPanel = new inputEx.widget.Dialog({ inputExDef: formConfig, title: 'Here the title of your dialog' }); // Example 2 Example2 = {}; Example2.myPanel = new inputEx.widget.Dialog({ inputExDef: { type: 'form', fields: [ {type:'string', label: 'Name', name: 'firstname', required: true }, {type:'email', label: 'Email', name: 'email', description: 'Won\'t be displayed...'}, {type:'url', label: 'Website',name:'website', typeInvite: '(optional)'}, {type:'text', label: 'Your comment',name:'comments'} ], buttons: [ {type: 'submit', value: 'Send', onClick: function() { alert(YAHOO.lang.JSON.stringify(Example2.myPanel.getForm().getValue())); return false; // prevent form submit }}, {type: 'link', value: 'Cancel', onClick: function() { Example2.myPanel.hide(); } } ] }, title: 'Please post a comment !', panelConfig: { constraintoviewport: true, underlay:"shadow", close:true, fixedcenter: true, visible:false, draggable:true, modal: true } }); }; var loader = new YAHOO.util.YUILoader({ require: ["inputex-emailfield", "inputex-urlfield", "inputex-selectfield", "inputex-form", "inputex-dialog", "inputex-textarea", "json"], loadOptional: true, onSuccess: init }); /** * Important: this functions declares all inputEx Modules to YUI */ YAHOO.addInputExModules(loader, '../'); loader.insert(); dp.SyntaxHighlighter.HighlightAll('code'); ``` -------------------------------- ### WireIt Sample Manager and Initialization Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/examples/presentation.html This JavaScript code defines the `SampleMgr` object, which orchestrates the interactive WireIt presentation. It manages the current sample index, loads and unloads samples, updates the display, and provides navigation functions. The `window.onload` event ensures the presentation initializes automatically when the page loads. ```JavaScript var SampleMgr = { sampleIndex: 0, init: function() { this.container = YAHOO.util.Dom.get('container'); this.next(); }, previous: function() { this.sampleIndex = Math.max(this.sampleIndex-2,0); this.next(); }, next: function() { if(!YAHOO.lang.isUndefined(this.lastLoaded) && YAHOO.lang.isFunction(WireIt.samples[this.lastLoaded].unload) ) { WireIt.samples[this.lastLoaded].unload(); } if(this.sampleIndex == WireIt.samples.length) return; this.container.innerHTML = WireIt.samples[this.sampleIndex].innerHTML; this.lastLoaded = this.sampleIndex; WireIt.samples[this.sampleIndex].init(); this.sampleIndex += 1; } }; window.onload = function() { SampleMgr.init(); }; ``` -------------------------------- ### WireIt Custom Adapter Skeleton Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/guide.html Provides a template for creating a custom WireIt.WiringEditor adapter. It includes a config object, an init method, and asynchronous methods (saveWiring, deleteWiring, listWirings) that use callbacks. ```JavaScript WireIt.WiringEditor.adapters.MyAdapter = { // adapter default options config: { // ... }, // Initialization method called by the WiringEditor init: function() { }, /** * save/list/delete asynchronous methods */ saveWiring: function(val, callbacks) { // ... // don't forget to call the callbacks ! }, deleteWiring: function(val, callbacks) { // ... // don't forget to call the callbacks ! }, listWirings: function(val, callbacks) { // ... // don't forget to call the callbacks ! } // + private methods or properties }; ``` -------------------------------- ### JavaScript Configuration and Editor Initialization Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/plugins/editor/examples/WiringEditor/index.html This JavaScript snippet configures the `inputEx` library's spacer image URL and initializes the `WireIt.WiringEditor` once the DOM is ready. It creates an instance of the editor using a `demoLanguage` definition and attempts to open a specific panel in the editor's accordion view, with basic error handling for robustness. ```JavaScript inputEx.spacerUrl = "/inputex/trunk/images/space.gif"; YAHOO.util.Event.onDOMReady( function() { try { var editor = new WireIt.WiringEditor(demoLanguage); // Open the infos panel editor.accordionView.openPanel(2); } catch(ex) { console.log(ex); } }); ``` -------------------------------- ### Set and Get Value for inputEx RTEField Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/plugins/inputex/lib/inputex/examples/rte_field.html Illustrates how to programmatically set and retrieve the content of an inputEx RTEField using its `setValue` and `getValue` methods. The example includes event listeners for buttons to trigger these actions, demonstrating dynamic content manipulation. ```JavaScript var div = YAHOO.util.Dom.get('container2'); var htmlField = new inputEx.RTEField({parentEl: div, name: 'test2'}); var button1 = inputEx.cn('button', null, null, "SetValue"); div.appendChild(button1); YAHOO.util.Event.addListener(button1, "click" ,function() { htmlField.setValue('RTEField can contain HTML !'); }); var button2 = inputEx.cn('button', null, null, "GetValue"); div.appendChild(button2); YAHOO.util.Event.addListener(button2, "click" ,function() { alert(htmlField.getValue()); }); ``` -------------------------------- ### Creating a Custom LogicContainer by Extending WireIt.ImageContainer Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/guide.html Illustrates the creation of a `LogicContainer` class, which inherits from `WireIt.ImageContainer`. This example demonstrates how to initialize a custom property (`logicInputValues`) and correctly set the `xtype` for a specialized container used in applications like interactive logic circuits. ```JavaScript LogicContainer = function(opts, layer) { LogicContainer.superclass.constructor.call(this, opts, layer); this.logicInputValues = []; }; YAHOO.lang.extend(LogicContainer, WireIt.ImageContainer, { setOptions: function(options) { LogicContainer.superclass.setOptions.call(this, options); this.options.xtype = "LogicContainer"; } }); ``` -------------------------------- ### WireIt Layer Initialization and Wiring Configuration Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/examples/label_editor.html This JavaScript snippet initializes a WireIt.Layer instance and uses its `setWiring` method to define two `WireIt.ImageContainer` modules and a `WireIt.BezierWire` connection between them. It also includes basic CSS for the demo layout, styling the containers and body. ```CSS body { font-size: 10px; } div.WireIt-Container { width: 350px; /* Prevent the modules from scratching on the right */ } div.WireIt-ImageContainer { width: auto; } div.Bubble div.body { width: 70px; height: 45px; opacity: 0.8; /*cursor: move;*/ } ``` ```JavaScript var demoLayer; YAHOO.util.Event.addListener(window, 'load', function() { // Layer Demo demoLayer = new WireIt.Layer({layerMap: false}); // You can use a global setWiring method demoLayer.setWiring({ containers: [ // ImageContainer { position:[600,240], "xtype":"WireIt.ImageContainer", "image": "bubble.png", //draggable: false, close: false, "terminals": [ {"name": "_INPUT1", direction: [-1,-1], offsetPosition: [-10,-10], editable: false}, {direction: [1,-1], offsetPosition: [25,-10]}, {direction: [-1,1], offsetPosition: [-10,25]}, {direction: [1,1], offsetPosition: [25,25]} ] }, // ImageContainer { position:[700,140], "xtype":"WireIt.ImageContainer", className: "WireIt-Container WireIt-ImageContainer Bubble", "image": "bubble.png", //draggable: false, close: false, "terminals": [ {"name": "_INPUT1", direction: [-1,-1], offsetPosition: [-10,-10], editable: false}, {direction: [1,-1], offsetPosition: [25,-10]}, {direction: [-1,1], offsetPosition: [-10,25]}, {direction: [1,1], offsetPosition: [25,25]} ] } ], wires: [ { src: { moduleId: 0, terminal: "_INPUT1" }, tgt: { moduleId: 1, terminal: "_INPUT1" }, label: 'Ouf !!', labelEditor: {type: 'string', value: "Testst"}, xtype: "WireIt.BezierWire" } ] }); }); ``` -------------------------------- ### WireIt Layer and Event Handling Initialization Source: https://github.com/vaibhavbansal/spiffworkflow/blob/master/wireit-editor/wireit/examples/wire_tooltips.html Initializes a WireIt layer and sets up the core functionality for handling wire events and displaying interactive UI elements. This includes creating a dynamic tooltip with close functionality, defining event handlers for wire interactions (click, mouse-in, mouse-out), and programmatically generating containers and wires with subscribed events. ```JavaScript window.onload = function() { var layer = new WireIt.Layer({}); // The wire tooltip var wireInfos = WireIt.cn('div', {className: 'wireInfos'}, {display: 'none'}, "
"); layer.el.appendChild(wireInfos); // method to close the tooltip var closeWireInfos = function(e) { YAHOO.util.Event.stopEvent(e); wireInfos.style.display = "none"; }; // close button var wireClose = WireIt.cn('div', {className: "WireIt-Container-closebutton"}); wireInfos.appendChild(wireClose); YAHOO.util.Event.addListener(wireClose, 'click', closeWireInfos); // Generate the tooltip contents YAHOO.util.Event.onAvailable('wireTooltip', function() { var el = YAHOO.util.Dom.get('wireTooltip'); el.innerHTML = "Wires properties :