This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function my_inspect(object,isExclusive){ | |
| isExclusive = typeof(isExclusive)!= "undefined" ? isExclusive : false | |
| var result=[]; | |
| for(var member in object){ | |
| var type = typeof object[member]; | |
| if(isExclusive){ | |
| if (object.hasOwnProperty(member)) | |
| result.push(member+"["+type+"] : "+object[member]); | |
| } | |
| else{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //運用正規表示法 | |
| function getParameterByName(name) { | |
| var results = RegExp("[\\?&]" + name + "=([^&#]*)").exec(location.search); | |
| return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); | |
| } | |
| //運用一般陣列 | |
| function getParameterByName2(name){ | |
| var object = {}; | |
| var pairs = location.search.substring(1).split("&"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Array.prototype.myEach = function(callback){ | |
| for(i=0;i<this.length;i++){ | |
| callback(this[i]); | |
| } | |
| };//這邊是先定義myEach並且透過prototype指定給Array,讓之後所有的Array都可以用此方法 | |
| [1,2,3,4,5].myEach(function(element){ | |
| console.log(element); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //JS取亂數可以靠random()這方法,回傳是0~1以內的隨機小數 | |
| Math.random(); | |
| //設定可以取回指定範圍內亂數 | |
| function useFloor(min,max){ | |
| return Math.floor(Math.random()*(max-min+1)+min); | |
| } | |
| function useCeil(min,max){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function shuffle(array){ | |
| var myLength = array.length, temp, index | |
| while(myLength > 0){ | |
| index = Math.floor(Math.random()*myLength); | |
| myLength--; //範圍不斷縮減,以防止已改變的成員又做更動 | |
| temp = array[myLength]; | |
| array[myLength] = array[index]; | |
| array[index] = temp; | |
| } | |
| return array; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Array.prototype.select = function(callback){ | |
| count = this.length; | |
| results = new Array(); | |
| for(i=0;i<count;i++){ | |
| if(callback(this[i])) | |
| results.push(this[i]); | |
| } | |
| return results; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Without turbolinks, it works fine! | |
| $(document).ready(function(){ | |
| formmodified=0; | |
| $('form *').change(function(){ | |
| formmodified=1; | |
| }); | |
| window.onbeforeunload = confirmExit; | |
| function confirmExit() { | |
| if (formmodified == 1) { | |
| return "資料有做修改,確定直接離開頁面嗎?"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var jq = document.createElement('script'); | |
| jq.src = "http://code.jquery.com/jquery-latest.min.js"; | |
| document.getElementByTagName('head')[0].appendChild(jq); | |
| //Done! Really simple as you imagine! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var text = 'there are a lot of great websites like www.missingmanuals.com and http://www.noelsaga.com' | |
| var urlRegex = /((\bhttps?:\/\/)|(\bwww\.))\S*/g | |
| var url = text.match(urlRegex) | |
| console.log(url[0]) | |
| console.log(url[1]); | |
| //看看兩者的差異 | |
| var text2 = 'my website is www.noelsaga.com' | |
| var urlRegex2 = /((\bhttps?:\/\/)|(\bwww\.))\S*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def checkout | |
| m = @merchant_data | |
| seller_id = m["_id"] | |
| unfulfillable_items = get_invalid_cart_items | |
| if unfulfillable_items.present? | |
| render status: :unprocessable_entity, json: { message: I18n.t('orders.error.fulfillment_error'), data: unfulfillable_items} | |
| return | |
| end | |
| delivery_option_id = params.fetchpath("order/delivery_option/_id") |
OlderNewer