2012-04-05 3 views
2

인라인 확인을 위해 this jquery plugin이 발견되었습니다. 나는 압축/모든 js 파일을 하나의 http 요청을 최적화하기 위해 결합한다 (이것은 수동이다). 이제이 파일의 맨 위에는 jquery Library 1.7.1이 있습니다. 그런 다음 인라인 확인 플러그인을 넣습니다. 그래서이 플러그인은 jquery 라이브러리가있는 파일에있을 때 작동하지 않습니다. 내 문제는 뭐니?jquery jquery와 병합/압축 할 때 플러그인이 작동하지 않음을 확인하십시오.

예는 : 일반 : 그렇다

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

전 (이 근무) :하지 Workk comperss 한 파일 (JQuery와 + 인라인 확인)에

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

인라인 확인 플러그인 :

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); 
    }); 
} 

감사합니다.

+0

압축 파일 플러그인 코드 이전에 jQuery 라이브러리가 있습니까? – rgin

+0

네, 물론입니다. 이 질문을 내 질문에 :이 파일의 맨 jquery 1.7.1 다음 인라인 확인 플러그인을 넣어 – BBKing

+0

전체 압축 된 파일을 표시하십시오. 또한 정말로 라이브러리와 플러그인을 하나의 파일에 넣으시겠습니까? 업데이트가 있다면 어떻게 될까요? – rgin

답변

0

나는 전체 파일을보아야 할 필요가있는 Rgin에 동의한다.하지만 파일이 캐시되어있을 수도있다. ctrl-F5를 누르거나 캐시를 수동으로 지우십시오.