util.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /* scriversi le cose nel local storage*/
  2. function initStorage() {
  3. try {
  4. return 'localStorage' in window && window.localStorage !== null;
  5. } catch (e) {
  6. return false;
  7. }
  8. }
  9. /*per network info*/
  10. function checkConnection(code, msgConnect, print) {
  11. var msgTitle = "Non sei connesso";
  12. msgConnect = msgConnect || "Occore essere connessi per poter ricevere i nuovi articoli";
  13. var networkState = navigator.connection.type;
  14. var states = {};
  15. states[Connection.UNKNOWN] = 'Unknown connection';
  16. states[Connection.ETHERNET] = 'Ethernet connection';
  17. states[Connection.WIFI] = 'WiFi connection';
  18. states[Connection.CELL_2G] = 'Cell 2G connection';
  19. states[Connection.CELL_3G] = 'Cell 3G connection';
  20. states[Connection.CELL_4G] = 'Cell 4G connection';
  21. states[Connection.CELL] = 'Cell generic connection';
  22. states[Connection.NONE] = 'No network connection';
  23. if (states[networkState] == 'Unknown connection' || states[networkState] == 'No network connection') {
  24. if(! print)
  25. toastr.warning(msgConnect, msgTitle);
  26. console.log(code);
  27. return false;
  28. } else {
  29. return true;
  30. }
  31. }
  32. var getObjKey = function(obj, val) {
  33. var key = null;
  34. for(var k in obj){
  35. if(obj[k] == val){
  36. key = k;
  37. break;
  38. }
  39. }
  40. return key;
  41. };
  42. function entityToHtml(string) {
  43. for (var i in entity_table) {
  44. if (i != 38) {
  45. string = string.replace(new RegExp(entity_table[i], "g"), String.fromCharCode(i));
  46. }
  47. }
  48. string = string.replace(new RegExp("&#(x?)(\\d+);", "g"), function(match, p1, p2, string) {
  49. return String.fromCharCode(((p1 == 'x') ? parseInt(p2, 16) : p2));
  50. });
  51. string = string.replace(new RegExp(entity_table[38], "g"), String.fromCharCode(38));
  52. return string;
  53. }
  54. var entity_table = {
  55. // 34: """, // Quotation mark. Not required
  56. 38: "&", // Ampersand. Applied before everything else in the application
  57. 60: "<", // Less-than sign
  58. 62: ">", // Greater-than sign
  59. // 63: "?", // Question mark
  60. // 111: "o", // Latin small letter o
  61. 160: " ", // Non-breaking space
  62. 161: "¡", // Inverted exclamation mark
  63. 162: "¢", // Cent sign
  64. 163: "£", // Pound sign
  65. 164: "¤", // Currency sign
  66. 165: "¥", // Yen sign
  67. 166: "¦", // Broken vertical bar
  68. 167: "§", // Section sign
  69. 168: "¨", // Diaeresis
  70. 169: "©", // Copyright sign
  71. 170: "ª", // Feminine ordinal indicator
  72. 171: "«", // Left-pointing double angle quotation mark
  73. 172: "¬", // Not sign
  74. 173: "­", // Soft hyphen
  75. 174: "®", // Registered sign
  76. 175: "¯", // Macron
  77. 176: "°", // Degree sign
  78. 177: "±", // Plus-minus sign
  79. 178: "²", // Superscript two
  80. 179: "³", // Superscript three
  81. 180: "´", // Acute accent
  82. 181: "µ", // Micro sign
  83. 182: "¶", // Pilcrow sign
  84. 183: "·", // Middle dot
  85. 184: "¸", // Cedilla
  86. 185: "¹", // Superscript one
  87. 186: "º", // Masculine ordinal indicator
  88. 187: "»", // Right-pointing double angle quotation mark
  89. 188: "¼", // Vulgar fraction one-quarter
  90. 189: "½", // Vulgar fraction one-half
  91. 190: "¾", // Vulgar fraction three-quarters
  92. 191: "¿", // Inverted question mark
  93. 192: "À", // A with grave
  94. 193: "Á", // A with acute
  95. 194: "Â", // A with circumflex
  96. 195: "Ã", // A with tilde
  97. 196: "Ä", // A with diaeresis
  98. 197: "Å", // A with ring above
  99. 198: "Æ", // AE
  100. 199: "Ç", // C with cedilla
  101. 200: "È", // E with grave
  102. 201: "É", // E with acute
  103. 202: "Ê", // E with circumflex
  104. 203: "Ë", // E with diaeresis
  105. 204: "Ì", // I with grave
  106. 205: "Í", // I with acute
  107. 206: "Î", // I with circumflex
  108. 207: "Ï", // I with diaeresis
  109. 208: "Ð", // Eth
  110. 209: "Ñ", // N with tilde
  111. 210: "Ò", // O with grave
  112. 211: "Ó", // O with acute
  113. 212: "Ô", // O with circumflex
  114. 213: "Õ", // O with tilde
  115. 214: "Ö", // O with diaeresis
  116. 215: "×", // Multiplication sign
  117. 216: "Ø", // O with stroke
  118. 217: "Ù", // U with grave
  119. 218: "Ú", // U with acute
  120. 219: "Û", // U with circumflex
  121. 220: "Ü", // U with diaeresis
  122. 221: "Ý", // Y with acute
  123. 222: "Þ", // Thorn
  124. 223: "ß", // Sharp s. Also known as ess-zed
  125. 224: "à", // a with grave
  126. 225: "á", // a with acute
  127. 226: "â", // a with circumflex
  128. 227: "ã", // a with tilde
  129. 228: "ä", // a with diaeresis
  130. 229: "å", // a with ring above
  131. 230: "æ", // ae. Also known as ligature ae
  132. 231: "ç", // c with cedilla
  133. 232: "è", // e with grave
  134. 233: "é", // e with acute
  135. 234: "ê", // e with circumflex
  136. 235: "ë", // e with diaeresis
  137. 236: "ì", // i with grave
  138. 237: "í", // i with acute
  139. 238: "î", // i with circumflex
  140. 239: "ï", // i with diaeresis
  141. 240: "ð", // eth
  142. 241: "ñ", // n with tilde
  143. 242: "ò", // o with grave
  144. 243: "ó", // o with acute
  145. 244: "ô", // o with circumflex
  146. 245: "õ", // o with tilde
  147. 246: "ö", // o with diaeresis
  148. 247: "÷", // Division sign
  149. 248: "ø", // o with stroke. Also known as o with slash
  150. 249: "ù", // u with grave
  151. 250: "ú", // u with acute
  152. 251: "û", // u with circumflex
  153. 252: "ü", // u with diaeresis
  154. 253: "ý", // y with acute
  155. 254: "þ", // thorn
  156. 255: "ÿ", // y with diaeresis
  157. 264: "Ĉ", // Latin capital letter C with circumflex
  158. 265: "ĉ", // Latin small letter c with circumflex
  159. 338: "Œ", // Latin capital ligature OE
  160. 339: "œ", // Latin small ligature oe
  161. 352: "Š", // Latin capital letter S with caron
  162. 353: "š", // Latin small letter s with caron
  163. 372: "Ŵ", // Latin capital letter W with circumflex
  164. 373: "ŵ", // Latin small letter w with circumflex
  165. 374: "Ŷ", // Latin capital letter Y with circumflex
  166. 375: "ŷ", // Latin small letter y with circumflex
  167. 376: "Ÿ", // Latin capital letter Y with diaeresis
  168. 402: "ƒ", // Latin small f with hook, function, florin
  169. 710: "ˆ", // Modifier letter circumflex accent
  170. 732: "˜", // Small tilde
  171. 913: "Α", // Alpha
  172. 914: "Β", // Beta
  173. 915: "Γ", // Gamma
  174. 916: "Δ", // Delta
  175. 917: "Ε", // Epsilon
  176. 918: "Ζ", // Zeta
  177. 919: "Η", // Eta
  178. 920: "Θ", // Theta
  179. 921: "Ι", // Iota
  180. 922: "Κ", // Kappa
  181. 923: "Λ", // Lambda
  182. 924: "Μ", // Mu
  183. 925: "Ν", // Nu
  184. 926: "Ξ", // Xi
  185. 927: "Ο", // Omicron
  186. 928: "Π", // Pi
  187. 929: "Ρ", // Rho
  188. 931: "Σ", // Sigma
  189. 932: "Τ", // Tau
  190. 933: "Υ", // Upsilon
  191. 934: "Φ", // Phi
  192. 935: "Χ", // Chi
  193. 936: "Ψ", // Psi
  194. 937: "Ω", // Omega
  195. 945: "α", // alpha
  196. 946: "β", // beta
  197. 947: "γ", // gamma
  198. 948: "δ", // delta
  199. 949: "ε", // epsilon
  200. 950: "ζ", // zeta
  201. 951: "η", // eta
  202. 952: "θ", // theta
  203. 953: "ι", // iota
  204. 954: "κ", // kappa
  205. 955: "λ", // lambda
  206. 956: "μ", // mu
  207. 957: "ν", // nu
  208. 958: "ξ", // xi
  209. 959: "ο", // omicron
  210. 960: "π", // pi
  211. 961: "ρ", // rho
  212. 962: "ς", // sigmaf
  213. 963: "σ", // sigma
  214. 964: "τ", // tau
  215. 965: "υ", // upsilon
  216. 966: "φ", // phi
  217. 967: "χ", // chi
  218. 968: "ψ", // psi
  219. 969: "ω", // omega
  220. 977: "ϑ", // Theta symbol
  221. 978: "ϒ", // Greek upsilon with hook symbol
  222. 982: "ϖ", // Pi symbol
  223. 8194: " ", // En space
  224. 8195: " ", // Em space
  225. 8201: " ", // Thin space
  226. 8204: "‌", // Zero width non-joiner
  227. 8205: "‍", // Zero width joiner
  228. 8206: "‎", // Left-to-right mark
  229. 8207: "‏", // Right-to-left mark
  230. 8211: "–", // En dash
  231. 8212: "—", // Em dash
  232. 8216: "‘", // Left single quotation mark
  233. 8217: "’", // Right single quotation mark
  234. 8218: "‚", // Single low-9 quotation mark
  235. 8220: "“", // Left double quotation mark
  236. 8221: "”", // Right double quotation mark
  237. 8222: "„", // Double low-9 quotation mark
  238. 8224: "†", // Dagger
  239. 8225: "‡", // Double dagger
  240. 8226: "•", // Bullet
  241. 8230: "…", // Horizontal ellipsis
  242. 8240: "‰", // Per mille sign
  243. 8242: "′", // Prime
  244. 8243: "″", // Double Prime
  245. 8249: "‹", // Single left-pointing angle quotation
  246. 8250: "›", // Single right-pointing angle quotation
  247. 8254: "‾", // Overline
  248. 8260: "⁄", // Fraction Slash
  249. 8364: "€", // Euro sign
  250. 8472: "℘", // Script capital
  251. 8465: "ℑ", // Blackletter capital I
  252. 8476: "ℜ", // Blackletter capital R
  253. 8482: "™", // Trade mark sign
  254. 8501: "ℵ", // Alef symbol
  255. 8592: "←", // Leftward arrow
  256. 8593: "↑", // Upward arrow
  257. 8594: "→", // Rightward arrow
  258. 8595: "↓", // Downward arrow
  259. 8596: "↔", // Left right arrow
  260. 8629: "↵", // Downward arrow with corner leftward. Also known as carriage return
  261. 8656: "⇐", // Leftward double arrow. ISO 10646 does not say that lArr is the same as the 'is implied by' arrow but also does not have any other character for that function. So ? lArr can be used for 'is implied by' as ISOtech suggests
  262. 8657: "⇑", // Upward double arrow
  263. 8658: "⇒", // Rightward double arrow. ISO 10646 does not say this is the 'implies' character but does not have another character with this function so ? rArr can be used for 'implies' as ISOtech suggests
  264. 8659: "⇓", // Downward double arrow
  265. 8660: "⇔", // Left-right double arrow
  266. // Mathematical Operators
  267. 8704: "∀", // For all
  268. 8706: "∂", // Partial differential
  269. 8707: "∃", // There exists
  270. 8709: "∅", // Empty set. Also known as null set and diameter
  271. 8711: "∇", // Nabla. Also known as backward difference
  272. 8712: "∈", // Element of
  273. 8713: "∉", // Not an element of
  274. 8715: "∋", // Contains as member
  275. 8719: "∏", // N-ary product. Also known as product sign. Prod is not the same character as U+03A0 'greek capital letter pi' though the same glyph might be used for both
  276. 8721: "∑", // N-ary summation. Sum is not the same character as U+03A3 'greek capital letter sigma' though the same glyph might be used for both
  277. 8722: "−", // Minus sign
  278. 8727: "∗", // Asterisk operator
  279. 8729: "∙", // Bullet operator
  280. 8730: "√", // Square root. Also known as radical sign
  281. 8733: "∝", // Proportional to
  282. 8734: "∞", // Infinity
  283. 8736: "∠", // Angle
  284. 8743: "∧", // Logical and. Also known as wedge
  285. 8744: "∨", // Logical or. Also known as vee
  286. 8745: "∩", // Intersection. Also known as cap
  287. 8746: "∪", // Union. Also known as cup
  288. 8747: "∫", // Integral
  289. 8756: "∴", // Therefore
  290. 8764: "∼", // tilde operator. Also known as varies with and similar to. The tilde operator is not the same character as the tilde, U+007E, although the same glyph might be used to represent both
  291. 8773: "≅", // Approximately equal to
  292. 8776: "≈", // Almost equal to. Also known as asymptotic to
  293. 8800: "≠", // Not equal to
  294. 8801: "≡", // Identical to
  295. 8804: "≤", // Less-than or equal to
  296. 8805: "≥", // Greater-than or equal to
  297. 8834: "⊂", // Subset of
  298. 8835: "⊃", // Superset of. Note that nsup, 'not a superset of, U+2283' is not covered by the Symbol font encoding and is not included.
  299. 8836: "⊄", // Not a subset of
  300. 8838: "⊆", // Subset of or equal to
  301. 8839: "⊇", // Superset of or equal to
  302. 8853: "⊕", // Circled plus. Also known as direct sum
  303. 8855: "⊗", // Circled times. Also known as vector product
  304. 8869: "⊥", // Up tack. Also known as orthogonal to and perpendicular
  305. 8901: "⋅", // Dot operator. The dot operator is not the same character as U+00B7 middle dot
  306. // Miscellaneous Technical
  307. 8968: "⌈", // Left ceiling. Also known as an APL upstile
  308. 8969: "⌉", // Right ceiling
  309. 8970: "⌊", // left floor. Also known as APL downstile
  310. 8971: "⌋", // Right floor
  311. 9001: "⟨", // Left-pointing angle bracket. Also known as bra. Lang is not the same character as U+003C 'less than'or U+2039 'single left-pointing angle quotation mark'
  312. 9002: "⟩", // Right-pointing angle bracket. Also known as ket. Rang is not the same character as U+003E 'greater than' or U+203A 'single right-pointing angle quotation mark'
  313. // Geometric Shapes
  314. 9642: "▪", // Black small square
  315. 9643: "▫", // White small square
  316. 9674: "◊", // Lozenge
  317. // Miscellaneous Symbols
  318. 9702: "◦", // White bullet
  319. 9824: "♠", // Black (filled) spade suit
  320. 9827: "♣", // Black (filled) club suit. Also known as shamrock
  321. 9829: "♥", // Black (filled) heart suit. Also known as shamrock
  322. 9830: "♦" // Black (filled) diamond suit
  323. };