jquery Confirm plugin not work when merge/compress with jquery

Go To StackoverFlow.com

2

i found this jquery plugin for inline confirmation. i compress/combine all js files to one for optimize http request (this is manual). now top of this files is jquery Library 1.7.1 and then i put inline confirmation plugin. so this plugin not worked when Located in a file with jquery library. what's my problem ?

e.x : normal : Apart ( this Worked )

<script type="text/javascript" src="./js/jquery.js"></script>
<script type="text/javascript" src="./js/inline-confirmation.js"></script>

e.x : comperss to One File ( jquery + inline-confirmation ) Not Workk

<script type="text/javascript" language="javascript" src="./js/main.js"></script>

Inline confirmation plugin :

jQuery.fn.confirm = function(options) {
  options = jQuery.extend({
    msg: 'Are you sure?',
    stopAfter: 'never',
    wrapper: '<span></span>',
    eventType: 'click',
    dialogShow: 'show',
    dialogSpeed: '',
    timeout: 0
  }, options);
  options.stopAfter = options.stopAfter.toLowerCase();
  if (!options.stopAfter in ['never', 'once', 'ok', 'cancel']) {
    options.stopAfter = 'never';
  }
  options.buttons = jQuery.extend({
    ok: 'Yes',
    cancel: 'No',
    wrapper:'<a href="#"></a>',
    separator: '/'
  }, options.buttons);

  // Shortcut to eventType.
  var type = options.eventType;

  return this.each(function() {
    var target = this;
    var $target = jQuery(target);
    var timer;
    var saveHandlers = function() {
      var events = jQuery.data(target, 'events');
      if (!events && target.href) {
        // No handlers but we have href
        $target.bind('click', function() {document.location = target.href});
        events = jQuery.data(target, 'events');
      } else if (!events) {
        // There are no handlers to save.
        return;
      }
      target._handlers = new Array();
      for (var i in events[type]) {
        target._handlers.push(events[type][i]);
      }
    }

    // Create ok button, and bind in to a click handler.
    var $ok = jQuery(options.buttons.wrapper)
      .append(options.buttons.ok)
      .click(function() {
      // Check if timeout is set.
      if (options.timeout != 0) {
        clearTimeout(timer);
      }
      $target.unbind(type, handler);
      $target.show();
      $dialog.hide();
      // Rebind the saved handlers.
      if (target._handlers != undefined) {
        jQuery.each(target._handlers, function() {
          $target.click(this.handler);
        });
      }
      // Trigger click event.
      $target.click();
      if (options.stopAfter != 'ok' && options.stopAfter != 'once') {
        $target.unbind(type);
        // Rebind the confirmation handler.
        $target.one(type, handler);
      }
      return false;
    })

    var $cancel = jQuery(options.buttons.wrapper).append(options.buttons.cancel).click(function() {
      // Check if timeout is set.
      if (options.timeout != 0) {
        clearTimeout(timer);
      }
      if (options.stopAfter != 'cancel' && options.stopAfter != 'once') {
        $target.one(type, handler);
      }
      $target.show();
      $dialog.hide();
      return false;
    });

    if (options.buttons.cls) {
      $ok.addClass(options.buttons.cls);
      $cancel.addClass(options.buttons.cls);
    }

    var $dialog = jQuery(options.wrapper)
    .append(options.msg)
    .append($ok)
    .append(options.buttons.separator)
    .append($cancel);

    var handler = function() {
      jQuery(this).hide();

      // Do this check because of a jQuery bug
      if (options.dialogShow != 'show') {
        $dialog.hide();
      }

      $dialog.insertBefore(this);
      // Display the dialog.
      $dialog[options.dialogShow](options.dialogSpeed);
      if (options.timeout != 0) {
        // Set timeout
        clearTimeout(timer);
        timer = setTimeout(function() {$cancel.click(); $target.one(type, handler);}, options.timeout);
      }
      return false;
    };

    saveHandlers();
    $target.unbind(type);
    target._confirm = handler
    target._confirmEvent = type;
    $target.one(type, handler);
  });
}

Thanks

2012-04-05 18:35
by BBKing
in the compressed file. Do you have the jQuery library before the plugin code - rgin 2012-04-05 19:01
Yes, Sure. I tell this to my question : now top of this files is jquery 1.7.1 and then i put inline confirmation plugi - BBKing 2012-04-05 19:04
Try showing the whole compressed file. Also, do you really want to put both library and plugin in one file? I mean, what if there are updates - rgin 2012-04-05 20:50


0

I agree with rgin that we probably need to see the entire file (and that you should probably keep it separate), but I think may just be that the file is cached. Hit ctrl-F5 or manually clear the cache.

2012-04-06 01:53
by craniumonempty
Ads