2012-08-29 2 views
0

하나의 div를 다른 div 앞에 렌더링하려고합니다.특정 js 파일이 Drupal에서 작동하지 않습니다.

로컬 컴퓨터에서 js를 테스트하여 간단한 페이지를 만들어 작동하는지 확인했습니다. JS에

(function ($, Drupal, window, document, undefined) { 

    $('.content .body').insertBefore('.content .field-name-field-image-one'); // check before() examples 

})(jQuery, Drupal, this, this.document); 

내 .INFO 파일 링크를 그리고로드 :

<!DOCTYPE html> 
<html> 
<head> 
    <script src="http://code.jquery.com/jquery-latest.js"></script> 
</head> 
<body> 
    <div id="QWERTY"> 
     <div class="content"> 
      <div class="field-name-field-image-one">IMAGE</div> 
      <div class="body">BODY</div> 
     </div> 
    </div>  
<script>$('.content .body').insertBefore('.content .field-name-field-image-one'); // check before() examples</script> 

</body> 
</html> 

나는 내 드루팔 사이트에 JS 파일에 다음 코드를 추가 한 다음과 같이 코드입니다. 자바 스크립트를 필요로하는 다른 요소들도 효과적입니다. 나는 html.tpl 파일에 스크립트를 추가하려고 시도 했는데도 작동하지 않았다.

영향을주고 싶은 div는 html 마크 업 내에 중첩되어 있으며, 내가 만든 간단한 버전과 비교하여 여러 클래스가 적용되어 있습니다. 이유가 될 수 있을까요? 충분히 구체적이지 않습니까? 도움을

답변

0

덕분에, 나는 다음에 업데이트되었습니다, 그것은 작동합니다

(function ($, Drupal, window, document, undefined) { 
    $(function() { 
    $('.content .body').insertBefore('.content .field-name-field-image-one'); // check before() examples 
    }); 

})(jQuery, Drupal, this, this.document); 
0

당신은 콘텐츠 형식의 필드의 순서를 변경하려면 자바 스크립트를 사용할 필요가 없습니다.

Drupal 7을 사용하는 경우 홈»관리»구조 (/ admin/structure/types)로 이동 한 다음 변경할 콘텐츠 유형 옆의 "디스플레이 관리"를 클릭하십시오. 이제 필드를 드래그 앤 드롭하여 각보기 모드 (예 : 기본값, 티저)에 대한 표시 순서를 변경할 수 있습니다.

실제로 자바 스크립트를 사용하려면 Drupal 7에서 특수 구문을 사용합니다.

(function ($) { 
    Drupal.behaviors.custom_moveimage = { 
    attach: function (context, settings) { 
     $('.content .body').insertBefore('.content .field-name-field-image-one'); 
    } 
    }; 
}(jQuery)); 

Drupal 설명서에는 이에 대한 more information이 있습니다.

관련 문제