js

Drupal7.x javascript function after ajax - ajax invoke

初探 Drupal 中使用 ajax 之後
使想在 AJAX complete 之後執行一些自定義的 javascript

例如ajax form submit 之後 slideUp form
submit 之後需要修改某些內容

使用的是 ajax callback 的command, 加上 ajax_command_invoke
Form array:

Drupal7 表單內載入 css, js, attach

Edit: 2012-11-07: external css

Drupal7 中以下的代碼是不會達到你想要的效果的

Drupal7 AJAX 提交表單 submit form

Drupal7 原生已經提供一大堆 AJAX 的 API 可以使用
令一些基本的 AJAX 工作變得很簡單,例如

Drupal7 Javascript, once()

-
Free tags: 

once() 是我碰到 ajax submit 的時候第一次使用到
它是一個已經內建到 Drupal 的一個 jQuery 插件
令一個 event 不會 bind 兩次

原意是一條連結觸發 ajax
我bind 了 click event 到增加一個 loading 的 gif
取代 (replaceWith) 的方式將一個 form 更換
因為 replaceWith 之後都會再一次執行 javascript
下一次解發連結便會有兩個 loading gif
可以使用 once() 解決:

Facebook Oauth2.0 client side authentication

-
Free tags: 

作為一個開發者,你就是無辦法避開 Facebook 的 API
無論它比屎還爛
或者文檔比死海古卷還殘缺都一樣

還好的是,這次介紹的API Google 都有
所以照抄之下還可以
就是 javascript side 的用戶認證
https://developers.facebook.com/docs/authentication/client-side/#no-jssdk

Barcamp HK 2012 summer 後記

先 open source 我的 presentation https://github.com/joetsuihk/barcamp2012

其實我講的 "JS 201, when JS becomes hard to manage"
也不是什麼新的東西
只是將我做小 project 時的經驗講一下
希望訓練自己的演講能力的同時
可以帶到些什麼給其他人

今年我自己覺得學生好像特別多
上一年在大學裏舉行,學生比例偏高是正常
但今年在 HK Cacoon 仍然有不少學生
更有正在做 startup 的

但整體 presenation 的質量仍然舋得每年下降 (我也有份拉低)
期望冬季的 barcamp 能有更精采的演講

Javascript substr 負數

-
Free tags: 

IE<9 的情況之下,
"1234".substr(-1)
是不會返回 "4" 的

IE<9 會將小於零的數字當作零
而其他的瀏覧器已經懂得返回“從最後開始算字符長度”了

在 IE 6 幾近死亡之後
IE 的路還很長呀

ref: http://eureka.ykyuen.info/2011/04/01/javascript-negative-substr-problem-...

Drupal 的 Javascript 變數陣列

Drupal 是一個CMS, 它除了有很多 PHP 的函數 可以調用之外,
還有在頁面的 javascript 加了一些常用的變數, 函數
你可以在 firebug 或者 chrome 的 developer console內,
Drupal.* 找到它們

例如 PHP 函數<?php base_path()?> 可以在 Drupal.settings.basePath 內找到
所以 AJAX 的要求路徑便可以隨網站路徑自動改變了

加js, css file 到theme, Add a theme specific js/css to a page

-
Free tags: 

如題, 你可以在 theme 的 .info file 用以下的方法

scripts[] = js/gallery.js

stylesheets[all][] = css/gallery.css

你可以加第三方的 js/css, 例如 jquery ui, fancybox 之類
如果你看到你的page.tpl.php 有<script type="text/javascript" src=""></script>你可能會考慮用以上的方法include 了

Note1: 路徑是相對到theme 的資料夾
Node2: 它們會被優化的, 如果你開啟了壓縮 js/css 檔案的話

As titled, if you want to add a js or css file only to a theme, you may:

Google