jquery document ready , window load の順番
4月 16th, 2012
$(window).load(function() {
console.log(’window load’);
});
$(document).ready(function(){
console.log(’document ready’);
});
$(function() {
console.log(’jquery’);
});
window loadは画像をなどを呼んだ後に呼ばれるので最後
document readyはドキュメントが出来たら呼ばれる?ので画像とか終わってから処理したい場合はダメ。
document readyと$()は同じ?みたいです。
Refused to evaluate script because of Content-Security-Policy. | chrome extension
4月 15th, 2012
setTimeout で
Refused to evaluate script because of Content-Security-Policy.
のエラーメッセージ。
setTimeoutをどうやって表現するかと
と思っていたら、ただ書き間違えていただけでした・・・
evalは使えませんが、普通に書く分には問題ないようです。
javascript closure compiler
4月 15th, 2012
複数ファイルを複数ファイルに出来ないのかな・・・?と思い。
compilerをダウンロード
https://developers.google.com/closure/compiler/
$ cd compiler-latest/
COPYING README compiler.jar
複数ファイルを一つにするには、READMEに書いてある通り
java -jar compiler.jar --js=in1.js --js=in2.js … --js_output_file=out.js
.js:55: WARNING - Suspicious code. This code lacks side-effects. Is there a bug?
reutrn;
普通に使うとエラー検出も出来て便利です。
levelを変更してみる
java -jar ../../compiler-latest/compiler.jar [...]
macでshift_jis , euc-jp 変換 iconv
4月 15th, 2012
ちょっと面倒だからShift_JISは無視してたけど必要なのでとりあえず。
nkf は入っていなかったので iconvで変換
$ which nkf
$ which iconv
/opt/local/bin/iconv
iconv -f UTF-8 -t Shift_JIS utf-8.txt > sjis.txt
メッセージファイルをsjisで保存しておいて使う。
var msg ={
menu:{
100: “メニュー”,
101: “ランチ”,
102: “ハンバーグ”
},
error:{
9001: “在庫がありません”,
9002: “待ち時間30分です。”
}
};
を保存しておいてsjisのページで読込んで使えました。
ajaxのhttp headerを書き換える。webrequest API | chrome extension
4月 13th, 2012
普通にxhrを弄る場合は
http://www.w3.org/TR/XMLHttpRequest/
http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method
mimetypeなどは
beforeSend: function(xhr){
xhr.overrideMimeType(”text/plain;charset=Shift_JIS”); // A
xhr.setRequestHeader(”Content-type”,”text/plain;charset=Shift_JIS”); // B
},
はAかBで更新できたのですが、この辺はダメで
Accept-Charset
Accept-Encoding
Access-Control-Request-Headers
Access-Control-Request-Method
Connection
Content-Length
Cookie
Cookie2
Content-Transfer-Encoding
Date
Expect
Host
Keep-Alive
Origin
Referer
TE
Trailer
Transfer-Encoding
Upgrade
User-Agent
Via
さてどうしようかと webRequest API の登場です。
http://code.google.com/chrome/extensions/trunk/webRequest.html#event-onBeforeSendHeaders
* onBeforeSendHeaders (optionally synchronous)
Fires when a request is about to occur and the initial headers have been prepared. The event is intended to [...]
focus blur textboxにメッセージを入れておく。 | javascript
4月 10th, 2012
input textboxの文字にメッセージを入れておく。
上が初期状態、下がフォーカス時。
(filterワードを入れるボックスなのでfilterと入れてあります。
<input type=”text” value=”filter” id=”textbox_id” >
$(’#textbox_id’).focus(function(){
if( $(’#textbox_id’).val().match(/filter/)){
$(’#textbox_id’).val(”);
}
$(’#textbox_id’).css(’color’,'#444444′);
});
$(’#textbox_id’).blur(function(){
if( $(’#textbox_id’).val() == ”){
[...]
javascript delete , undefined
4月 9th, 2012
objectの要素を削除する。
obj = {
prop: 100
};
// 100
console.log( obj.prop );
delete( obj.prop );
// undefined
console.log( obj.prop );
submission error loading page when post form. | jquery mobile
3月 16th, 2012
formの時、ajaxでエラーが出るのでなんか・・・
検索すると
mobileinitで
$.extend( $.mobile , {
ajaxFormsEnabled :false
});
$.mobile.ajaxFormsEnabled=false;
これしかない!
ってなっちゃうのですが、これがdoesn’t work for me な感じで。
単純に
<form ajax-data=”false” method=”POST” … >
だけで良いと言う結果。
まぁドキュメントが追いつかないのは良くあることなので仕方ないのですが。
検索しても色々なバージョンのドキュメントが散らばっているのもなかなか手強いところです。
console.log()を出力させない。 | phonegap iOS
3月 2nd, 2012
とりあえず、phonegap.jsで DebugConsoleが定義されているので
if ( true ){
DebugConsole.prototype.log = function(message, maxDepth) {};
DebugConsole.prototype.warn = function(message, maxDepth) {};
DebugConsole.prototype.error = function(message, maxDepth) {};
window.console = new DebugConsole();
}
こんな感じで上書きするとconsole.logで何もしなくなります。
リンクをsafariで開く | phonegap iOS
3月 2nd, 2012
外部ページもアプリで開いてしまうので、外部リンクは、safariで開くように変更します。
Classes AppDelegate.mを編集します。
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
return [self.viewController webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}
http://groups.google.com/group/phonegap/browse_frm/thread/7815d5e103fc18ac/a3ba58b1002af281?#a3ba58b1002af281
webViewを利用している人は、ここにドメインの振り分けを追加する感じで。
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
if( [[url scheme] isEqualToString:@”http”] ||
[[url scheme] isEqualToString:@”https”])
{
[[UIApplication [...]