Chinaunix首页 | 论坛 | 博客
  • 博客访问: 41102
  • 博文数量: 30
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 310
  • 用 户 组: 普通用户
  • 注册时间: 2013-12-10 07:50
个人简介

学会总结,积累

文章分类

全部博文(30)

文章存档

2014年(14)

2013年(16)

我的朋友

分类: IT业界

2013-12-16 14:30:45

1,创建自己的module
在/mobile/app/modules/下创建custom文件夹,在custom文件夹下再创建以你的module名称命名的文件夹,比如  my_module,然后在这个文件夹里创建 'my_module.js',然后就是按照API在 'my_module.js'中写一些JS代码,例如:

点击(此处)折叠或打开

  1. function gt_first_test_menu() {
  2.   var items = {
  3.      page_one:{
  4.       title:'欢迎光临',
  5.       page_callback:'gt_first_test_page_one',
  6.       title_callback:'gt_first_test_custom_page_title_callback',
  7.       title_arguments:['My Cool Title']
  8.     },
  9.      page_two:{
  10.       title:'Page Two',
  11.       page_callback:'gt_first_test_page_two'
  12.     }
  13.   };
  14.   return items;
  15. }
  16. /**
  17.  * Callback function for page one.
  18.  */
  19. function gt_first_test_page_one() {
  20.   var content = {
  21.     page_two_button:{
  22.       path:"page_two",
  23.       text:"Go to Page Two",
  24.       theme:"button_link"
  25.     }
  26.   };
  27.   return content;
  28. }
  29. /**
  30.  * Callback function for page two.
  31.  */
  32. function gt_first_test_page_two() {
  33.   var content = {
  34.     page_two_button:{
  35.       path:"page_one",
  36.       text:"Go to Page One",
  37.       theme:"button_link"
  38.     }
  39.   };
  40.   return content;
  41. }
  42. /**
  43.  * Page callback function for custom_page title_callback.
  44.  */
  45. function gt_first_test_custom_page_title_callback(title) {
  46.   try {
  47.       
  48.     return title.replace("Cool", "Great");
  49.     //drupalgap_set_title('Fast Food Friday');
  50.     
  51.   }
  52.   catch (error) { drupalgap_error(error); }
  53. }
这样我们就创建好了一些静态的module,动态调用后端数据我们后面再说,先把架子搭起来。然后当然是要告诉drupalgap启用我们自己写的module,在settings.js里

点击(此处)折叠或打开

  1. // Custom Modules - www/app/modules/custom
  2.     drupalgap.modules.custom = [
  3.       {name:'my_module'},
  4.     ];



2,创建自己的theme
Drupalgap的theme机制和Drupal本身的theme机制是一致的,都是在mobile/app/themes/下建立一个名称和你的theme名字一样的文件夹来放置所有和你的自定义theme相关的文件。 然后就是具体的执行渲染方法不大一样,Drupalgap是放置一个page.tpl.html来放置你的region placeholder,

点击(此处)折叠或打开

  1. <div id="{:drupalgap_page_id:}" data-role="page">
  2.   {:header:}
  3.   {:navigation:}
  4.   {:content:}
  5.   {:footer:}
  6. </div>
教程里提到至少应放置的region为:header, content 和 footer.然后在这个theme文件夹里继续添加一个 ‘my_theme.js’去设置regions:

点击(此处)折叠或打开

  1. /**
  2.  * Implements DrupalGap's template_info() hook.
  3.  */
  4. function medicine_info() {
  5.   try {
  6.     var theme = {
  7.       "name":"medicine",
  8.       "regions":{
  9.         "header":{
  10.           "attributes":{
  11.             "data-role":"header"
  12.           }
  13.         },
  14.         "navigation":{
  15.           "attributes":{
  16.             "data-role":"navbar"
  17.           }
  18.         },
  19.        
  20.         "content":{
  21.           "attributes":{
  22.             "data-role":"content"
  23.           }
  24.         },
  25.         "footer":{
  26.           "attributes":{
  27.             "data-role":"footer"
  28.           }
  29.         }
  30.       }
  31.     };
  32.     return theme;
  33.   }
  34.   catch (error) { drupalgap_error(error); }
  35. }
设置完region,就应该把blocks添加到你的region里,这一步我们是在 mobiles/app/settings.js里的 '//Theme blocks里完成的,代码像这样


点击(此处)折叠或打开

  1. //my_theme Theme blocks
  2. drupalgap.settings.blocks.my_theme = {
  3.   top:{
  4.     logo:{} /* drupalgap's logo system block */
  5.   },
  6.   header:{
  7.     title:{} /* drupalgap's title system block */
  8.   },
  9.   navigation:{
  10.     main_menu:{} /* drupalgap's main menu system block */
  11.   },
  12.   content:{
  13.     main:{} /* drupalgap's main system block, used to display page content */
  14.   },
  15.   footer:{
  16.     powered_by:{} /* drupalgap's 'powered by' block */
  17.   }
  18. };
这样就设置好了我们的theme,最后,为了启用我们的新theme,在settings.js里这样

点击(此处)折叠或打开

  1. // Theme
  2. drupalgap.settings.theme = 'my_theme';

然后是使用jQuery mobile theme roller定制样式,这里要注意jQuery mobile的版本,记得随时关注更新,然后把解压的css文件放置到app根目录下的index.html中


阅读(559) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~