How to get an onclick element to work with requirejs modules









up vote
0
down vote

favorite












I am working on a project that is using requirejs, and html. I have an HTML element that has an onclick event:



<li><a href="#" onclick="filesystem.newFloorplan()">New <p class="shortcut">(Ctrl + D)</p></a></li>


When this is clicked, its not working. Here is the main file that is invoking the code:



define(function (require) {
"use strict";

var $ = require('jquery'),
go = require('goJS');

require('bootstrap');
require('jqueryUI');
require('floorWarmingDesignTool-Floorplan');

if ($("#floorWarmingDesignTool").length === 0)
return;


function init()
require(['floorWarmingDesignTool-Floorplan'], function (fp, FloorplanFilesystem)
// Floorplan
var myFloorplan = new fp.Floorplan("myFloorplanDiv");

// Filesystem
var filesyestem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
//var ui = new fp.FloorplanUI(myFloorplan, "ui", "myFloorplan", fp.GUI_STATE);

// Palettes - Node Data Arrays
var furniturePalette = new fp.FloorplanPalette("furniturePaletteDiv", myFloorplan, fp.FURNITURE_NODE_DATA_ARRAY);
var wallPartsPalette = new fp.FloorplanPalette("wallPartsPaletteDiv", myFloorplan, fp.WALLPARTS_NODE_DATA_ARRAY);

// Enable Hotkeys
var body = document.getElementById('floorWarmingDesignTool');
body.addEventListener("keydown", function (e)
var keynum = e.which;
if (e.ctrlKey)
e.preventDefault();
switch (keynum)
case 83: filesystem.saveFloorplan(); // ctrl + s
break;
case 79: filesystem.showOpenWindow(); // ctrl + o
break;
case 68: e.preventDefault(); filesystem.newFloorplan(); // ctrl + d
break;
case 82: filesystem.showRemoveWindow(); // ctrl + r
break;
case 49: ui.setBehavior('wallBuilding', myFloorplan); // ctrl + 1
break;
case 50: ui.setBehavior('dragging', myFloorplan); // ctrl + 2
break;
case 72: ui.hideShow('diagramHelpDiv'); // ctrl + h
break;
case 73: ui.hideShow('selectionInfoWindow'); // ctrl + i
break;
case 80: ui.hideShow('myPaletteWindow'); // ctrl + p
break;
case 69: ui.hideShow('myOverviewWindow'); // ctrl + e
break;
case 66: ui.hideShow('optionsWindow'); // ctrl + b
break;
case 71: ui.hideShow('statisticsWindow'); // ctrl + g
break;

);

// Default Model Data
myFloorplan.floorplanFilesystem.loadFloorplanFromModel(fp.DEFAULT_MODEL_DATA);

// See all exposed Floorplan classes
console.log(fp);
);


init();

console.log("Floor Warming Design Tool - Ready!");


);



Here is the snippet of code that is from another module:



define(function (require, exports) 
"use strict";

Object.defineProperty(exports, "__esModule",
value: true
);

var $ = require('jquery'),
go = require('goJS');

if ($("#floorWarmingDesignTool").length === 0)
return;


/*
* Instance methods
* New Floorplan, Save Floorplan, Save Floorplan As, Load Floorplan, Remove Floorplan
* Show Open Window, Show Remove Window
* Set Current File Name, Get Current File Name
*/

// Create new floorplan (Ctrl + D or File -> New)
FloorplanFilesystem.prototype.newFloorplan = function ()
var floorplan = this.floorplan;
// checks to see if all changes have been saved
if (floorplan.isModified)
var save = confirm("Would you like to save changes to " + this.getCurrentFileName() + "?");
if (save)
this.saveFloorplan();


this.setCurrentFileName(this.UNSAVED_FILENAME);
// loads an empty diagram
var model = new go.GraphLinksModel;
// initialize all modelData
model.modelData = this.DEFAULT_MODELDATA;
floorplan.model = model;
floorplan.undoManager.isEnabled = true;
floorplan.isModified = false;
if (floorplan.floorplanUI)
floorplan.floorplanUI.updateUI();
floorplan.floorplanUI.updateStatistics();



exports.FloorplanFilesystem = FloorplanFilesystem;

);


How do I get this onclick to work?



Thank You advance-










share|improve this question



























    up vote
    0
    down vote

    favorite












    I am working on a project that is using requirejs, and html. I have an HTML element that has an onclick event:



    <li><a href="#" onclick="filesystem.newFloorplan()">New <p class="shortcut">(Ctrl + D)</p></a></li>


    When this is clicked, its not working. Here is the main file that is invoking the code:



    define(function (require) {
    "use strict";

    var $ = require('jquery'),
    go = require('goJS');

    require('bootstrap');
    require('jqueryUI');
    require('floorWarmingDesignTool-Floorplan');

    if ($("#floorWarmingDesignTool").length === 0)
    return;


    function init()
    require(['floorWarmingDesignTool-Floorplan'], function (fp, FloorplanFilesystem)
    // Floorplan
    var myFloorplan = new fp.Floorplan("myFloorplanDiv");

    // Filesystem
    var filesyestem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
    //var ui = new fp.FloorplanUI(myFloorplan, "ui", "myFloorplan", fp.GUI_STATE);

    // Palettes - Node Data Arrays
    var furniturePalette = new fp.FloorplanPalette("furniturePaletteDiv", myFloorplan, fp.FURNITURE_NODE_DATA_ARRAY);
    var wallPartsPalette = new fp.FloorplanPalette("wallPartsPaletteDiv", myFloorplan, fp.WALLPARTS_NODE_DATA_ARRAY);

    // Enable Hotkeys
    var body = document.getElementById('floorWarmingDesignTool');
    body.addEventListener("keydown", function (e)
    var keynum = e.which;
    if (e.ctrlKey)
    e.preventDefault();
    switch (keynum)
    case 83: filesystem.saveFloorplan(); // ctrl + s
    break;
    case 79: filesystem.showOpenWindow(); // ctrl + o
    break;
    case 68: e.preventDefault(); filesystem.newFloorplan(); // ctrl + d
    break;
    case 82: filesystem.showRemoveWindow(); // ctrl + r
    break;
    case 49: ui.setBehavior('wallBuilding', myFloorplan); // ctrl + 1
    break;
    case 50: ui.setBehavior('dragging', myFloorplan); // ctrl + 2
    break;
    case 72: ui.hideShow('diagramHelpDiv'); // ctrl + h
    break;
    case 73: ui.hideShow('selectionInfoWindow'); // ctrl + i
    break;
    case 80: ui.hideShow('myPaletteWindow'); // ctrl + p
    break;
    case 69: ui.hideShow('myOverviewWindow'); // ctrl + e
    break;
    case 66: ui.hideShow('optionsWindow'); // ctrl + b
    break;
    case 71: ui.hideShow('statisticsWindow'); // ctrl + g
    break;

    );

    // Default Model Data
    myFloorplan.floorplanFilesystem.loadFloorplanFromModel(fp.DEFAULT_MODEL_DATA);

    // See all exposed Floorplan classes
    console.log(fp);
    );


    init();

    console.log("Floor Warming Design Tool - Ready!");


    );



    Here is the snippet of code that is from another module:



    define(function (require, exports) 
    "use strict";

    Object.defineProperty(exports, "__esModule",
    value: true
    );

    var $ = require('jquery'),
    go = require('goJS');

    if ($("#floorWarmingDesignTool").length === 0)
    return;


    /*
    * Instance methods
    * New Floorplan, Save Floorplan, Save Floorplan As, Load Floorplan, Remove Floorplan
    * Show Open Window, Show Remove Window
    * Set Current File Name, Get Current File Name
    */

    // Create new floorplan (Ctrl + D or File -> New)
    FloorplanFilesystem.prototype.newFloorplan = function ()
    var floorplan = this.floorplan;
    // checks to see if all changes have been saved
    if (floorplan.isModified)
    var save = confirm("Would you like to save changes to " + this.getCurrentFileName() + "?");
    if (save)
    this.saveFloorplan();


    this.setCurrentFileName(this.UNSAVED_FILENAME);
    // loads an empty diagram
    var model = new go.GraphLinksModel;
    // initialize all modelData
    model.modelData = this.DEFAULT_MODELDATA;
    floorplan.model = model;
    floorplan.undoManager.isEnabled = true;
    floorplan.isModified = false;
    if (floorplan.floorplanUI)
    floorplan.floorplanUI.updateUI();
    floorplan.floorplanUI.updateStatistics();



    exports.FloorplanFilesystem = FloorplanFilesystem;

    );


    How do I get this onclick to work?



    Thank You advance-










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am working on a project that is using requirejs, and html. I have an HTML element that has an onclick event:



      <li><a href="#" onclick="filesystem.newFloorplan()">New <p class="shortcut">(Ctrl + D)</p></a></li>


      When this is clicked, its not working. Here is the main file that is invoking the code:



      define(function (require) {
      "use strict";

      var $ = require('jquery'),
      go = require('goJS');

      require('bootstrap');
      require('jqueryUI');
      require('floorWarmingDesignTool-Floorplan');

      if ($("#floorWarmingDesignTool").length === 0)
      return;


      function init()
      require(['floorWarmingDesignTool-Floorplan'], function (fp, FloorplanFilesystem)
      // Floorplan
      var myFloorplan = new fp.Floorplan("myFloorplanDiv");

      // Filesystem
      var filesyestem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
      //var ui = new fp.FloorplanUI(myFloorplan, "ui", "myFloorplan", fp.GUI_STATE);

      // Palettes - Node Data Arrays
      var furniturePalette = new fp.FloorplanPalette("furniturePaletteDiv", myFloorplan, fp.FURNITURE_NODE_DATA_ARRAY);
      var wallPartsPalette = new fp.FloorplanPalette("wallPartsPaletteDiv", myFloorplan, fp.WALLPARTS_NODE_DATA_ARRAY);

      // Enable Hotkeys
      var body = document.getElementById('floorWarmingDesignTool');
      body.addEventListener("keydown", function (e)
      var keynum = e.which;
      if (e.ctrlKey)
      e.preventDefault();
      switch (keynum)
      case 83: filesystem.saveFloorplan(); // ctrl + s
      break;
      case 79: filesystem.showOpenWindow(); // ctrl + o
      break;
      case 68: e.preventDefault(); filesystem.newFloorplan(); // ctrl + d
      break;
      case 82: filesystem.showRemoveWindow(); // ctrl + r
      break;
      case 49: ui.setBehavior('wallBuilding', myFloorplan); // ctrl + 1
      break;
      case 50: ui.setBehavior('dragging', myFloorplan); // ctrl + 2
      break;
      case 72: ui.hideShow('diagramHelpDiv'); // ctrl + h
      break;
      case 73: ui.hideShow('selectionInfoWindow'); // ctrl + i
      break;
      case 80: ui.hideShow('myPaletteWindow'); // ctrl + p
      break;
      case 69: ui.hideShow('myOverviewWindow'); // ctrl + e
      break;
      case 66: ui.hideShow('optionsWindow'); // ctrl + b
      break;
      case 71: ui.hideShow('statisticsWindow'); // ctrl + g
      break;

      );

      // Default Model Data
      myFloorplan.floorplanFilesystem.loadFloorplanFromModel(fp.DEFAULT_MODEL_DATA);

      // See all exposed Floorplan classes
      console.log(fp);
      );


      init();

      console.log("Floor Warming Design Tool - Ready!");


      );



      Here is the snippet of code that is from another module:



      define(function (require, exports) 
      "use strict";

      Object.defineProperty(exports, "__esModule",
      value: true
      );

      var $ = require('jquery'),
      go = require('goJS');

      if ($("#floorWarmingDesignTool").length === 0)
      return;


      /*
      * Instance methods
      * New Floorplan, Save Floorplan, Save Floorplan As, Load Floorplan, Remove Floorplan
      * Show Open Window, Show Remove Window
      * Set Current File Name, Get Current File Name
      */

      // Create new floorplan (Ctrl + D or File -> New)
      FloorplanFilesystem.prototype.newFloorplan = function ()
      var floorplan = this.floorplan;
      // checks to see if all changes have been saved
      if (floorplan.isModified)
      var save = confirm("Would you like to save changes to " + this.getCurrentFileName() + "?");
      if (save)
      this.saveFloorplan();


      this.setCurrentFileName(this.UNSAVED_FILENAME);
      // loads an empty diagram
      var model = new go.GraphLinksModel;
      // initialize all modelData
      model.modelData = this.DEFAULT_MODELDATA;
      floorplan.model = model;
      floorplan.undoManager.isEnabled = true;
      floorplan.isModified = false;
      if (floorplan.floorplanUI)
      floorplan.floorplanUI.updateUI();
      floorplan.floorplanUI.updateStatistics();



      exports.FloorplanFilesystem = FloorplanFilesystem;

      );


      How do I get this onclick to work?



      Thank You advance-










      share|improve this question















      I am working on a project that is using requirejs, and html. I have an HTML element that has an onclick event:



      <li><a href="#" onclick="filesystem.newFloorplan()">New <p class="shortcut">(Ctrl + D)</p></a></li>


      When this is clicked, its not working. Here is the main file that is invoking the code:



      define(function (require) {
      "use strict";

      var $ = require('jquery'),
      go = require('goJS');

      require('bootstrap');
      require('jqueryUI');
      require('floorWarmingDesignTool-Floorplan');

      if ($("#floorWarmingDesignTool").length === 0)
      return;


      function init()
      require(['floorWarmingDesignTool-Floorplan'], function (fp, FloorplanFilesystem)
      // Floorplan
      var myFloorplan = new fp.Floorplan("myFloorplanDiv");

      // Filesystem
      var filesyestem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
      //var ui = new fp.FloorplanUI(myFloorplan, "ui", "myFloorplan", fp.GUI_STATE);

      // Palettes - Node Data Arrays
      var furniturePalette = new fp.FloorplanPalette("furniturePaletteDiv", myFloorplan, fp.FURNITURE_NODE_DATA_ARRAY);
      var wallPartsPalette = new fp.FloorplanPalette("wallPartsPaletteDiv", myFloorplan, fp.WALLPARTS_NODE_DATA_ARRAY);

      // Enable Hotkeys
      var body = document.getElementById('floorWarmingDesignTool');
      body.addEventListener("keydown", function (e)
      var keynum = e.which;
      if (e.ctrlKey)
      e.preventDefault();
      switch (keynum)
      case 83: filesystem.saveFloorplan(); // ctrl + s
      break;
      case 79: filesystem.showOpenWindow(); // ctrl + o
      break;
      case 68: e.preventDefault(); filesystem.newFloorplan(); // ctrl + d
      break;
      case 82: filesystem.showRemoveWindow(); // ctrl + r
      break;
      case 49: ui.setBehavior('wallBuilding', myFloorplan); // ctrl + 1
      break;
      case 50: ui.setBehavior('dragging', myFloorplan); // ctrl + 2
      break;
      case 72: ui.hideShow('diagramHelpDiv'); // ctrl + h
      break;
      case 73: ui.hideShow('selectionInfoWindow'); // ctrl + i
      break;
      case 80: ui.hideShow('myPaletteWindow'); // ctrl + p
      break;
      case 69: ui.hideShow('myOverviewWindow'); // ctrl + e
      break;
      case 66: ui.hideShow('optionsWindow'); // ctrl + b
      break;
      case 71: ui.hideShow('statisticsWindow'); // ctrl + g
      break;

      );

      // Default Model Data
      myFloorplan.floorplanFilesystem.loadFloorplanFromModel(fp.DEFAULT_MODEL_DATA);

      // See all exposed Floorplan classes
      console.log(fp);
      );


      init();

      console.log("Floor Warming Design Tool - Ready!");


      );



      Here is the snippet of code that is from another module:



      define(function (require, exports) 
      "use strict";

      Object.defineProperty(exports, "__esModule",
      value: true
      );

      var $ = require('jquery'),
      go = require('goJS');

      if ($("#floorWarmingDesignTool").length === 0)
      return;


      /*
      * Instance methods
      * New Floorplan, Save Floorplan, Save Floorplan As, Load Floorplan, Remove Floorplan
      * Show Open Window, Show Remove Window
      * Set Current File Name, Get Current File Name
      */

      // Create new floorplan (Ctrl + D or File -> New)
      FloorplanFilesystem.prototype.newFloorplan = function ()
      var floorplan = this.floorplan;
      // checks to see if all changes have been saved
      if (floorplan.isModified)
      var save = confirm("Would you like to save changes to " + this.getCurrentFileName() + "?");
      if (save)
      this.saveFloorplan();


      this.setCurrentFileName(this.UNSAVED_FILENAME);
      // loads an empty diagram
      var model = new go.GraphLinksModel;
      // initialize all modelData
      model.modelData = this.DEFAULT_MODELDATA;
      floorplan.model = model;
      floorplan.undoManager.isEnabled = true;
      floorplan.isModified = false;
      if (floorplan.floorplanUI)
      floorplan.floorplanUI.updateUI();
      floorplan.floorplanUI.updateStatistics();



      exports.FloorplanFilesystem = FloorplanFilesystem;

      );


      How do I get this onclick to work?



      Thank You advance-







      javascript html requirejs prototype






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 21:13

























      asked Nov 9 at 20:31









      Jon Nowak

      5419




      5419






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          First set the Id of the tag.



          Then:



          function init() 
          require(['floorWarmingDesignTool-Floorplan'], function (fp)
          var newAnchor = document.getElementById("id");
          newAnchor.onclick = function()
          fp.filesystem.newFloorplan();

          );







          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232883%2fhow-to-get-an-onclick-element-to-work-with-requirejs-modules%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            First set the Id of the tag.



            Then:



            function init() 
            require(['floorWarmingDesignTool-Floorplan'], function (fp)
            var newAnchor = document.getElementById("id");
            newAnchor.onclick = function()
            fp.filesystem.newFloorplan();

            );







            share|improve this answer
























              up vote
              0
              down vote



              accepted










              First set the Id of the tag.



              Then:



              function init() 
              require(['floorWarmingDesignTool-Floorplan'], function (fp)
              var newAnchor = document.getElementById("id");
              newAnchor.onclick = function()
              fp.filesystem.newFloorplan();

              );







              share|improve this answer






















                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                First set the Id of the tag.



                Then:



                function init() 
                require(['floorWarmingDesignTool-Floorplan'], function (fp)
                var newAnchor = document.getElementById("id");
                newAnchor.onclick = function()
                fp.filesystem.newFloorplan();

                );







                share|improve this answer












                First set the Id of the tag.



                Then:



                function init() 
                require(['floorWarmingDesignTool-Floorplan'], function (fp)
                var newAnchor = document.getElementById("id");
                newAnchor.onclick = function()
                fp.filesystem.newFloorplan();

                );








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 at 14:42









                Jon Nowak

                5419




                5419



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232883%2fhow-to-get-an-onclick-element-to-work-with-requirejs-modules%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo