@zykjcommon/questions 0.0.66 → 0.0.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24980,6 +24980,414 @@ var state = {
24980
24980
  }
24981
24981
  }
24982
24982
  });
24983
+ ;// CONCATENATED MODULE: ./src/assets/js/json2html.js
24984
+
24985
+
24986
+
24987
+
24988
+
24989
+
24990
+
24991
+
24992
+
24993
+
24994
+
24995
+
24996
+ //Copyright (c) 2018 Crystalline Technologies
24997
+ //
24998
+ // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'),
24999
+ // to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
25000
+ // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
25001
+ //
25002
+ // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
25003
+ //
25004
+ // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25005
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25006
+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25007
+ var json2html = {
25008
+ /* ---------------------------------------- Public Methods ------------------------------------------------ */
25009
+ 'transform': function transform(json, _transform2, _options) {
25010
+ //create the default output
25011
+ var out = {
25012
+ 'events': [],
25013
+ 'html': ''
25014
+ };
25015
+
25016
+ //default options (by default we don't allow events)
25017
+ var options = {
25018
+ 'events': false
25019
+ };
25020
+
25021
+ //extend the options
25022
+ options = json2html._extend(options, _options);
25023
+
25024
+ //Make sure we have a transform & json object
25025
+ if (_transform2 !== undefined || json !== undefined) {
25026
+ //Normalize strings to JSON objects if necessary
25027
+ var obj = typeof json === 'string' ? JSON.parse(json) : json;
25028
+
25029
+ //Transform the object (using the options)
25030
+ out = json2html._transform(obj, _transform2, options);
25031
+ }
25032
+
25033
+ //determine if we need the events
25034
+ // otherwise return just the html string
25035
+ if (options.events) return out;else return out.html;
25036
+ },
25037
+ /* ---------------------------------------- Private Methods ------------------------------------------------ */
25038
+
25039
+ //Extend options
25040
+ '_extend': function _extend(obj1, obj2) {
25041
+ var obj3 = {};
25042
+ for (var attrname in obj1) {
25043
+ obj3[attrname] = obj1[attrname];
25044
+ }
25045
+ for (var attrname in obj2) {
25046
+ obj3[attrname] = obj2[attrname];
25047
+ }
25048
+ return obj3;
25049
+ },
25050
+ //Append results
25051
+ '_append': function _append(obj1, obj2) {
25052
+ var out = {
25053
+ 'html': '',
25054
+ 'event': []
25055
+ };
25056
+ if (typeof obj1 !== 'undefined' && typeof obj2 !== 'undefined') {
25057
+ out.html = obj1.html + obj2.html;
25058
+ out.events = obj1.events.concat(obj2.events);
25059
+ }
25060
+ return out;
25061
+ },
25062
+ //isArray (fix for IE prior to 9)
25063
+ '_isArray': function _isArray(obj) {
25064
+ return Object.prototype.toString.call(obj) === '[object Array]';
25065
+ },
25066
+ //Transform object
25067
+ '_transform': function _transform(json, transform, options) {
25068
+ var elements = {
25069
+ 'events': [],
25070
+ 'html': ''
25071
+ };
25072
+
25073
+ //Determine the type of this object
25074
+ if (json2html._isArray(json)) {
25075
+ //Itterrate through the array and add it to the elements array
25076
+ var len = json.length;
25077
+ for (var j = 0; j < len; ++j) {
25078
+ //Apply the transform to this object and append it to the results
25079
+ elements = json2html._append(elements, json2html._apply(json[j], transform, j, options));
25080
+ }
25081
+ } else if (_typeof(json) === 'object') {
25082
+ //Apply the transform to this object and append it to the results
25083
+ elements = json2html._append(elements, json2html._apply(json, transform, undefined, options));
25084
+ }
25085
+
25086
+ //Return the resulting elements
25087
+ return elements;
25088
+ },
25089
+ //Apply the transform at the second level
25090
+ '_apply': function _apply(obj, transform, index, options) {
25091
+ var element = {
25092
+ 'events': [],
25093
+ 'html': ''
25094
+ };
25095
+
25096
+ //Itterate through the transform and create html as needed
25097
+ if (json2html._isArray(transform)) {
25098
+ var t_len = transform.length;
25099
+ for (var t = 0; t < t_len; ++t) {
25100
+ //transform the object and append it to the output
25101
+ element = json2html._append(element, json2html._apply(obj, transform[t], index, options));
25102
+ }
25103
+ } else if (_typeof(transform) === 'object') {
25104
+ var _element = '<>';
25105
+
25106
+ //Add legacy support for tag
25107
+ if (transform[_element] === undefined) _element = 'tag';
25108
+
25109
+ //Check to see if we have a valid element name
25110
+ if (transform[_element] !== undefined) {
25111
+ //Get the element name (this can be tokenized)
25112
+ var name = json2html._getValue(obj, transform, _element, index);
25113
+
25114
+ //Create a new element
25115
+ element.html += '<' + name;
25116
+
25117
+ //Create a new object for the children
25118
+ var children = {
25119
+ 'events': [],
25120
+ 'html': ''
25121
+ };
25122
+
25123
+ //innerHTML
25124
+ var html;
25125
+
25126
+ //Look into the properties of this transform
25127
+ for (var key in transform) {
25128
+ switch (key) {
25129
+ //DEPRECATED (use <> instead)
25130
+ case 'tag':
25131
+
25132
+ //HTML element to render
25133
+ case '<>':
25134
+ //Do nothing as we have already created the element
25135
+ break;
25136
+
25137
+ //Encode as text
25138
+ case 'text':
25139
+ //Get the transform value associated with this key
25140
+ var _transform = transform[key];
25141
+
25142
+ //Determine what kind of object this is
25143
+ // array => NOT SUPPORTED
25144
+ // other => text
25145
+ if (json2html._isArray(_transform)) {
25146
+ //NOT Supported
25147
+ } else if (typeof _transform === 'function') {
25148
+ //Get the result from the function
25149
+ var temp = _transform.call(obj, obj, index);
25150
+
25151
+ //Don't allow arrays as return objects from functions
25152
+ if (!json2html._isArray(temp)) {
25153
+ //Determine what type of object was returned
25154
+ switch (_typeof(temp)) {
25155
+ //Not supported for text
25156
+ case 'function':
25157
+ case 'undefined':
25158
+ case 'object':
25159
+ break;
25160
+
25161
+ //Append as text
25162
+ // string, number, boolean
25163
+ default:
25164
+ //Insure we encode as text first
25165
+ children.html += json2html.toText(temp);
25166
+ break;
25167
+ }
25168
+ }
25169
+ } else {
25170
+ //Get the encoded text associated with this element
25171
+ html = json2html.toText(json2html._getValue(obj, transform, key, index));
25172
+ }
25173
+ break;
25174
+
25175
+ //DEPRECATED (use HTML instead)
25176
+ case 'children':
25177
+
25178
+ //Encode as HTML
25179
+ // accepts Array of children, functions, string, number, boolean
25180
+ case 'html':
25181
+ //Get the transform value associated with this key
25182
+ // added as key could be children or html
25183
+ var _transform = transform[key];
25184
+
25185
+ //Determine what kind of object this is
25186
+ // array & function => children
25187
+ // other => html
25188
+ if (json2html._isArray(_transform)) {
25189
+ //Apply the transform to the children
25190
+ children = json2html._append(children, json2html._apply(obj, _transform, index, options));
25191
+ } else if (typeof _transform === 'function') {
25192
+ //Get the result from the function
25193
+ var temp = _transform.call(obj, obj, index);
25194
+
25195
+ //Don't allow arrays as return objects from functions
25196
+ if (!json2html._isArray(temp)) {
25197
+ //Determine what type of object was returned
25198
+ switch (_typeof(temp)) {
25199
+ //Only returned by json2html.transform or $.json2html calls
25200
+ case 'object':
25201
+ //make sure this object is a valid json2html response object
25202
+ // we ignore all other objects (since we don't know how to represent them in html)
25203
+ if (temp.html !== undefined && temp.events !== undefined) children = json2html._append(children, temp);
25204
+ break;
25205
+
25206
+ //Not supported
25207
+ case 'function':
25208
+ case 'undefined':
25209
+ break;
25210
+
25211
+ //Append to html
25212
+ // string, number, boolean
25213
+ default:
25214
+ children.html += temp;
25215
+ break;
25216
+ }
25217
+ }
25218
+ } else {
25219
+ //Get the HTML associated with this element
25220
+ html = json2html._getValue(obj, transform, key, index);
25221
+ }
25222
+ break;
25223
+ default:
25224
+ //Add the property as a attribute if it's not a key one
25225
+ var isEvent = false;
25226
+
25227
+ //Check if the first two characters are 'on' then this is an event
25228
+ if (key.length > 2) if (key.substring(0, 2).toLowerCase() == 'on') {
25229
+ //Determine if we should add events
25230
+ if (options.events) {
25231
+ //if so then setup the event data
25232
+ var data = {
25233
+ 'action': transform[key],
25234
+ 'obj': obj,
25235
+ 'data': options.eventData,
25236
+ 'index': index
25237
+ };
25238
+
25239
+ //create a new id for this event
25240
+ var id = json2html._guid();
25241
+
25242
+ //append the new event to this elements events
25243
+ element.events[element.events.length] = {
25244
+ 'id': id,
25245
+ 'type': key.substring(2),
25246
+ 'data': data
25247
+ };
25248
+
25249
+ //Insert temporary event property (json2html-event-id) into the element
25250
+ element.html += " json2html-event-id-" + key.substring(2) + "='" + id + "'";
25251
+ }
25252
+ //this is an event
25253
+ isEvent = true;
25254
+ }
25255
+
25256
+ //If this wasn't an event AND we actually have a value then add it as a property
25257
+ if (!isEvent) {
25258
+ //Get the value
25259
+ var val = json2html._getValue(obj, transform, key, index);
25260
+
25261
+ //Make sure we have a value
25262
+ if (val !== undefined) {
25263
+ var out;
25264
+
25265
+ //Determine the output type of this value (wrap with quotes)
25266
+ if (typeof val === 'string') out = '"' + val.replace(/"/g, '&quot;') + '"';else out = val;
25267
+
25268
+ //create the name value pair
25269
+ element.html += ' ' + key + '=' + out;
25270
+ }
25271
+ }
25272
+ break;
25273
+ }
25274
+ }
25275
+
25276
+ //close the opening element
25277
+ element.html += '>';
25278
+
25279
+ //add the innerHTML (if we have any)
25280
+ if (html) element.html += html;
25281
+
25282
+ //add the children (if we have any)
25283
+ element = json2html._append(element, children);
25284
+
25285
+ //add the closing element
25286
+ element.html += '</' + name + '>';
25287
+ }
25288
+ }
25289
+
25290
+ //Return the output object
25291
+ return element;
25292
+ },
25293
+ //Get a new GUID (used by events)
25294
+ '_guid': function _guid() {
25295
+ var S4 = function S4() {
25296
+ return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
25297
+ };
25298
+ return S4() + S4() + "-" + S4() + S4() + "-" + S4() + S4();
25299
+ },
25300
+ //Get the html value of the object
25301
+ '_getValue': function _getValue(obj, transform, key, index) {
25302
+ var out = '';
25303
+ var val = transform[key];
25304
+ var type = _typeof(val);
25305
+ if (type === 'function') {
25306
+ return val.call(obj, obj, index);
25307
+ } else if (type === 'string') {
25308
+ var _tokenizer = new json2html._tokenizer([/\$\{([^\}\{]+)\}/], function (src, real, re) {
25309
+ return real ? src.replace(re, function (all, name) {
25310
+ //Split the string into it's seperate components
25311
+ var components = name.split('.');
25312
+
25313
+ //Set the object we use to query for this name to be the original object
25314
+ var useObj = obj;
25315
+
25316
+ //Output value
25317
+ var outVal = '';
25318
+
25319
+ //Parse the object components
25320
+ var c_len = components.length;
25321
+ for (var i = 0; i < c_len; ++i) {
25322
+ if (components[i].length > 0) {
25323
+ var newObj = useObj[components[i]];
25324
+ useObj = newObj;
25325
+ if (useObj === null || useObj === undefined) break;
25326
+ }
25327
+ }
25328
+
25329
+ //As long as we have an object to use then set the out
25330
+ if (useObj !== null && useObj !== undefined) outVal = useObj;
25331
+ return outVal;
25332
+ }) : src;
25333
+ });
25334
+ out = _tokenizer.parse(val).join('');
25335
+ } else {
25336
+ out = val;
25337
+ }
25338
+ return out;
25339
+ },
25340
+ //Encode the html to text
25341
+ 'toText': function toText(html) {
25342
+ return html.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\"/g, '&quot;').replace(/\'/g, '&#39;').replace(/\//g, '&#x2F;');
25343
+ },
25344
+ //Tokenizer
25345
+ '_tokenizer': function _tokenizer(tokenizers, doBuild) {
25346
+ if (!(this instanceof json2html._tokenizer)) return new json2html._tokenizer(tokenizers, doBuild);
25347
+ this.tokenizers = tokenizers.splice ? tokenizers : [tokenizers];
25348
+ if (doBuild) this.doBuild = doBuild;
25349
+ this.parse = function (src) {
25350
+ this.src = src;
25351
+ this.ended = false;
25352
+ this.tokens = [];
25353
+ do {
25354
+ this.next();
25355
+ } while (!this.ended);
25356
+ return this.tokens;
25357
+ };
25358
+ this.build = function (src, real) {
25359
+ if (src) this.tokens.push(!this.doBuild ? src : this.doBuild(src, real, this.tkn));
25360
+ };
25361
+ this.next = function () {
25362
+ var self = this,
25363
+ plain;
25364
+ self.findMin();
25365
+ plain = self.src.slice(0, self.min);
25366
+ self.build(plain, false);
25367
+ self.src = self.src.slice(self.min).replace(self.tkn, function (all) {
25368
+ self.build(all, true);
25369
+ return '';
25370
+ });
25371
+ if (!self.src) self.ended = true;
25372
+ };
25373
+ this.findMin = function () {
25374
+ var self = this,
25375
+ i = 0,
25376
+ tkn,
25377
+ idx;
25378
+ self.min = -1;
25379
+ self.tkn = '';
25380
+ while ((tkn = self.tokenizers[i++]) !== undefined) {
25381
+ idx = self.src[tkn.test ? 'search' : 'indexOf'](tkn);
25382
+ if (idx != -1 && (self.min == -1 || idx < self.min)) {
25383
+ self.tkn = tkn;
25384
+ self.min = idx;
25385
+ }
25386
+ }
25387
+ if (self.min == -1) self.min = self.src.length;
25388
+ };
25389
+ }
25390
+ };
24983
25391
  ;// CONCATENATED MODULE: ./src/components/questions/buildEntry.js
24984
25392
 
24985
25393
 
@@ -25003,6 +25411,7 @@ var state = {
25003
25411
 
25004
25412
 
25005
25413
 
25414
+
25006
25415
  var parseQuestionListItem = function parseQuestionListItem(mode, question_list, answer_map) {
25007
25416
  var _this = this;
25008
25417
  var parentIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
@@ -25080,14 +25489,14 @@ var parseQuestionListItem = function parseQuestionListItem(mode, question_list,
25080
25489
  var contentWidth = jQuery('.question-list').width() - 30;
25081
25490
  //图片宽度超出框架的时候把宽度设置成框架大小
25082
25491
  parseContent(contentArr, contentWidth);
25083
- item.htmlContent = $.json2html({}, contentArr);
25492
+ item.htmlContent = json2html.transform({}, contentArr);
25084
25493
  } catch (e) {
25085
25494
  item.htmlContent = item.content;
25086
25495
  }
25087
25496
  //转化analysis富文本
25088
25497
  try {
25089
25498
  if (item.analysis) {
25090
- item.analysisHtmlContent = $.json2html({}, JSON.parse(item.analysis));
25499
+ item.analysisHtmlContent = json2html.transform({}, JSON.parse(item.analysis));
25091
25500
  } else {
25092
25501
  item.analysisHtmlContent = '';
25093
25502
  }