Simple Javascript Joyride plugin in rails

前端 未结 3 779
你的背包
你的背包 2021-01-23 09:30

I\'m afraid my plugin isn\'t working properly because of a misunderstanding of rails. I\'m adding zurbs joyride plugin to an index page.

I have the following in v

相关标签:
3条回答
  • 2021-01-23 10:17

    Tmacram,

    I answered a similar question Here

    The original answer was correct about better organization of included files within Rails, but that wasn't causing your issue. The real reason this wasn't working is that Zurb's own instructions for setup are misleading. They say you can use whatever ID you want for your <ol> list that holds the steps of your guided tour, but you actually can't out of the box.

    Zurb's code for joyride is dependent upon a specific ID between the CSS/Javascript. This ID and the relevant code is located within the included joyride.css file. The ID used there is "joyRideTipContent." I've pasted the relevant couple lines of code from the joyride.css file (they're near the very top):

    #joyRideTipContent { display: none; }
    .joyRideTipContent { display: none; }
    

    If you would prefer to use a different ID, simply change the above code in the css file as follows and then it will work (I've included the name from your code snippet above):

    #list_index_tour{ display: none; }
    .list_index_tour{ display: none; }
    

    Alternatively, you could just change the ID and selector of your <ol> to be "joyRideTipContent" and it would work right out of the box.

    0 讨论(0)
  • 2021-01-23 10:21

    i have been having the same issue with joyride, i just got it working , just to complete what already said in my case

    first step : in the vendor/assets/javascripts i remove the js at the end of the file name and also in the application.js place the require file in the same order from the demo. and also require the css file

    second step : i create a partial that contain the code for the joyride place it in the folder that will contain the joyride views and render it in the layout/application.html.erb place after my footer

    3rd step: i convert the javascript in coffeescript with js2coffee.org exemple from the demo

    $(window).load(function() {
        $('#joyRideTipContent').joyride({
          autoStart : true,
          postStepCallback : function (index, tip) {
          if (index == 2) {
            $(this).joyride('set_li', false, 1);
          }
        },
        modal:true,
        expose: true
        });
      });
    

    to coffeescript:

     $(window).load ->
      $("#joyRideTipContent").joyride
        autoStart: true
        postStepCallback: (index, tip) ->
          $(this).joyride "set_li", false, 1  if index is 2
    
        modal: true
        expose: true
    

    so basically this is the step that i did and it works for me .

    P.s try not to put the file in another folder inside vendor/assets/javascripts , they are going to be compiled anyway.

    0 讨论(0)
  • 2021-01-23 10:32

    You could try to make a manifest file for this plugin. Create an index.js inside your subfolder and reference your assets.

    In your application.js you can have just:

    //= require joyride

    You can also try to drop the .js part in //= require joyride/modernizr.mq.js

    0 讨论(0)
提交回复
热议问题