Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the following script in my cms page:

window.addEvent('domready', function () {

    SqueezeBox.initialize({});
    SqueezeBox.assign($$('a.modal'), {
        parse: 'rel'
    });
});

var j2storeURL = 'http://tours-international.com.gridhosted.co.uk/';

if (typeof (J2Store) == 'undefined') {
    var J2Store = jQuery.noConflict();
}


J2Store(document).ready(function () {
    J2Store('.j2storeCartForm').each(function () {
        J2Store(this).validate({
            errorElement: 'em',
            errorPlacement: function (error, element) {
                error.appendTo(element.parent().parent().next('div'));
            },
            success: function (label) {
                //label.text('Ok').addClass('success');
            },
            submitHandler: function (form) {

                j2storeAddToCart('addtocart', form);

            }
        });
    });
});

jQuery(document).ready(function () {
    jQuery('.hasTooltip').tooltip({});
});

I want to loop through the above and remove the following JS:

SqueezeBox.initialize({});

SqueezeBox.assign($$('a.modal'), {
    parse: 'rel'
});

Please advise easiest/smallest way to do this.

share|improve this question
add comment

1 Answer

If I understood the question correctly, you want to remove that part from a file???

If yes, then you can do the following:

  1. Read the file into string $file_str = file_get_contents('your_file_path');
  2. Get the positions: $pos_a = strpos($file_str, "SqueezeBox") and $pos_b = strpos($file_str, "var")
  3. Write this back: substr_replace($file_str, "", $pos_a, ($pos_b - $pos_a));

Good luck

share|improve this answer
    
Well, sort of - this is Joomla, so a plugin is injecting the SqueezeBox part into & building that script... so I need a bit of php to remove just the SqueezeBox bit, after it has been created –  user991830 Jun 15 '13 at 8:38
    
there is not an actual file, the javascript is being built & input into my template - so I want to add something to my template to remove that part –  user991830 Jun 15 '13 at 8:40
    
when you say "i wanna loop through", what do you mean. How do you exactly access this code...from where??? –  Brian Jun 15 '13 at 8:43
    
in my joomla template I have <jdoc:include type="head" /> - this pull's in bits & builds the head, including building that JS. So I just want to remove the SqueezeBox part of that JS after it has been built. So I thought about looping through the _scripts array and removing it from there. –  user991830 Jun 15 '13 at 8:47
    
what do you mean "scripts array"? If you can get a script from the array as a string => my answer still applies to it. –  Brian Jun 15 '13 at 8:52
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.