Created
June 2, 2017 17:22
-
-
Save sarangbk/eebe332ba538bcc2616f46df55bd0446 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SPThumbnailPathGenerator { | |
_SPThumbnailPath: string; | |
constructor(path: string) { | |
this._SPThumbnailPath = path; | |
} | |
SPThumbnailPath_W () | |
{ | |
let imgPath = this._SPThumbnailPath; | |
let pathWithOutFileName = imgPath.substring(0, imgPath.lastIndexOf("/") + 1); | |
let fileName = imgPath.substring(imgPath.lastIndexOf("/") + 1); | |
fileName = fileName.replace('.', '_'); | |
imgPath = `${pathWithOutFileName}_w/${fileName}` | |
if (imgPath.includes('?')) | |
{ | |
return imgPath.replace("?", ".jpg?"); | |
} | |
else | |
{ | |
return`${imgPath}.jpg` | |
} | |
} | |
SPThumbnailPath_T () | |
{ | |
let imgPath = this._SPThumbnailPath; | |
let pathWithOutFileName = imgPath.substring(0, imgPath.lastIndexOf("/") + 1); | |
let fileName = imgPath.substring(imgPath.lastIndexOf("/") + 1); | |
fileName = fileName.replace('.', '_'); | |
imgPath = `${pathWithOutFileName}_t/${fileName}` | |
if (imgPath.includes('?')) | |
{ | |
return imgPath.replace("?", ".jpg?"); | |
} | |
else | |
{ | |
return`${imgPath}.jpg` | |
} | |
} | |
} | |
let spthumbnailPathGenerator = new SPThumbnailPathGenerator("https://www.somesite.com/sites/sitename/listname/imagename.jpg"); | |
let thumbNailButton = document.createElement('button'); | |
let wideImageButton = document.createElement('button'); | |
thumbNailButton.textContent = "Get Thumbnail Path"; | |
wideImageButton.textContent = "Get bigger image Path"; | |
thumbNailButton.onclick = function() { | |
alert(spthumbnailPathGenerator.SPThumbnailPath_T()); | |
} | |
wideImageButton.onclick = function() { | |
alert(spthumbnailPathGenerator.SPThumbnailPath_W()); | |
} | |
document.body.appendChild(thumbNailButton); | |
document.body.appendChild(wideImageButton); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment