将棋盤と駒をWEB上に表示する1

まずは静的に将棋盤と駒をWEBページに表示してみる。
HTMLの記述は以下のごとくなる。
当該部分のみ

<link href="boardstyle.css"  rel="stylesheet" >
.
.

<div class="table"> <!-- outer table -->

<div class="row">
<div id="boardbase" class="cell">
<img class="board" src="assets/images/shogiboards/ban_kaya_a.png" alt=""/> <!-- 盤を表示-->
<img class="board" src="assets/images/shogiboards/masu_dot_xy.png" alt=""/><!-- マス目を表示 -->
<img class="koma c5 r9" src="assets/images/shogiboards/Sou.png" alt=""/><!--先手王を 59に -->
<img class="koma c5 r1" src="assets/images/shogiboards/Gou.png" alt=""/><!-- 後手王を 51に-->
<img class="koma c3 r7" src="assets/images/shogiboards/Ggin.png" alt=""/><!--後手銀を 37に -->
<img class="koma c9 r7" src="assets/images/shogiboards/Sfu.png" alt=""/><!--先手の歩を97に-->
<img class="koma c4 r9" src="assets/images/shogiboards/Skin.png" alt=""/><!--先手の金を49に-->
</div>

<div class="table"><!-- inner table -->
<div class="row">
<div id="goteMochigoma" class="komadai cell"> <!-- 後手の駒台-->
<img src="assets/images/shogiboards/Gou.png" alt=""/>
<img src="assets/images/shogiboards/Ggin.png" alt=""/>
<img src="assets/images/shogiboards/Gfu.png" alt=""/>
<img src="assets/images/shogiboards/Gfu.png" alt=""/>
<img src="assets/images/shogiboards/Gkin.png" alt=""/>
</div>
</div>
<div class="row">
<div class="cell empty" ></div>
</div>
<div class="row">
<div id="senteMochigoma" class="komadai cell"><!--先手の駒台-->
<img src="assets/images/shogiboards/Sgin.png" alt=""/>
<img src="assets/images/shogiboards/Sfu.png" alt=""/>
<img src="assets/images/shogiboards/Sfu.png" alt=""/>
<img src="assets/images/shogiboards/Skyo.png" alt=""/>

</div>
</div>
</div><!-- innter table -->
</div><!-- shogirow for the outer css-table-->
</div><!--shogitable-->

一方、boardstyle.cssは

.forSnapshot {position:relative;}
.table {display:table;}
.row {display:table-row;}
.cell {display:table-cell;}
.empty {height:25px;}
#boardbase {position:relative; width: 440px; height:490px;}
#senteMochigoma {vertical-align:bottom;}
.komadai {height:220px; width:160px; background-image:url(assets/images/shogiboards/ban_kaya_a.png);}
.board {position: absolute; left:10px; top:9px; }
.comment {padding-left:10px; width:590px;min-height:120px;}
.koma {position: absolute ; width:43px; height:48px;}
.marker {position:absolute; width:43px; height:48px;}
.lostworld {left:-20000px; top: -20000px;}
.c1 {left:365px;} .c2 {left: 322px;} .c3 {left:279px;}
.c4 {left:236px;} .c5 {left: 193px;} .c6 {left:150px;}
.c7 {left:107px;} .c8 {left: 64px;}  .c9 {left: 23px;}
.r1 {top:20px;}   .r2 {top:68px;}    .r3 {top:116px;}
.r4{top:164px;}   .r5{top:212px;}    .r6 {top:260px;}
.r7{top:308px;}   .r8{top:356px;}    .r9{top:404px;}
画像ファイルはすべてassets/images/shogiboards フォルダーに格納しておく。
ポイントとしては


<div id=boardbase> で将棋板ブロックのコンテクストを作り、この中に画像を放り込む。この画像の位置については koma属性でabsolute とし、列と行の位置をcx, rx でそれぞれ指定する。 r1=20px, c9=23px を起点に cxは横幅43px  lxは 縦高さ48pxづつ変化させている。駒台のブロックには単純に駒のイメージファイルを放り込んでおくと順番に表示される。

html において、将棋板と駒台をアレンジするのに、CSSのdisplay:table 属性を使っている。 htmlの一連のtable tag類 を使うことも考えたが、これはデータをリストアップするのとはちょっと違ったような気がしたので。cssで処理をすることにした。

結果はこちら

 

一応表示できるようになったが、これで将棋の駒40枚をならべるのは大変なので、 次回はたとえば文字列 ”s44g”,”g65p” などの羅列をつくり、これをJavascriptで処理して駒の配置表示する方法をかんがえる。

将棋盤をHTML/CSSで構成し、駒をJavaScriptで動かしてみる。

趣味で英語の将棋入門サイトをホストして5年くらい経つ。 駒の動きとか手筋、などをみせるのに過去ネット上で入手できる色々なアプリに世話になってきた。一番お世話になっているのが柿木さんのkifu for Flash で、定跡の紹介などは、このアプリケーションが欠かせない。 他にもユモケンさんのFlashを使った将棋盤を使って歩の手筋の紹介などをしてきた。 数年前に簡単な詰め将棋集をつくるのにBCM将棋で画像を生成し、これを順次表示して詰め手順を示すしくみを当時覚えたてのJavaScriptで書いてみた。 ただそのときわかったのだが、手数ごとの画像をいちいちセーブしてそれを組みたてる、というのはJavaScriptを使っていても結構手間がかかる。 今回駒職人1さんのサイトからCreative common license による駒と将棋盤の画像が入手できたのでこれを機会に初期の駒配置と動きのデータをJavaScriptファイルに書いておけば、それをなぞって実行してくれるようなしかけを作ってみた。

一応うごくようになったので、ここに公開しておくことにする。

特徴としては

駒の配置をCSSで処理しているということで、具体的にいうと たとえば先手の銀を34におきたい場合、銀のイメージファイルがSgin.png とすると

<img  src=”Sgin.png” class=”koma c3 r4″ alt=”” /> というようなイメージエレメントをJavascriptで動的に生成して将棋盤の3四の位置に銀を表示させる、というような手法をとっている。

動くサンプルをここにおいておく。 また、3年経つと何をやっているのかわからなくなる、というのが前回の経験でよくわかったので少し詳しい説明を順次ここに書きのこしておくことにする。 誰かの参考になればうれしいし、もっと経験のある方から助言をいただけるとありがたい。

ねらい: サイトの教材作成に使えるような動く将棋盤
データのエラーチェックなどはつけない(自分でしか使わないので)
前もって用意しておいたデータファイルをもとに初期配置およびその後の駒の動きを表示できる
CSSとJavaScript、HTMLの3種の神器のみで記述、JavaScriptはJqueryLibraryも使用

上記のページにはHTML記述に余計なものは入れていないので、ブラウザーの開発ツールを使って二つのJSファイルの中身とCSSファイルの中身も一緒に見てもらえれば、それなりにコメントも入れたので、ほぼ全容がつかめると思う。

Switching host

I have just moved the web host from free hosting to fee based hosting.  One thing I immediately noticed was the increase in speed for accessing the site.  This costs me $4/month but hopefully I don’t need to deal with connection difficulty as often as I used to with the previous service.  The service I was using before was actually a fine one for free service.  The provider is called 000webhost.com, and they supplied a site without any advertisement, so I was able to have a site without clutter of flashy advertisement. But I think it’s worth to pay $4 for a peace of mind knowing I have a little better service with larger bandwidth.  Time to do more exploring.

Showing a list from another SharePoint Site

Showing a list from another SharePoint site (or cross-site listing)

One of the frustration about developing SharePoint page is that you can not use a list view from another Site. If two sites are under the same Site collection, then it will be possible but our IT people created each division’s site as independent site and not as a site collection (and there was a good reason for doing this way, 4 years ago. I am aware of that too.)

Christophe Humbert from Path to SharePoint has a solution to this. One of his online tools will generate a JavaScript snippet that you can drop into CEWP to show a list or calendar from another site page.  He uses JQuery to extract a list out of the target page and insert where the CEWP is located.

This “Cross site list Snapshot tool” works pretty well.  However, the list “extracted” in this manner can not take advantage of TextToHTML script.

The TextToHTML is another gem from Christophe that uses calculated columns to display colored text, background or even bar charts and also traffic signals (as KPI). If you have not seen his solution, take a look at this,this and this.  Along with Easy Tabs (another Christophe’s creation)  my colleagues in the office think I am a SharePoint wizard (far from the truth)

The reason the combination does not work is because  TextToHTML will execute as soon as the browser read the script. Unfortunately at that time, the Cross site list snapshot script is still busy working on extracting the list so TexttoHTML does not see the list.

In his response to one of the comments in his blog, Christophe mentioned a use of callback function that is available for JQuery so that two scripts can talk to each other.

The idea is for the JQuerry load function to “call back” textToHTML script once the load function finishes its primary job.

I have experimented with this concept and came up with (my) solution so I am presenting it here.  This works with scripts available from PathToSharePoint site as of November 1, 2010

First we have to modify the TextToHTML script.  Download the script from Christophe’s site and look for the following section of the code. (I use “light version” of the script)

// Calendar views
var regexpA = new RegExp("\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*");
TextToHTML(document.getElementsByTagName("a"),regexpA);

// List views
var regexpTD = new RegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");
TextToHTML(document.getElementsByTagName("TD"),regexpTD);

Change  the code above as follows. In essense, we are turning the executable codes to function declarations.

// Start of modifications
//Calendar views
function calendarT2H() {
var regexpA = new RegExp("\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*");
TextToHTML(document.getElementsByTagName("a"),regexpA);
}
// List views
function listT2H(){
var regexpTD = new RegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");
TextToHTML(document.getElementsByTagName("TD"),regexpTD);
}
//maintains the original functionality of the script.
// Omit below two lines if no other part of the page uses TexttoHtML
calendarT2H();
listT2H();
//end of modifications

Save the above script as your TextToHTML.

Now generate your list snapshot script using Path To SharePoint’s  Tool -Cross-Site-List-Snapshot page

Open the Script with text editor. Search for the following string toward the end of the script.

..(“href”,$(this).attr(“href”)+s+”Source=”+location.href);});});};LoadView…

Change

“location.href);});});};”

to

“location.href);},listT2H());});};”

What I did was to add a callback function parameter to JQuery’s  load() function.  [Replace listT2H() with calendarT2H() if the target is calendar.]

The JQuery load() function works like this
Load (url,parameters,callback)
Here, url is the URL of the resource being fetched, parameters is a Javascript object whose properties hold values to send to the server, and callback is a callback function that jQuery will call when the Ajax operation is complete. In the snapshot code, url is our list page url, parameters is a magic that Christophe is passing on to modify the list output. However,
as supplied by Christophe’s code generator, There is no callback.

Save the Script text.

I am using SharePoint2007 and I found the cleanest way to use CEWP for scripting is to link a file to CEWP, rather than entering source code directly in CEWP.  I create “webpart” document library and upload both text files to the library.

So, in the above set up,   A Web Part Zone has two webparts. Both are CEWP.

WepPart 1 – CEWP  linked to ../webpart/CrossSiteListSnapshot-modified.txt
WebPart 2 – CEWP (Hidden) linked to ../webpart/TexttoHTML-modified.txt

The page now shows a list from another site with calculated columns correctly rendered.

Way of wayfinder

ModXのWayfinderはナビゲーションリストを作るときに、base_urlからの相対パスを出力する。 よってテンプレートに<base>tagで [[++site_url]]指定をしてやる必要がある、これを指定せずに階層の下がったページからナビゲーションしようとすると システムはカレントパスを相対パスの前に追加するからリンク先が存在しない事態になる。

Make sure you have the following in the the <head> section of your template:
Code:

<base href=”[(site_url)]” />
without the above code in the site template, the navigation menu  wayfinder will generate will not render correct path.   This is because Wayfinder generates the path from base url. If you left <base> tag out, the system will always start from current path.
Let me describe what had happened to me.
Target document tree looks like below;
one – two
  |_    three
  |__ four
  |__ five
The wayfinder sinppet generates a list with correct hrefs and  works fine in the page one.
When navigated to page two, then the links generated for other pages are incorrect.
if you are in second level, then the path will start as http://…/one.  the wayfinder adds /one/three.  Therefore the generated path is http://…../one/one/three,  rather than http://…./one/three  etc., (“one/ “is repeated twice)
Simply adding the <base href=”[[++site_url]]”> line at the <head> section of the template solve the issue.

Drupal, WordPress, netdotduke, oh my

Microsoft now has a nice installer called Web installer which, on top of usual microsoft tools and applications related to Web development, let us install PHP tools and other popular tools and appilcation, including Drupal, WordPress, Joomla! etc.,  and it does not involve installation of Apache server.  All are installed under IIS.
Frankly, I am overwhelmed.   There is a lot to learn for this HTML, CCS and javaScript only Sunday web developer to grasp the whole new array of tools. It must be a good thing that I am not restricted to aps.net metaphor.

blogger.com のftpサポートの中止

blogger.comからメールが来てftpによるpublishingをやめるとのこと。 これがよくてこのプロバイダーにしたのだが、よくよく考えてみると、テンプレートは普通のhtmlで記述できるのでurlがコムキャストからblogspot.comに変わるだけだった。 というわけで早速移動した。 

手間がかかるのがすべてのページのリンクを変更しなければいけないこと。 これがあるからサーバーサイドインクルードかクライエントサイドインクルードを考えなければいけないんだろうなあ。

Changed the header

Changed the header image of the home page from the image that was on the net to my wife’s collection of paint drawings.   This is much more personal.
ヘッダーのイメージを嫁さんの水彩画にしてみました。 ぐっとパーソナルな雰囲気です。