Skip to content

Instantly share code, notes, and snippets.

@tingwei628
tingwei628 / gist:9417c21c4f87c0e3e955
Last active August 29, 2015 14:21
[JavaScript] Blength()&subBytes()(算中英文字數)
/*
Blength() 是用來計算string 以Byte為單位
subBtyes(str, max)是用來切割Btyes(str:被切割字串, max:最大Bytes數)
例: "我abc我".Blength() = 7
subBtyes("我abc我", 3) // 結果是 我a
*/
String.prototype.Blength = function(){
var str = this.match(/[^\x00-\xff]/ig);
return str === null ? this.length : this.length + str.length;
};
@tingwei628
tingwei628 / gist:36c72d7778026957c6c4
Last active August 29, 2015 14:22
[JavaScript] Checked html-like string
/*
例如 Content = '<div style="background-color: rgba(255, 255, 255, 0.843137);">&nbsp; gg<br>yy<br><br><br>uu<br><br>  ff&nbsp;<br>  u<br></div><div style="background-color: rgba(255, 255, 255, 0.843137);"><br></div><div style="background-color: rgba(255, 255, 255, 0.843137);">&nbsp; i</div> '
此code示範如何將Contne html字串,檢查其有沒有word
註: var str="我是中文字"
(/\w|[^\x00-\xff]/ig).test(str); //回傳是true
*/
var html = $(Content); //jQuery 將字串轉成html
var innertext = null;
//檢查內容每一行有無中英文
@tingwei628
tingwei628 / gist:ebebd51a31498c421af5
Created July 2, 2015 01:41
[JavaScript] 本地預覽圖片(ExtJS)
/*
設image 的本地預覽圖片路徑 url
*/
function setImageSrc() {
var url = '',
file = filefield.fileInputEl.dom.files[0];
if (window.createObjectURL) {
url = window.createObjectURL(file);
} else if (window.URL) { // mozilla(firefox)
url = window.URL.createObjectURL(file);
@tingwei628
tingwei628 / gist:1dfe0b452275fefef821
Created July 14, 2015 17:19
[JavaScript] 讀取Dom 並作排序
/*
目的: 對購物網站項目的價格做排序 (購物網站網址:http://activity.books.com.tw/ps/prog/2601/page/200/category/217234)
方法: 讀取Dom, 並sort()
*/
var all = $('li'); //先取全部的li
var chose = [];
var price = [];
var title =[]
var bookstore = [];
for(var key in all){
@tingwei628
tingwei628 / [JavaScript][ExtJS] Htmleditor validation
Last active August 29, 2015 14:27
[JavaScript][ExtJS] Htmleditor validation (like allowBlank:false)
/* IsValid() 驗證htmleditor 的 value值是否空白,並會排除空白情況
*/
//validate htmleditor
function IsValid(value) {
var div = document.createElement('div'), text;
div.innerHTML = value;
text = div.textContent || div.innerText || "";
return (text.replace(/^\s+|\s+$/gm, '') != "");
}
@tingwei628
tingwei628 / gist:3600d927fb7b2a66baaf
Last active December 7, 2015 09:48
[JavaScript][ExtJS]如何將 ExtJS 的htmleditor 裡面的style 簡單化 (simplify the style inside the htmleditor)
paste: {
element: 'inputEl',
fn: function(event, inputEl) {
var a = add_Content.getValue();
//已過濾表格 儲存在var b
var b = a.replace(/((<td[^>]+)style=".*?">)/ig, function(x) {
return x = x.replace(/style=".*?"/, 'style="border:solid"');
});
@tingwei628
tingwei628 / gist:9277c8026c5be92fb80e
Last active September 16, 2015 06:19
Html converts to img (將html 輸出成img格式)
<!--baseURL 就是 輸出的img src 連結-->
<!--該Html 引用<script type="text/javascript" src="http://html2canvas.hertzen.com/build/html2canvas.js"></script>-->
<!--Ext.getCmp('wincv-1110').el.dom ,即是該html的DOM-->
<!--參考 html2canvas : http://html2canvas.hertzen.com/-->
<script type="text/javascript" src="http://html2canvas.hertzen.com/build/html2canvas.js"></script>
<script>
html2canvas(Ext.getCmp('wincv-1110').el.dom,{onrendered:function(canvas){
var baseURL = canvas.toDataURL("img/png");
console.log(baseURL);
}});
@tingwei628
tingwei628 / gist:aec48c3ade0327ebf240
Last active November 30, 2015 03:40
[Bootstrap-table][JavaScript]利用Bootstrap-Table 配合後端作分頁(With server-side pagination) 並下OData參數
/*
Bootstrap-Table: http://bootstrap-table.wenzhixin.net.cn/documentation/
練習下OData參數,從後端分頁GET資料
*/
$('#table').bootstrapTable({
url: '',//api
cache: false,
contentType: 'application/json',
pageNumber: 1, // 起始第1頁
@tingwei628
tingwei628 / gist:48081b991f0658ae59c5
Last active September 15, 2016 08:35
[ReactJS][Redux]動態增加/刪除陣列內元素
/*
reducer 寫法參考:https://github.com/rackt/redux/blob/master/examples/todos-with-undo/reducers.js
說明: Redux負責儲存 陣列狀態
用Immutable方式
意思是"不要汙染(改變)原本在reducer的舊的state
而是創造一個全新的state回傳, 且舊的state不影響
另外,注意刪減時, Rowt 要有key值
*/
//這是一個 叫做clickAction的Reducer
//初始狀態是state={'rows':[(Rowt)]}; Rowt 是html tag
@tingwei628
tingwei628 / inlinestyle.js
Last active December 15, 2015 07:47
[JavaScript] function converts to inline style when using JSX
/*
React style={{marginRight: spacing + 'em'}} when using JSX
Therefore, it can help you with routine work ....
For example,
var x ="border-top-width: 1px; border-bottom-width: 1px; border-left-width: 1px; width: 150px; right: auto; left: 725px; top: 0px; margin: 0px;"
inlinestyle(x)
//output=> {{borderTopWidth:'1px', BorderbottomWidth:'1px', borderLeftWidth:'1px', width:'150px', right:'auto', left:'725px', top:'0px', margin:'0px'}}
*/
function inlinestyle(x){