util.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. function getImageUrl(str, dim) {
  55. var sstr = str.split(";");
  56. for(var i = 0; i < sstr.length; i++) {
  57. if(sstr[i].indexOf(dim) > -1){
  58. return sstr[i +1];
  59. }
  60. }
  61. }
  62. var entity_table = {
  63. // 34: "&quot;", // Quotation mark. Not required
  64. 38: "&amp;", // Ampersand. Applied before everything else in the application
  65. 60: "&lt;", // Less-than sign
  66. 62: "&gt;", // Greater-than sign
  67. // 63: "&#63;", // Question mark
  68. // 111: "&#111;", // Latin small letter o
  69. 160: "&nbsp;", // Non-breaking space
  70. 161: "&iexcl;", // Inverted exclamation mark
  71. 162: "&cent;", // Cent sign
  72. 163: "&pound;", // Pound sign
  73. 164: "&curren;", // Currency sign
  74. 165: "&yen;", // Yen sign
  75. 166: "&brvbar;", // Broken vertical bar
  76. 167: "&sect;", // Section sign
  77. 168: "&uml;", // Diaeresis
  78. 169: "&copy;", // Copyright sign
  79. 170: "&ordf;", // Feminine ordinal indicator
  80. 171: "&laquo;", // Left-pointing double angle quotation mark
  81. 172: "&not;", // Not sign
  82. 173: "&shy;", // Soft hyphen
  83. 174: "&reg;", // Registered sign
  84. 175: "&macr;", // Macron
  85. 176: "&deg;", // Degree sign
  86. 177: "&plusmn;", // Plus-minus sign
  87. 178: "&sup2;", // Superscript two
  88. 179: "&sup3;", // Superscript three
  89. 180: "&acute;", // Acute accent
  90. 181: "&micro;", // Micro sign
  91. 182: "&para;", // Pilcrow sign
  92. 183: "&middot;", // Middle dot
  93. 184: "&cedil;", // Cedilla
  94. 185: "&sup1;", // Superscript one
  95. 186: "&ordm;", // Masculine ordinal indicator
  96. 187: "&raquo;", // Right-pointing double angle quotation mark
  97. 188: "&frac14;", // Vulgar fraction one-quarter
  98. 189: "&frac12;", // Vulgar fraction one-half
  99. 190: "&frac34;", // Vulgar fraction three-quarters
  100. 191: "&iquest;", // Inverted question mark
  101. 192: "&Agrave;", // A with grave
  102. 193: "&Aacute;", // A with acute
  103. 194: "&Acirc;", // A with circumflex
  104. 195: "&Atilde;", // A with tilde
  105. 196: "&Auml;", // A with diaeresis
  106. 197: "&Aring;", // A with ring above
  107. 198: "&AElig;", // AE
  108. 199: "&Ccedil;", // C with cedilla
  109. 200: "&Egrave;", // E with grave
  110. 201: "&Eacute;", // E with acute
  111. 202: "&Ecirc;", // E with circumflex
  112. 203: "&Euml;", // E with diaeresis
  113. 204: "&Igrave;", // I with grave
  114. 205: "&Iacute;", // I with acute
  115. 206: "&Icirc;", // I with circumflex
  116. 207: "&Iuml;", // I with diaeresis
  117. 208: "&ETH;", // Eth
  118. 209: "&Ntilde;", // N with tilde
  119. 210: "&Ograve;", // O with grave
  120. 211: "&Oacute;", // O with acute
  121. 212: "&Ocirc;", // O with circumflex
  122. 213: "&Otilde;", // O with tilde
  123. 214: "&Ouml;", // O with diaeresis
  124. 215: "&times;", // Multiplication sign
  125. 216: "&Oslash;", // O with stroke
  126. 217: "&Ugrave;", // U with grave
  127. 218: "&Uacute;", // U with acute
  128. 219: "&Ucirc;", // U with circumflex
  129. 220: "&Uuml;", // U with diaeresis
  130. 221: "&Yacute;", // Y with acute
  131. 222: "&THORN;", // Thorn
  132. 223: "&szlig;", // Sharp s. Also known as ess-zed
  133. 224: "&agrave;", // a with grave
  134. 225: "&aacute;", // a with acute
  135. 226: "&acirc;", // a with circumflex
  136. 227: "&atilde;", // a with tilde
  137. 228: "&auml;", // a with diaeresis
  138. 229: "&aring;", // a with ring above
  139. 230: "&aelig;", // ae. Also known as ligature ae
  140. 231: "&ccedil;", // c with cedilla
  141. 232: "&egrave;", // e with grave
  142. 233: "&eacute;", // e with acute
  143. 234: "&ecirc;", // e with circumflex
  144. 235: "&euml;", // e with diaeresis
  145. 236: "&igrave;", // i with grave
  146. 237: "&iacute;", // i with acute
  147. 238: "&icirc;", // i with circumflex
  148. 239: "&iuml;", // i with diaeresis
  149. 240: "&eth;", // eth
  150. 241: "&ntilde;", // n with tilde
  151. 242: "&ograve;", // o with grave
  152. 243: "&oacute;", // o with acute
  153. 244: "&ocirc;", // o with circumflex
  154. 245: "&otilde;", // o with tilde
  155. 246: "&ouml;", // o with diaeresis
  156. 247: "&divide;", // Division sign
  157. 248: "&oslash;", // o with stroke. Also known as o with slash
  158. 249: "&ugrave;", // u with grave
  159. 250: "&uacute;", // u with acute
  160. 251: "&ucirc;", // u with circumflex
  161. 252: "&uuml;", // u with diaeresis
  162. 253: "&yacute;", // y with acute
  163. 254: "&thorn;", // thorn
  164. 255: "&yuml;", // y with diaeresis
  165. 264: "&#264;", // Latin capital letter C with circumflex
  166. 265: "&#265;", // Latin small letter c with circumflex
  167. 338: "&OElig;", // Latin capital ligature OE
  168. 339: "&oelig;", // Latin small ligature oe
  169. 352: "&Scaron;", // Latin capital letter S with caron
  170. 353: "&scaron;", // Latin small letter s with caron
  171. 372: "&#372;", // Latin capital letter W with circumflex
  172. 373: "&#373;", // Latin small letter w with circumflex
  173. 374: "&#374;", // Latin capital letter Y with circumflex
  174. 375: "&#375;", // Latin small letter y with circumflex
  175. 376: "&Yuml;", // Latin capital letter Y with diaeresis
  176. 402: "&fnof;", // Latin small f with hook, function, florin
  177. 710: "&circ;", // Modifier letter circumflex accent
  178. 732: "&tilde;", // Small tilde
  179. 913: "&Alpha;", // Alpha
  180. 914: "&Beta;", // Beta
  181. 915: "&Gamma;", // Gamma
  182. 916: "&Delta;", // Delta
  183. 917: "&Epsilon;", // Epsilon
  184. 918: "&Zeta;", // Zeta
  185. 919: "&Eta;", // Eta
  186. 920: "&Theta;", // Theta
  187. 921: "&Iota;", // Iota
  188. 922: "&Kappa;", // Kappa
  189. 923: "&Lambda;", // Lambda
  190. 924: "&Mu;", // Mu
  191. 925: "&Nu;", // Nu
  192. 926: "&Xi;", // Xi
  193. 927: "&Omicron;", // Omicron
  194. 928: "&Pi;", // Pi
  195. 929: "&Rho;", // Rho
  196. 931: "&Sigma;", // Sigma
  197. 932: "&Tau;", // Tau
  198. 933: "&Upsilon;", // Upsilon
  199. 934: "&Phi;", // Phi
  200. 935: "&Chi;", // Chi
  201. 936: "&Psi;", // Psi
  202. 937: "&Omega;", // Omega
  203. 945: "&alpha;", // alpha
  204. 946: "&beta;", // beta
  205. 947: "&gamma;", // gamma
  206. 948: "&delta;", // delta
  207. 949: "&epsilon;", // epsilon
  208. 950: "&zeta;", // zeta
  209. 951: "&eta;", // eta
  210. 952: "&theta;", // theta
  211. 953: "&iota;", // iota
  212. 954: "&kappa;", // kappa
  213. 955: "&lambda;", // lambda
  214. 956: "&mu;", // mu
  215. 957: "&nu;", // nu
  216. 958: "&xi;", // xi
  217. 959: "&omicron;", // omicron
  218. 960: "&pi;", // pi
  219. 961: "&rho;", // rho
  220. 962: "&sigmaf;", // sigmaf
  221. 963: "&sigma;", // sigma
  222. 964: "&tau;", // tau
  223. 965: "&upsilon;", // upsilon
  224. 966: "&phi;", // phi
  225. 967: "&chi;", // chi
  226. 968: "&psi;", // psi
  227. 969: "&omega;", // omega
  228. 977: "&thetasym;", // Theta symbol
  229. 978: "&upsih;", // Greek upsilon with hook symbol
  230. 982: "&piv;", // Pi symbol
  231. 8194: "&ensp;", // En space
  232. 8195: "&emsp;", // Em space
  233. 8201: "&thinsp;", // Thin space
  234. 8204: "&zwnj;", // Zero width non-joiner
  235. 8205: "&zwj;", // Zero width joiner
  236. 8206: "&lrm;", // Left-to-right mark
  237. 8207: "&rlm;", // Right-to-left mark
  238. 8211: "&ndash;", // En dash
  239. 8212: "&mdash;", // Em dash
  240. 8216: "&lsquo;", // Left single quotation mark
  241. 8217: "&rsquo;", // Right single quotation mark
  242. 8218: "&sbquo;", // Single low-9 quotation mark
  243. 8220: "&ldquo;", // Left double quotation mark
  244. 8221: "&rdquo;", // Right double quotation mark
  245. 8222: "&bdquo;", // Double low-9 quotation mark
  246. 8224: "&dagger;", // Dagger
  247. 8225: "&Dagger;", // Double dagger
  248. 8226: "&bull;", // Bullet
  249. 8230: "&hellip;", // Horizontal ellipsis
  250. 8240: "&permil;", // Per mille sign
  251. 8242: "&prime;", // Prime
  252. 8243: "&Prime;", // Double Prime
  253. 8249: "&lsaquo;", // Single left-pointing angle quotation
  254. 8250: "&rsaquo;", // Single right-pointing angle quotation
  255. 8254: "&oline;", // Overline
  256. 8260: "&frasl;", // Fraction Slash
  257. 8364: "&euro;", // Euro sign
  258. 8472: "&weierp;", // Script capital
  259. 8465: "&image;", // Blackletter capital I
  260. 8476: "&real;", // Blackletter capital R
  261. 8482: "&trade;", // Trade mark sign
  262. 8501: "&alefsym;", // Alef symbol
  263. 8592: "&larr;", // Leftward arrow
  264. 8593: "&uarr;", // Upward arrow
  265. 8594: "&rarr;", // Rightward arrow
  266. 8595: "&darr;", // Downward arrow
  267. 8596: "&harr;", // Left right arrow
  268. 8629: "&crarr;", // Downward arrow with corner leftward. Also known as carriage return
  269. 8656: "&lArr;", // 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
  270. 8657: "&uArr;", // Upward double arrow
  271. 8658: "&rArr;", // 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
  272. 8659: "&dArr;", // Downward double arrow
  273. 8660: "&hArr;", // Left-right double arrow
  274. // Mathematical Operators
  275. 8704: "&forall;", // For all
  276. 8706: "&part;", // Partial differential
  277. 8707: "&exist;", // There exists
  278. 8709: "&empty;", // Empty set. Also known as null set and diameter
  279. 8711: "&nabla;", // Nabla. Also known as backward difference
  280. 8712: "&isin;", // Element of
  281. 8713: "&notin;", // Not an element of
  282. 8715: "&ni;", // Contains as member
  283. 8719: "&prod;", // 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
  284. 8721: "&sum;", // 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
  285. 8722: "&minus;", // Minus sign
  286. 8727: "&lowast;", // Asterisk operator
  287. 8729: "&#8729;", // Bullet operator
  288. 8730: "&radic;", // Square root. Also known as radical sign
  289. 8733: "&prop;", // Proportional to
  290. 8734: "&infin;", // Infinity
  291. 8736: "&ang;", // Angle
  292. 8743: "&and;", // Logical and. Also known as wedge
  293. 8744: "&or;", // Logical or. Also known as vee
  294. 8745: "&cap;", // Intersection. Also known as cap
  295. 8746: "&cup;", // Union. Also known as cup
  296. 8747: "&int;", // Integral
  297. 8756: "&there4;", // Therefore
  298. 8764: "&sim;", // 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
  299. 8773: "&cong;", // Approximately equal to
  300. 8776: "&asymp;", // Almost equal to. Also known as asymptotic to
  301. 8800: "&ne;", // Not equal to
  302. 8801: "&equiv;", // Identical to
  303. 8804: "&le;", // Less-than or equal to
  304. 8805: "&ge;", // Greater-than or equal to
  305. 8834: "&sub;", // Subset of
  306. 8835: "&sup;", // Superset of. Note that nsup, 'not a superset of, U+2283' is not covered by the Symbol font encoding and is not included.
  307. 8836: "&nsub;", // Not a subset of
  308. 8838: "&sube;", // Subset of or equal to
  309. 8839: "&supe;", // Superset of or equal to
  310. 8853: "&oplus;", // Circled plus. Also known as direct sum
  311. 8855: "&otimes;", // Circled times. Also known as vector product
  312. 8869: "&perp;", // Up tack. Also known as orthogonal to and perpendicular
  313. 8901: "&sdot;", // Dot operator. The dot operator is not the same character as U+00B7 middle dot
  314. // Miscellaneous Technical
  315. 8968: "&lceil;", // Left ceiling. Also known as an APL upstile
  316. 8969: "&rceil;", // Right ceiling
  317. 8970: "&lfloor;", // left floor. Also known as APL downstile
  318. 8971: "&rfloor;", // Right floor
  319. 9001: "&lang;", // 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'
  320. 9002: "&rang;", // 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'
  321. // Geometric Shapes
  322. 9642: "&#9642;", // Black small square
  323. 9643: "&#9643;", // White small square
  324. 9674: "&loz;", // Lozenge
  325. // Miscellaneous Symbols
  326. 9702: "&#9702;", // White bullet
  327. 9824: "&spades;", // Black (filled) spade suit
  328. 9827: "&clubs;", // Black (filled) club suit. Also known as shamrock
  329. 9829: "&hearts;", // Black (filled) heart suit. Also known as shamrock
  330. 9830: "&diams;" // Black (filled) diamond suit
  331. };