0

Need to access a method from another page. Seems like there should be something like $("#selectedClip").setValue(4,4);

(function($) {
$.fn.extend({
    spinit: function(options) {
        var settings = $.extend({ min: 0, max: 100, initValue: 0, callback: null, stepInc: 1, pageInc: 10, width: 50, height: 15, btnWidth: 10, mask: '' }, options);
        return this.each(function() {
            var UP = 38;
            var DOWN = 40;
            var PAGEUP = 33;
            var PAGEDOWN = 34;
            var mouseCaptured = false;
            var mouseIn = false;
            var interval;

........

function setValue(a, b) {
                if (a >= settings.min && a <= settings.max) {
                    value = b;
                    //this is for editVideo php. Probably will break code in other page
                    spinnerChange(value);
                } el.val(value);
            }

above is the method I need to call outside of this file. Help!! :)

Brayden Hancock
  • 736
  • 1
  • 5
  • 21
  • are you trying to access the `settings` that are within `spinit` ? They don't have public access scope from outside of `spinit` function. The spinit function would need to be modified to either make these values accessible by public function or stored into another global object or jQuery data on an element – charlietfl Oct 16 '12 at 00:38
  • alright that makes sense. I'm not having trouble with the settings. I just need to change the variable "value" within spinit: function. How do I make it public? I've tried adding the public tag on the function but that didn't seem to work. Tried to make the variable value global but couldn't get that to work. And theirs no way of making a get function? Thanks a ton for the help. – Brayden Hancock Oct 16 '12 at 19:10
  • when you call the plugin you pass it as an option in the options object assuming that the plugin is set up to accept the option you want to change ( one of the ones in $.extend) – charlietfl Oct 16 '12 at 23:16
  • Heres how I set it up. This works just fine. Now I need to call the setValue function. 'code'$(document).ready(function() { $('#selectedClip').spinit({ min : 1, max : 50, stepInc : 1, pageInc : 20, height : 19, mask : '' }); }); – Brayden Hancock Oct 17 '12 at 16:15
  • does the API for plugin have a `setValue` method? If not the plugin would need modifying and there isn't enough info here to do that – charlietfl Oct 17 '12 at 22:59
  • all there is is that setValue function under spinit. There's no way to add to the code to get that value outside? Or even send the value on change to a variable outside? – Brayden Hancock Oct 18 '12 at 17:18
  • yes can be added, requires rewrite parts of plugin. WOuld need to add a public method parser as well as activate whatever you are passing into it. There isn't enough code shown to do that, and would require testing. Look for another plugin with better API – charlietfl Oct 18 '12 at 18:41

1 Answers1

0

You have several alternatives to do this, but basically you have to isolate your common code (the setValue function) in a separate javascript file (let's name it common.js), then you can do any of the following:

  • The difficult-to-maintain solution of always including the common.js in all your html files
  • Use jquery.getScript method to load common.js, This answer here shows a great example of how to load TinyMCE if not already loaded
  • Maybe you can use this plugin (I haven't tested it before).

Personally, I'd recommend jquery.getScript method.

Community
  • 1
  • 1
Hisham
  • 422
  • 3
  • 7