2010-06-06 4 views
4

drupal이 특정 페이지에서 1.4를 사용하도록하는 방법을 찾고 있습니다. drupal jQuery 1.4 on specific pages특정 페이지의 drupal jQuery 1.4

그것은 내가 올바른 표시 대답을 시도하는 나에게 동안을 찾습니다

이이 오래된 질문과 동일합니다. 하지만 전반적으로 모듈 개발자가 처음이기 때문에 대답을 기반으로 파악할 수 없었습니다.

그 대답에서 코드는 다음처럼 보였다 :

/** 
* Implementation of hook_theme_registry_alter(). 
* Based on the jquery_update module. 
* 
* Make this page preprocess function runs *last*, 
* so that a theme can't call drupal_get_js(). 
*/ 
function MYMODULE_theme_registry_alter(&$theme_registry) { 
    if (isset($theme_registry['page'])) { 
    // See if our preprocess function is loaded, if so remove it. 
    if ($key = array_search('MYMODULE_preprocess_page', 
     $theme_registry['page']['preprocess functions'])) { 
     unset($theme_registry['page']['preprocess functions'][$key]); 
    } 
    // Now add it on at the end of the array so that it runs last. 
    $theme_registry['page']['preprocess functions'][] = 'MYMODULE_preprocess_page'; 
    } 
} 

/** 
* Implementation of moduleName_preprocess_hook(). 
* Based on the jquery_update module functions. * 
* Strips out JS and CSS for a path. 
*/ 
function MYMODULE_preprocess_page(&$variables, $arg = 'my_page', $delta=0) { 

    // I needed a one hit wonder. Can be altered to use function arguments 
    // to increase it's flexibility. 
    if(arg($delta) == $arg) { 
    $scripts = drupal_add_js(); 
    $css = drupal_add_css(); 
    // Only do this for pages that have JavaScript on them. 
    if (!empty($variables['scripts'])) { 
     $path = drupal_get_path('module', 'admin_menu'); 
     unset($scripts['module'][$path . '/admin_menu.js']); 
     $variables['scripts'] = drupal_get_js('header', $scripts); 
    } 
    // Similar process for CSS but there are 2 Css realted variables. 
    // $variables['css'] and $variables['styles'] are both used. 
    if (!empty($variables['css'])) { 
     $path = drupal_get_path('module', 'admin_menu'); 
     unset($css['all']['module'][$path . '/admin_menu.css']); 
     unset($css['all']['module'][$path . '/admin_menu.color.css']); 
     $variables['styles'] = drupal_get_css($css); 
    } 
    } 
} 

내가 '비디오'를 '블로그'과의 노드 유형에 대한 설정이 해제하는 jquery_update 1.3.2이 필요합니다. 누군가 나를 도울 수 있습니까?

감사합니다.

답변

2

MYMODULE_preprocess_page 함수에서 $ scripts 변수에는 페이지에 추가 할 모든 JavaScript에 대한 정보가 들어있는 배열이 들어 있습니다.

페이지에서 JS 파일을 제거하려면 $ scripts 배열에서 항목을 제거한 다음 $ variables [ 'scripts']를 업데이트해야합니다. 이것이 바로 unset의 기능입니다. 당신이 찾을 수 있도록 print_r에 $ 스크립트 var에있을 것이다, 그렇지 않으면

unset($scripts['core']['misc/jquery.js']); 

:

는 제거하려는 jQuery를 당신이 그것을 제거 할 수 있습니다, 드루팔 함께 제공 년대 한 경우 제거해야하는 항목

+0

콘텐츠 유형을 확인하여 설정 해제 위치를 어떻게 알 수 있습니까? 지금은 arg를 통해 작동합니다. 감사합니다. – Mark

+0

올바른 방법인지 확실하지 않지만 nid ($ _GET [ 'q'])를 기반으로 '유형'필드에 대해 '노드'테이블을 쿼리하면됩니다. –

관련 문제