File indexing completed on 2024-05-12 06:01:03
0001 window.hpHelpers = function () { 0002 0003 function dechex(number) { 0004 // discuss at: http://locutus.io/php/dechex/ 0005 // original by: Philippe Baumann 0006 // bugfixed by: Onno Marsman (https://twitter.com/onnomarsman) 0007 // improved by: http://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript 0008 // input by: pilus 0009 // example 1: dechex(10) 0010 // returns 1: 'a' 0011 // example 2: dechex(47) 0012 // returns 2: '2f' 0013 // example 3: dechex(-1415723993) 0014 // returns 3: 'ab9dc427' 0015 0016 if (number < 0) { 0017 number = 0xFFFFFFFF + number + 1; 0018 } 0019 return parseInt(number, 10).toString(16); 0020 } 0021 0022 function calculateScoreColor(score) { 0023 let blue, 0024 red, 0025 green, 0026 defaultColor = 200; 0027 if (score > 50) { 0028 red = defaultColor - (score - 50) * 4; 0029 green = defaultColor; 0030 blue = defaultColor - (score - 50) * 4; 0031 } else if (score < 51) { 0032 red = defaultColor; 0033 green = defaultColor - (score - 50) * 4; 0034 blue = defaultColor - (score - 50) * 4; 0035 } 0036 0037 return "rgb(" + red + "," + green + "," + blue + ")"; 0038 } 0039 0040 return { 0041 dechex, 0042 calculateScoreColor 0043 }; 0044 }(); 0045 0046 class App extends React.Component { 0047 constructor(props) { 0048 super(props); 0049 this.state = { 0050 loading: true, 0051 hpVersion: window.hpVersion 0052 }; 0053 this.initHomePage = this.initHomePage.bind(this); 0054 this.updateDimensions = this.updateDimensions.bind(this); 0055 } 0056 0057 componentWillMount() { 0058 this.updateDimensions(); 0059 } 0060 0061 componentWillUnmount() { 0062 window.removeEventListener("resize", this.updateDimensions); 0063 window.removeEventListener("orientationchange", this.updateDimensions); 0064 } 0065 0066 componentDidMount() { 0067 this.initHomePage(); 0068 } 0069 0070 initHomePage() { 0071 0072 window.addEventListener("resize", this.updateDimensions); 0073 window.addEventListener("orientationchange", this.updateDimensions); 0074 0075 let env = "live"; 0076 if (location.hostname.endsWith('cc')) { 0077 env = "test"; 0078 } else if (location.hostname.endsWith('localhost')) { 0079 env = "test"; 0080 } 0081 0082 this.setState({ env: env }); 0083 } 0084 0085 updateDimensions() { 0086 0087 const width = window.innerWidth; 0088 let device; 0089 if (width >= 910) { 0090 device = "large"; 0091 } else if (width < 910 && width >= 610) { 0092 device = "mid"; 0093 } else if (width < 610) { 0094 device = "tablet"; 0095 } 0096 0097 this.setState({ device: device }); 0098 } 0099 0100 render() { 0101 const featuredProduct = JSON.parse(window.data['featureProducts']); 0102 return React.createElement( 0103 "main", 0104 { id: "opendesktop-homepage" }, 0105 React.createElement(SpotlightProduct, { 0106 env: this.state.env, 0107 device: this.state.device, 0108 featuredProduct: featuredProduct 0109 }) 0110 ); 0111 } 0112 } 0113 0114 class SpotlightProduct extends React.Component { 0115 constructor(props) { 0116 super(props); 0117 this.state = { 0118 featuredProduct: this.props.featuredProduct, 0119 type: "featured", 0120 featuredPage: 0, 0121 loading: true 0122 }; 0123 this.onSpotlightMenuClick = this.onSpotlightMenuClick.bind(this); 0124 } 0125 0126 componentDidMount() { 0127 this.onSpotlightMenuClick('plinged'); 0128 } 0129 0130 onSpotlightMenuClick(val) { 0131 0132 this.setState({ type: val, loading: true }, function () { 0133 0134 let url = "/home/showfeaturejson/page/"; 0135 let featuredPage = this.state.featuredPage; 0136 if (this.state.type === "plinged") { 0137 url = "/home/getnewactiveplingedproductjson?limit=1&offset=" + this.state.featuredPage; 0138 featuredPage = this.state.featuredPage + 1; 0139 } else if (this.state.type === "random") { 0140 url += "0"; 0141 } else { 0142 url += "1"; 0143 } 0144 const self = this; 0145 0146 $.ajax({ url: url, cache: false }).done(function (response) { 0147 0148 let featuredProduct = response; 0149 if (self.state.type === "plinged") { 0150 featuredProduct = response[0]; 0151 } 0152 0153 console.log(featuredProduct); 0154 0155 self.setState({ 0156 featuredProduct: featuredProduct, 0157 featuredPage: featuredPage, 0158 loading: false 0159 }); 0160 }); 0161 }); 0162 } 0163 0164 render() { 0165 0166 let spotlightProductDisplay; 0167 if (this.state.loading) { 0168 spotlightProductDisplay = React.createElement(SpotlightProductDummy, null); 0169 } else { 0170 0171 let productImageUrl; 0172 if (this.state.type === "plinged") { 0173 productImageUrl = this.state.featuredProduct.image_small; 0174 } else { 0175 let imageBaseUrl; 0176 if (this.props.env === 'live') { 0177 imageBaseUrl = 'cn.opendesktop.org'; 0178 } else { 0179 imageBaseUrl = 'cn.opendesktop.cc'; 0180 } 0181 productImageUrl = "https://" + imageBaseUrl + "/cache/300x230-1/img/" + this.state.featuredProduct.image_small; 0182 } 0183 0184 let description = this.state.featuredProduct.description; 0185 if (description && description.length > 295) { 0186 description = this.state.featuredProduct.description.substring(0, 295) + "..."; 0187 } 0188 0189 let featuredLabelDisplay; 0190 if (this.state.type === "featured") { 0191 featuredLabelDisplay = React.createElement( 0192 "span", 0193 { className: "featured-label" }, 0194 "featured" 0195 ); 0196 } else if (this.state.type === "plinged") { 0197 featuredLabelDisplay = React.createElement( 0198 "span", 0199 { className: "featured-label plinged" }, 0200 "plinged" 0201 ); 0202 } 0203 0204 let cDate = new Date(this.state.featuredProduct.created_at); 0205 cDate = cDate.toString(); 0206 const createdDate = cDate.split(' ')[1] + " " + cDate.split(' ')[2] + " " + cDate.split(' ')[3]; 0207 // const productScoreColor = window.hpHelpers.calculateScoreColor(this.state.featuredProduct.laplace_score); 0208 0209 let commentCount; 0210 if (this.state.featuredProduct.count_comments) { 0211 commentCount = this.state.featuredProduct.count_comments; 0212 } else { 0213 commentCount = "0"; 0214 } 0215 0216 let categoryDisplay = this.state.featuredProduct.category; 0217 if (this.state.type === "plinged") { 0218 categoryDisplay = this.state.featuredProduct.cat_title; 0219 } 0220 0221 spotlightProductDisplay = React.createElement( 0222 "div", 0223 { className: "container" }, 0224 React.createElement( 0225 "div", 0226 { className: "spotlight-image" }, 0227 React.createElement("img", { className: "product-image", src: productImageUrl }), 0228 React.createElement( 0229 "figure", 0230 { className: "user-avatar" }, 0231 React.createElement("img", { src: this.state.featuredProduct.profile_image_url }) 0232 ) 0233 ), 0234 React.createElement( 0235 "div", 0236 { className: "spotlight-info" }, 0237 React.createElement( 0238 "div", 0239 { className: "spotlight-info-wrapper" }, 0240 featuredLabelDisplay, 0241 React.createElement( 0242 "div", 0243 { className: "info-top" }, 0244 React.createElement( 0245 "h2", 0246 null, 0247 React.createElement( 0248 "a", 0249 { href: "/p/" + this.state.featuredProduct.project_id }, 0250 this.state.featuredProduct.title 0251 ) 0252 ), 0253 React.createElement( 0254 "h3", 0255 null, 0256 categoryDisplay 0257 ), 0258 React.createElement( 0259 "div", 0260 { className: "user-info" }, 0261 React.createElement("img", { src: this.state.featuredProduct.profile_image_url }), 0262 this.state.featuredProduct.username 0263 ), 0264 React.createElement( 0265 "span", 0266 null, 0267 commentCount, 0268 " comments" 0269 ), 0270 React.createElement( 0271 "div", 0272 { className: "score-info" }, 0273 React.createElement( 0274 "div", 0275 { className: "score-number" }, 0276 "score ", 0277 this.state.featuredProduct.laplace_score + "%" 0278 ), 0279 React.createElement( 0280 "div", 0281 { className: "score-bar-container" }, 0282 React.createElement("div", { className: "score-bar", style: { "width": this.state.featuredProduct.laplace_score + "%" } }) 0283 ), 0284 React.createElement( 0285 "div", 0286 { className: "score-bar-date" }, 0287 createdDate 0288 ) 0289 ) 0290 ), 0291 React.createElement( 0292 "div", 0293 { className: "info-description" }, 0294 description 0295 ) 0296 ), 0297 React.createElement( 0298 "div", 0299 { className: "spotlight-menu" }, 0300 React.createElement( 0301 "a", 0302 { onClick: () => this.onSpotlightMenuClick('random') }, 0303 "random" 0304 ), 0305 React.createElement( 0306 "a", 0307 { onClick: () => this.onSpotlightMenuClick('featured') }, 0308 "featured" 0309 ), 0310 React.createElement( 0311 "a", 0312 { onClick: () => this.onSpotlightMenuClick('plinged') }, 0313 "plinged" 0314 ) 0315 ) 0316 ) 0317 ); 0318 } 0319 0320 return React.createElement( 0321 "div", 0322 { id: "spotlight-product" }, 0323 React.createElement( 0324 "h2", 0325 null, 0326 "In the Spotlight" 0327 ), 0328 spotlightProductDisplay 0329 ); 0330 } 0331 } 0332 0333 class SpotlightProductDummy extends React.Component { 0334 constructor(props) { 0335 super(props); 0336 this.state = {}; 0337 } 0338 0339 render() { 0340 return React.createElement( 0341 "div", 0342 { className: "container dummy-product" }, 0343 React.createElement( 0344 "div", 0345 { className: "spotlight-image" }, 0346 React.createElement( 0347 "figure", 0348 { className: "user-avatar" }, 0349 React.createElement("div", { className: "ajax-loader" }) 0350 ) 0351 ), 0352 React.createElement( 0353 "div", 0354 { className: "spotlight-info" }, 0355 React.createElement( 0356 "div", 0357 { className: "spotlight-info-wrapper" }, 0358 React.createElement( 0359 "div", 0360 { className: "info-top" }, 0361 React.createElement("h2", null), 0362 React.createElement("h3", null), 0363 React.createElement( 0364 "div", 0365 { className: "user-info" }, 0366 React.createElement( 0367 "figure", 0368 null, 0369 React.createElement("span", { className: "glyphicon glyphicon-user" }) 0370 ), 0371 React.createElement("span", null) 0372 ), 0373 React.createElement("span", { className: "comments-count" }), 0374 React.createElement( 0375 "div", 0376 { className: "score-info" }, 0377 React.createElement("div", { className: "score-number" }), 0378 React.createElement( 0379 "div", 0380 { className: "score-bar-container" }, 0381 React.createElement("div", { className: "score-bar", style: { "width": "50%" } }) 0382 ), 0383 React.createElement("div", { className: "score-bar-date" }) 0384 ) 0385 ), 0386 React.createElement( 0387 "div", 0388 { className: "info-description" }, 0389 React.createElement("span", null), 0390 React.createElement("span", null), 0391 React.createElement("span", null), 0392 React.createElement("span", { className: "half" }) 0393 ) 0394 ) 0395 ) 0396 ); 0397 } 0398 } 0399 0400 class SpotlightUser extends React.Component { 0401 constructor(props) { 0402 super(props); 0403 this.state = { 0404 loading: true, 0405 version: 2 0406 }; 0407 this.updateDimensions = this.updateDimensions.bind(this); 0408 this.getSpotlightUser = this.getSpotlightUser.bind(this); 0409 } 0410 0411 componentWillMount() { 0412 window.addEventListener("resize", this.updateDimensions); 0413 } 0414 0415 componentDidMount() { 0416 this.updateDimensions(); 0417 this.getSpotlightUser(); 0418 } 0419 0420 updateDimensions() { 0421 const containerWidth = $('#main-content').width(); 0422 const userProductsPerRow = 4; 0423 const userProductsDimensions = containerWidth / userProductsPerRow; 0424 this.setState({ itemWidth: userProductsDimensions, itemHeight: userProductsDimensions }); 0425 } 0426 0427 getSpotlightUser(page) { 0428 if (!page) { 0429 page = 0; 0430 } 0431 this.setState({ loading: true, page: page }, function () { 0432 let url = "/home/showspotlightjson?page=" + this.state.page; 0433 const self = this; 0434 $.ajax({ url: url, cache: false }).done(function (response) { 0435 self.setState({ user: response, loading: false }, function () { 0436 const height = $('#user-container').height(); 0437 if (height > 0) { 0438 this.setState({ containerHeight: height }); 0439 } 0440 }); 0441 }); 0442 }); 0443 } 0444 0445 render() { 0446 0447 let spotlightUserDisplay; 0448 if (this.state.loading) { 0449 let loadingStyle; 0450 if (this.state.containerHeight) { 0451 loadingStyle = { 0452 "height": this.state.containerHeight 0453 }; 0454 } 0455 spotlightUserDisplay = React.createElement( 0456 "div", 0457 { className: "loading-container", style: loadingStyle }, 0458 React.createElement("div", { className: "ajax-loader" }) 0459 ); 0460 } else { 0461 let userProducts; 0462 if (this.state.itemWidth) { 0463 userProducts = this.state.user.products.map((p, index) => React.createElement(SpotlightUserProduct, { 0464 key: index, 0465 itemHeight: this.state.itemHeight, 0466 itemWidth: this.state.itemWidth, 0467 product: p 0468 })); 0469 } 0470 spotlightUserDisplay = React.createElement( 0471 "div", 0472 { id: "spotlight-user" }, 0473 React.createElement( 0474 "div", 0475 { className: "user-container" }, 0476 React.createElement( 0477 "figure", 0478 null, 0479 React.createElement("img", { src: this.state.user.profile_image_url }) 0480 ), 0481 React.createElement( 0482 "h2", 0483 null, 0484 React.createElement( 0485 "a", 0486 { href: "/u/" + this.state.user.username }, 0487 this.state.user.username 0488 ) 0489 ) 0490 ), 0491 React.createElement( 0492 "div", 0493 { className: "products-container" }, 0494 userProducts 0495 ) 0496 ); 0497 } 0498 0499 let prevButtonDisplay; 0500 if (this.state.page > 0) { 0501 prevButtonDisplay = React.createElement( 0502 "a", 0503 { onClick: () => this.getSpotlightUser(this.state.page - 1), className: "spotlight-user-next" }, 0504 "< Prev" 0505 ); 0506 } 0507 0508 let nextButtonDisplay; 0509 if (this.state.page < 8) { 0510 nextButtonDisplay = React.createElement( 0511 "a", 0512 { onClick: () => this.getSpotlightUser(this.state.page + 1), className: "spotlight-user-next" }, 0513 "Next >" 0514 ); 0515 } 0516 0517 let versionCssClass; 0518 if (this.state.version === 2) { 0519 versionCssClass = "v-two"; 0520 } 0521 0522 return React.createElement( 0523 "div", 0524 { id: "spotlight-user-container", className: versionCssClass }, 0525 React.createElement( 0526 "h2", 0527 null, 0528 "In the Spotlight" 0529 ), 0530 spotlightUserDisplay, 0531 React.createElement( 0532 "div", 0533 { className: "spotlight-user-buttons" }, 0534 prevButtonDisplay, 0535 nextButtonDisplay 0536 ) 0537 ); 0538 } 0539 } 0540 0541 class SpotlightUserProduct extends React.Component { 0542 constructor(props) { 0543 super(props); 0544 this.state = {}; 0545 } 0546 0547 componentDidMount() { 0548 console.log(this.props); 0549 } 0550 0551 render() { 0552 let userProductStyle; 0553 if (this.props.itemWidth) { 0554 userProductStyle = { 0555 "height": this.props.itemHeight, 0556 "width": this.props.itemWidth 0557 }; 0558 } 0559 return React.createElement( 0560 "div", 0561 { style: userProductStyle, className: "spotlight-user-product" }, 0562 React.createElement( 0563 "figure", 0564 null, 0565 React.createElement("img", { src: this.props.product.image_small }) 0566 ), 0567 React.createElement( 0568 "div", 0569 { className: "product-title-overlay" }, 0570 React.createElement( 0571 "div", 0572 { className: "product-title" }, 0573 this.props.product.title 0574 ) 0575 ), 0576 React.createElement( 0577 "div", 0578 { className: "product-plings-counter" }, 0579 React.createElement("img", { src: "/images/system/pling-btn-active.png" }), 0580 React.createElement( 0581 "span", 0582 null, 0583 this.props.product.sum_plings 0584 ) 0585 ) 0586 ); 0587 } 0588 } 0589 0590 ReactDOM.render(React.createElement(App, null), document.getElementById('main-content'));