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