Fix ie8 bug

String.trim() is not supported in ie8, replaced with String.replace(/^\s+|\s+$/g, '')