passing global variable to plugin

0 votes
asked Dec 9, 2015 by beau-michael

I'm trying to pass a global variable into a plugin. The global variable is content loaded from a separate page

 

This is my current code:

$( "#results" ).load( "/content.html");
var rawevents = document.getElementById("results").innerHTML;

 

I can log the rawevents variable in the console no dramas and the plain text comes back all fine

My problem is I need to get the plain text from this variable and shove it into the following:

 

<script type="text/javascript">
    $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,basicWeek,basicDay'
        },
        events: [{

            RESULTS HERE,

            title: 'Holder',
            start: "2015-12-12",
            allDay: true,
            }],
    });
</script>

 

If possible, it would also be awesome if it could strip all white spaces/minify the code when it passes it through - I'm not going to get cocky about it though!

Any help would be really, really appreciated. Cheers :)
- Beau

2 Answers

0 votes
answered Dec 9, 2015 by mike

I'm not sure if I'm understanding this correctly, but I'll give it a shot.. if rawevents is a global variable and it exists and is populated before you're trying to use the plugin, you should just be able to use the variable in the plugin.

Unless I'm just misunderstanding your question.

Even if rawevents is a local variable declared in the same scope as where you're initializing that calendar, it should still work.

0 votes
answered Dec 9, 2015 by dreamweiver
  • Pass the data to plugin like this

    $('#calendar').fullCalendar({
        plainText:rawEvents
    });
    
  • Then Retrieve the same in the plugin as

    //Jquery Plugin extension
    jQuery.fn['fullCalendar'] = function (options){ return calendarFunc($(this),options);};
    
    //private function        
    var calendarFunc= function ($container,options){
         //process and Render calendar 
    }
    

    For More Info on Jquery Plugin Creation

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...