0

I need to override a paritcular javascript variable within Foundation 3.2.5 library. I need to do it in such a way I do not include the entire project just for this change.

The variable I am willing to override is in this particular file jquery.foundation.clearing.js

Snippet:

;(function ($, window, document, undefined) {
  'use strict';

  var defaults = {
        templates : {
          viewing : '<a href="#" class="clearing-close">&times;</a>' +
            '<div class="visible-img" style="display: none"><img src="#">' +
            '<p class="clearing-caption"></p><a href="#" class="clearing-main-left"></a>' +
            '<a href="#" class="clearing-main-right"></a></div>'
        },
        close_selectors : 'a.clearing-close',
        initialized : false,
        locked : false
      },

The full file is located here

The variable I want to override is defaults.templates.viewing. How to accomplish this smartly in Rails with minimal code change? I tried to create a foundaiton_override.js file but I don't know how to access the specific variable directly from there and override it.

bragboy
  • 34,892
  • 30
  • 114
  • 171
  • 1
    It's not possible to change the values in your given code snippet. The values are declared within literals, and not exposed to "the outside". After looking at your question's revision history, I've noticed that your question is a bit more specific. You cannot modify the values themselves, but you could try to modify the interpretation of the values by hooking the relevant functions in the library you're using. – Rob W Jan 16 '14 at 13:08
  • @RobW: I am trying to change the default value located in this file http://code.google.com/p/cdnjs/source/browse/ajax/libs/foundation/3.2.5/javascripts/jquery.foundation.clearing.js?spec=svnafd35b0324bbc81fc6b91df6f04a3becbbbe3b43&r=afd35b0324bbc81fc6b91df6f04a3becbbbe3b43 Can you please take a look at and let me know how it is possible via the exposed public method ? – bragboy Jan 16 '14 at 13:11
  • 1
    A quick look shows that you can override the default settings via the `cl.init` method, which in turn is exposed publicly via `$().foundationClearing`. – Rob W Jan 16 '14 at 13:15
  • Please remove the `;` from the beginning of the JS... So unnecessary... – Jeff Shaver Jan 16 '14 at 13:20
  • 3
    @JeffShaver The semicolon before a parenthesis is a not-so-uncommon pattern to ease concatenation of JavaScript files. It is not completely unnecessary, see http://stackoverflow.com/questions/7365172/semicolon-before-self-invoking-function – Rob W Jan 16 '14 at 13:22
  • 1
    @RobW I know what it is. It is unnecessary. If people would take care when concatenating files, we could avoid this ridiculous trend. Use semi-colons appropriately. – Jeff Shaver Jan 16 '14 at 13:30

1 Answers1

0

Solution found here

$(document).foundationClearing({
    templates: {
      viewing: ''
  }
});
bragboy
  • 34,892
  • 30
  • 114
  • 171