1(function (global) { 2 3 //namespace 4 5 var ns = function (name) { 6 var namespaces = name.split('.'); 7 var obj = global; 8 while (namespaces.length > 0) { 9 var segment = namespaces.pop(); 10 if (typeof obj[segment] === 'undefined') { 11 obj[segment] = {}; 12 } 13 if (typeof obj[segment] !== 'object') { 14 // do nothing 15 return null; 16 } 17 obj = obj[segment]; 18 }; 19 return obj; 20 }; 21 22 // can not remove jp.naver.line.media for old snippets 23 if (!ns('media_line_me') || !ns('media.line.naver.jp')) { 24 return; 25 } 26 27 // util 28 var $ = { 29 bind: function (obj, type, fn) { 30 obj.addEventListener ? 31 obj.addEventListener(type, fn, false) : 32 obj.attachEvent('on' + type, fn); 33 }, 34 getThisScriptElement: function () { 35 // returns caller script element node if it is called in loading 36 var scripts = document.getElementsByTagName('script'); 37 return scripts[scripts.length - 1]; 38 }, 39 each: function (array, fn) { 40 for (var i = 0, l = array.length; i < l; i++) { 41 var r = fn(i, array[i], array); 42 if (r === false) { return; } 43 } 44 }, 45 attr: function (el, obj) { 46 for (var key in obj) { 47 el.setAttribute(key, obj[key]); 48 } 49 }, 50 map: function (array, fn) { 51 var res = []; 52 $.each(array, function (i, v, a) { 53 res.push(fn(i, v, a)); 54 }); 55 return res; 56 }, 57 filter: function (array, fn) { 58 var res = []; 59 $.each(array, function (i, v, a) { 60 if (fn(i, v, a)) { res.push(v) }; 61 }); 62 return res; 63 }, 64 ready: function (fn) { 65 $.bind(window, 'load', fn); 66 }, 67 isSmartphone: function () { 68 return navigator.userAgent.match(/(iPhone|iPod|iPad|Android)/i); 69 } 70 }; 71 72 var lineButton = { 73 constant: { 74 LINE_BASE_URL: '//line.me/R/msg/text/', 75 IMG_BASE_URL: '//media.line.me/img/button/', 76 ALT: { ja: 'LINE\u3067\u9001\u308b', 77 en: 'LINE it!', 78 'zh-hans': 'LINE it!', 79 'zh-hant': 'LINE it!' 80 }, 81 // width, height 82 IMG_SIZE: { ja: { a: [82, 20], b: [20, 20], c: [30, 30], d: [40, 40], e: [36, 60] }, 83 en: { a: [78, 20], b: [20, 20], c: [30, 30], d: [40, 40], e: [36, 60] }, 84 'zh-hans': { a: [84, 20], b: [20, 20], c: [30, 30], d: [40, 40], e: [36, 60] }, 85 'zh-hant': { a: [84, 20], b: [20, 20], c: [30, 30], d: [40, 40], e: [36, 60] } 86 } 87 }, 88 89 insertButton: function (argOption, scriptParent, script) { 90 91 var self = this; 92 var option = self.validate(argOption); 93 if (!(option.pc || $.isSmartphone())) { 94 return; 95 } 96 97 98 var s = (script.parentNode === scriptParent) ? script : undefined; 99 100 scriptParent.insertBefore(self.createTag(option), s); 101 }, 102 103 validate: function (argOption) { 104 var self = this; 105 var pattern = { lang: /^(ja|en|zh-han[st])$/, 106 type: /^(a|b|c|d|e)$/, 107 text: /^[\s\S]+$/ 108 }; 109 //default 110 var option = { lang: 'ja', type: 'a', text: null }; 111 if (!argOption) { 112 return option; 113 } 114 for (var key in option) { 115 if (argOption[key] 116 && typeof argOption[key] === 'string' 117 && argOption[key].match(pattern[key])) { 118 option[key] = argOption[key]; 119 } 120 } 121 122 option.withUrl = !!argOption.withUrl; 123 option.pc = !!argOption.pc; 124 125 return option; 126 }, 127 128 createTag: function (option) { 129 var self = this; 130 var size = self.constant.IMG_SIZE[option.lang][option.type]; 131 132 /* 133 <a href="{url}"> 134 <img src="{img}" alt="{alt}" height="{height}" width="{width}"/> 135 </a> 136 */ 137 var a = document.createElement('a'); 138 $.attr(a, { href: self.createUrl(option) }); 139 var img = document.createElement('img'); 140 $.attr(img, 141 { src: self.createImageUrl(option), 142 width: size[0], 143 height: size[1], 144 alt: self.constant.ALT[option.lang] 145 }); 146 147 a.appendChild(img); 148 149 return a; 150 }, 151 152 createUrl: function (option) { 153 var self = this; 154 var text = self.text(option); 155 return [self.constant.LINE_BASE_URL, 156 encodeURIComponent(text).replace(/\+/g, '%20') 157 ].join('?'); 158 }, 159 160 text: function (option) { 161 var text; 162 if (option.text) { 163 text = [option.text]; 164 if (option.withUrl) { 165 text.push(document.location.href); 166 } 167 } else { 168 text = [document.title, document.location.href]; 169 } 170 return text.join('\n'); 171 }, 172 173 createImageUrl: function (option) { 174 var self = this; 175 var C = self.constant; 176 var size = C.IMG_SIZE[option.lang][option.type]; 177 return [C.IMG_BASE_URL, 178 option.lang, '/', 179 size[0], 'x', size[1], '.png'].join(''); 180 } 181 }; 182 183 global.media_line_me.LineButton = global.jp.naver.line.media.LineButton = function (option, parentId) { 184 // for jQuery Mobile 185 // It cannot move with document.write() 186 // and it removes script tag... 187 var script = $.getThisScriptElement(); 188 var scriptParent = script.parentNode; 189 190 if (parentId != null) { 191 scriptParent = document.getElementById(parentId); 192 } 193 if (scriptParent.tagName.toLowerCase() !== 'head') { 194 $.ready(function () { 195 lineButton.insertButton(option, scriptParent, script); 196 }); 197 } 198 }; 199 200})(this);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.